Optimized the socket referencing in packet processing. silc.client.0.9.15
authorPekka Riikonen <priikone@silcnet.org>
Fri, 31 Oct 2003 11:14:16 +0000 (11:14 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Fri, 31 Oct 2003 11:14:16 +0000 (11:14 +0000)
silc_socket_set_qos with NULL arguments resets the QoS.

CHANGES
apps/silcd/server.c
lib/silcclient/client.c
lib/silccore/silcpacket.c
lib/silcutil/silcsockconn.c
lib/silcutil/silcsockconn.h

diff --git a/CHANGES b/CHANGES
index 485885a3ab25f5fb47c88e7c72f7eed2f816998d..3e70e8f2a1d44eb4080de51e662a9256a0ac20a3 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,7 +1,17 @@
+Fri Oct 31 12:33:59 EET 2003 Pekka Riikonen <priikone@silcnet.org>
+
+       * Optimized the socket referencing in packet routines, client
+         library and server.  Affected files are lib/silccore/silcpacket.c,
+         lib/silcclient/client.c and silcd/server.c.
+
+       * If silc_socket_set_qos is given with NULL arguments the QoS is
+         reset from the socket.  Affected files are
+         lib/silcutil/silcsockconn.[ch].
+
 Thu Oct 30 21:23:24 CET 2003 Jochen Eisinger <jochen@penguin-breeder.org>
 
        * Add a /LISTKEYS command which lists the locally cached
-         client and server keys.  Affected files 
+         client and server keys.  Affected files
          irssi/src/fe-common/module-formats.[ch],
          irssi/src/silc/core/silc-{channels,servers}.c
          irssi/docs/help/in/listkeys.in
index 8c635e2ed5813d613176d0fa4152c3f7cedd80ed..9860302b1b3cc192d70506d984dd54b31ca6d29f 100644 (file)
@@ -2481,7 +2481,6 @@ SILC_TASK_CALLBACK(silc_server_packet_parse_real)
 
  out:
   silc_packet_context_free(packet);
-  silc_socket_free(parse_ctx->sock);
   silc_free(parse_ctx);
 }
 
@@ -2496,13 +2495,6 @@ bool silc_server_packet_parse(SilcPacketParserContext *parser_context,
   SilcIDListData idata = (SilcIDListData)sock->user_data;
   bool ret;
 
-  if (SILC_IS_DISCONNECTING(sock) || SILC_IS_DISCONNECTED(sock)) {
-    SILC_LOG_DEBUG(("Connection is disconnected"));
-    silc_socket_free(parser_context->sock);
-    silc_free(parser_context);
-    return FALSE;
-  }
-
   if (idata)
     idata->psn_receive = parser_context->packet->sequence + 1;
 
@@ -2513,16 +2505,13 @@ bool silc_server_packet_parse(SilcPacketParserContext *parser_context,
   if (sock->protocol && sock->protocol->protocol &&
       (sock->protocol->protocol->type == SILC_PROTOCOL_SERVER_KEY_EXCHANGE ||
        sock->protocol->protocol->type == SILC_PROTOCOL_SERVER_REKEY)) {
-    silc_socket_dup(sock);
     silc_server_packet_parse_real(server->schedule, server, 0, sock->sock,
                                  parser_context);
 
     if (SILC_IS_DISCONNECTING(sock) || SILC_IS_DISCONNECTED(sock)) {
       SILC_LOG_DEBUG(("Connection is disconnected"));
-      silc_socket_free(sock);
       return FALSE;
     }
-    silc_socket_free(sock);
 
     /* Reprocess data since we'll return FALSE here.  This is because
        the idata->receive_key might have become valid in the last packet
@@ -3160,6 +3149,7 @@ void silc_server_close_connection(SilcServer server,
                  "Router"), tmp[0] ? tmp : ""));
 
   SILC_SET_DISCONNECTED(sock);
+  silc_socket_set_qos(sock, 0, 0, 0, 0, NULL);
   silc_schedule_task_add(server->schedule, sock->sock,
                         silc_server_close_connection_final,
                         (void *)sock, 0, 1, SILC_TASK_TIMEOUT,
index 034b5cb05c6694d220c09a77471c0a286cbf6f20..0e7fe71b579c139bc199ac27e9ffe398c31b7713 100644 (file)
@@ -1042,7 +1042,6 @@ static bool silc_client_packet_parse(SilcPacketParserContext *parser_context,
 
   if (ret == SILC_PACKET_NONE) {
     silc_packet_context_free(packet);
-    silc_socket_free(parser_context->sock);
     silc_free(parser_context);
     return FALSE;
   }
@@ -1071,7 +1070,6 @@ static bool silc_client_packet_parse(SilcPacketParserContext *parser_context,
                                  silc_client_packet_parse, client);
 
     silc_packet_context_free(packet);
-    silc_socket_free(parser_context->sock);
     silc_free(parser_context);
 
     return FALSE;
@@ -1080,7 +1078,6 @@ static bool silc_client_packet_parse(SilcPacketParserContext *parser_context,
   /* Parse the incoming packet type */
   silc_client_packet_parse_type(client, sock, packet);
   silc_packet_context_free(packet);
-  silc_socket_free(parser_context->sock);
   silc_free(parser_context);
   return TRUE;
 }
index 0a9ad104d24443bf07d6c339c121b63216e4820f..58f090b9ab64a0c6652e8f2e44c3cba6bc2dd743 100644 (file)
@@ -323,10 +323,12 @@ bool silc_packet_receive_process(SilcSocketConnection sock,
     mac_len = silc_hmac_len(hmac);
 
   /* Parse the packets from the data */
+  silc_socket_dup(sock);
   while (sock->inbuf->len > 0 && cont) {
 
     if (sock->inbuf->len < SILC_PACKET_MIN_HEADER_LEN) {
       SILC_LOG_DEBUG(("Partial packet in queue, waiting for the rest"));
+      silc_socket_free(sock);
       return TRUE;
     }
 
@@ -349,6 +351,7 @@ bool silc_packet_receive_process(SilcSocketConnection sock,
       SILC_LOG_ERROR(("Received too short packet"));
       memset(header, 0, sizeof(header));
       silc_buffer_clear(sock->inbuf);
+      silc_socket_free(sock);
       return FALSE;
     }
 
@@ -357,6 +360,7 @@ bool silc_packet_receive_process(SilcSocketConnection sock,
                      "(%d bytes)", paddedlen + mac_len - sock->inbuf->len));
       SILC_SET_INBUF_PENDING(sock);
       memset(tmp, 0, sizeof(tmp));
+      silc_socket_free(sock);
       return TRUE;
     }
 
@@ -375,19 +379,22 @@ bool silc_packet_receive_process(SilcSocketConnection sock,
                        sock->protocol ? sock->protocol->protocol->type : -1));
       memset(tmp, 0, sizeof(tmp));
       silc_buffer_clear(sock->inbuf);
+      silc_socket_free(sock);
       return FALSE;
     }
 
     SILC_UNSET_INBUF_PENDING(sock);
     parse_ctx = silc_calloc(1, sizeof(*parse_ctx));
-    if (!parse_ctx)
+    if (!parse_ctx) {
+      silc_socket_free(sock);
       return FALSE;
+    }
     parse_ctx->packet = silc_packet_context_alloc();
     parse_ctx->packet->buffer = silc_buffer_alloc_size(paddedlen);
     parse_ctx->packet->type = (SilcPacketType)header[3];
     parse_ctx->packet->padlen = (SilcUInt8)header[4];
     parse_ctx->packet->sequence = sequence++;
-    parse_ctx->sock = silc_socket_dup(sock);
+    parse_ctx->sock = sock;
     parse_ctx->context = parser_context;
 
     /* Check whether this is normal or special packet */
@@ -432,6 +439,7 @@ bool silc_packet_receive_process(SilcSocketConnection sock,
        memset(tmp, 0, sizeof(tmp));
        silc_packet_context_free(parse_ctx->packet);
        silc_free(parse_ctx);
+       silc_socket_free(sock);
        return FALSE;
       }
     }
@@ -459,15 +467,20 @@ bool silc_packet_receive_process(SilcSocketConnection sock,
   }
 
   /* Don't clear buffer if pending data is in the buffer */
-  if (cont == FALSE && sock->inbuf->len > 0)
+  if (cont == FALSE && sock->inbuf->len > 0) {
+    silc_socket_free(sock);
     return TRUE;
+  }
 
   /* Don't clear buffer if QoS data exists in the buffer */
-  if (sock->qos && sock->qos->data_len > 0)
+  if (sock->qos && sock->qos->data_len > 0) {
+    silc_socket_free(sock);
     return TRUE;
+  }
 
   SILC_LOG_DEBUG(("Clearing inbound buffer"));
   silc_buffer_clear(sock->inbuf);
+  silc_socket_free(sock);
   return TRUE;
 }
 
index 4a57a343c5c4b6cb74afabefafbfdf08af7be2c1..9b44b7ed357ae1af084525d0443faba308996fe4 100644 (file)
@@ -169,6 +169,19 @@ void silc_socket_set_qos(SilcSocketConnection sock,
                         SilcUInt32 limit_usec,
                         SilcSchedule schedule)
 {
+  if (!sock)
+    return;
+
+  if (sock->qos && !read_rate && !read_limit_bytes &&
+      !limit_sec && !limit_usec && !schedule) {
+    silc_schedule_task_del_by_context(sock->qos->schedule, sock->qos);
+    silc_free(sock->qos);
+    sock->qos = NULL;
+    return;
+  }
+  if (!schedule)
+    return;
+
   if (!sock->qos) {
     sock->qos = silc_calloc(1, sizeof(*sock->qos));
     if (!sock->qos)
index 960da4bbd194dfe872d44c2d13fced6f334d690d..6fcea38d361b8271f4e4b5a2d64be9c953dd6ca7 100644 (file)
@@ -431,7 +431,9 @@ void silc_socket_set_heartbeat(SilcSocketConnection sock,
  *    will be applied for the reading.  The `limit_sec' and `limit_usec'
  *    specifies the limit that is applied if `read_rate' and/or
  *    `read_limit_bytes' is reached.  The `schedule' is the application's
- *    scheduler.
+ *    scheduler.  If all arguments except `sock' are NULL or zero this
+ *    resets the QoS from the socket, all QoS for this socket that may
+ *    be pending will be cancelled.
  *
  ***/
 void silc_socket_set_qos(SilcSocketConnection sock,