From 8543455245d62550fbb73be3e609286f403a3d75 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Fri, 31 Oct 2003 11:14:16 +0000 Subject: [PATCH] Optimized the socket referencing in packet processing. silc_socket_set_qos with NULL arguments resets the QoS. --- CHANGES | 12 +++++++++++- apps/silcd/server.c | 12 +----------- lib/silcclient/client.c | 3 --- lib/silccore/silcpacket.c | 21 +++++++++++++++++---- lib/silcutil/silcsockconn.c | 13 +++++++++++++ lib/silcutil/silcsockconn.h | 4 +++- 6 files changed, 45 insertions(+), 20 deletions(-) diff --git a/CHANGES b/CHANGES index 485885a3..3e70e8f2 100644 --- a/CHANGES +++ b/CHANGES @@ -1,7 +1,17 @@ +Fri Oct 31 12:33:59 EET 2003 Pekka Riikonen + + * 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 * 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 diff --git a/apps/silcd/server.c b/apps/silcd/server.c index 8c635e2e..9860302b 100644 --- a/apps/silcd/server.c +++ b/apps/silcd/server.c @@ -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, diff --git a/lib/silcclient/client.c b/lib/silcclient/client.c index 034b5cb0..0e7fe71b 100644 --- a/lib/silcclient/client.c +++ b/lib/silcclient/client.c @@ -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; } diff --git a/lib/silccore/silcpacket.c b/lib/silccore/silcpacket.c index 0a9ad104..58f090b9 100644 --- a/lib/silccore/silcpacket.c +++ b/lib/silccore/silcpacket.c @@ -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; } diff --git a/lib/silcutil/silcsockconn.c b/lib/silcutil/silcsockconn.c index 4a57a343..9b44b7ed 100644 --- a/lib/silcutil/silcsockconn.c +++ b/lib/silcutil/silcsockconn.c @@ -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) diff --git a/lib/silcutil/silcsockconn.h b/lib/silcutil/silcsockconn.h index 960da4bb..6fcea38d 100644 --- a/lib/silcutil/silcsockconn.h +++ b/lib/silcutil/silcsockconn.h @@ -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, -- 2.24.0