updates.
authorPekka Riikonen <priikone@silcnet.org>
Tue, 19 Jun 2001 19:06:42 +0000 (19:06 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Tue, 19 Jun 2001 19:06:42 +0000 (19:06 +0000)
TODO
lib/silccore/silcpacket.c
lib/silccore/silcpacket.h

diff --git a/TODO b/TODO
index abdffebe5f650fa0aa6abdeb9743a0d361e32a75..c28ff5541253e9d478719850d3af4e3451479d51 100644 (file)
--- a/TODO
+++ b/TODO
@@ -64,6 +64,9 @@ TODO/bugs In SILC Client Library
 TODO/bugs In SILC Server
 ========================
 
+ o Seems that router does not announce its client to the connecting
+   server when server announces its clients on the channel.
+
  o When server quits and all clients of that server are removed from all
    channels the channel keys are re-generated for all clients.  This is
    a bug and should be done only once per channel after all clients of
index b19f2a9d70278a446c77c713f555976cdb4df18b..e1637c26d2032d906f1b5a0b8d0988cdcbc1db82 100644 (file)
@@ -264,10 +264,12 @@ void silc_packet_send_prepare(SilcSocketConnection sock,
       /* There is some pending data in the buffer. */
 
       /* Allocate more space if needed */
-      if ((sock->outbuf->end - sock->outbuf->tail) < data_len) {
+      if ((sock->outbuf->end - sock->outbuf->tail) < 
+         (totlen + 20)) {
        SILC_LOG_DEBUG(("Reallocating outgoing data buffer"));
        sock->outbuf = silc_buffer_realloc(sock->outbuf, 
-                                          sock->outbuf->truelen + totlen);
+                                          sock->outbuf->truelen +
+                                          (totlen * 2));
       }
 
       oldlen = sock->outbuf->len;
@@ -276,6 +278,15 @@ void silc_packet_send_prepare(SilcSocketConnection sock,
     } else {
       /* Buffer is free for use */
       silc_buffer_clear(sock->outbuf);
+
+      /* Allocate more space if needed */
+      if ((sock->outbuf->end - sock->outbuf->tail) < (totlen + 20)) {
+       SILC_LOG_DEBUG(("Reallocating outgoing data buffer"));
+       sock->outbuf = silc_buffer_realloc(sock->outbuf, 
+                                          sock->outbuf->truelen + 
+                                          (totlen * 2));
+      }
+
       silc_buffer_pull_tail(sock->outbuf, totlen);
       silc_buffer_pull(sock->outbuf, header_len + padlen);
     }
@@ -302,56 +313,38 @@ void silc_packet_send_prepare(SilcSocketConnection sock,
    This returns amount of bytes read or -1 on error or -2 on case where
    all of the data could not be read at once. */
 
-int silc_packet_read(int sock, SilcBuffer dest)
+int silc_packet_read(int fd, SilcSocketConnection sock)
 {
   int len = 0;
   unsigned char buf[SILC_PACKET_READ_SIZE];
 
-  SILC_LOG_DEBUG(("Reading data from socket %d", sock));
+  SILC_LOG_DEBUG(("Reading data from socket %d", fd));
 
   /* Read the data from the socket. */
-  len = read(sock, buf, sizeof(buf));
+  len = read(fd, buf, sizeof(buf));
   if (len < 0) {
     if (errno == EAGAIN || errno == EINTR) {
       SILC_LOG_DEBUG(("Could not read immediately, will do it later"));
       return -2;
     }
-    SILC_LOG_ERROR(("Cannot read from socket: %d:%s", sock, strerror(errno)));
+    SILC_LOG_ERROR(("Cannot read from socket: %d:%s", fd, strerror(errno)));
     return -1;
   }
 
   if (!len)
     return 0;
 
-  /* Insert the data to the buffer. If the data doesn't fit to the 
-     buffer space is allocated for the buffer. */
-  /* XXX: This may actually be bad thing as if there is pending data in
-     the buffer they will be lost! */
-  if (dest) {
-
-    /* If the data doesn't fit we just have to allocate a whole new 
-       data area */
-    if (dest->truelen <= len) {
-
-      /* Free the old buffer */
-      memset(dest->head, 'F', dest->truelen);
-      silc_free(dest->head);
-
-      /* Allocate new data area */
-      len += SILC_PACKET_DEFAULT_SIZE;
-      dest->data = silc_calloc(len, sizeof(char));
-      dest->truelen = len;
-      dest->len = 0;
-      dest->head = dest->data;
-      dest->data = dest->data;
-      dest->tail = dest->data;
-      dest->end = dest->data + dest->truelen;
-      len -= SILC_PACKET_DEFAULT_SIZE;
-    }
+  /* Insert the data to the buffer. */
 
-    silc_buffer_put_tail(dest, buf, len);
-    silc_buffer_pull_tail(dest, len);
-  }
+  if (!sock->inbuf)
+    sock->inbuf = silc_buffer_alloc(SILC_PACKET_DEFAULT_SIZE);
+  
+  /* If the data does not fit to the buffer reallocate it */
+  if ((sock->inbuf->end - sock->inbuf->tail) < len)
+    sock->inbuf = silc_buffer_realloc(sock->inbuf, sock->inbuf->truelen + 
+                                     (len * 2));
+  silc_buffer_put_tail(sock->inbuf, buf, len);
+  silc_buffer_pull_tail(sock->inbuf, len);
 
   SILC_LOG_DEBUG(("Read %d bytes", len));
 
@@ -448,12 +441,8 @@ int silc_packet_receive(SilcSocketConnection sock)
                   sock->type == SILC_SOCKET_TYPE_SERVER ? "Server" :
                   "Router")));
 
-  /* Allocate the incoming data buffer if not done already. */
-  if (!sock->inbuf)
-    sock->inbuf = silc_buffer_alloc(SILC_PACKET_DEFAULT_SIZE);
-
   /* Read some data from connection */
-  ret = silc_packet_read(sock->sock, sock->inbuf);
+  ret = silc_packet_read(sock->sock, sock);
 
   return ret;
 }
index 2d5ba45dd5e1b00badfc3cf1204b02afe71f0813..029c455debfcaee7e462fdc11c5a65c3e911bb71 100644 (file)
@@ -500,7 +500,7 @@ void silc_packet_send_prepare(SilcSocketConnection sock,
  *
  * SYNOPSIS
  *
- *    int silc_packet_read(int sock, SilcBuffer dest);
+ *    int silc_packet_read(int fd, SilcSocketConnection sock);
  *
  * DESCRIPTION
  *
@@ -519,7 +519,7 @@ void silc_packet_send_prepare(SilcSocketConnection sock,
  *    all of the data could not be read at once.
  *
  ***/
-int silc_packet_read(int sock, SilcBuffer dest);
+int silc_packet_read(int fd, SilcSocketConnection sock);
 
 /****f* silccore/SilcPacketAPI/silc_packet_receive
  *