From: Pekka Riikonen Date: Thu, 10 Apr 2008 15:01:35 +0000 (+0300) Subject: Fixed QoS data limit handling in socket stream when reading data. X-Git-Tag: silc.server.1.1.3~6 X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=commitdiff_plain;h=c724c52cf360b74e42a7f2c7450a25bd1fcb220d Fixed QoS data limit handling in socket stream when reading data. --- diff --git a/lib/silccore/silcpacket.c b/lib/silccore/silcpacket.c index bea63579..08c2a0ac 100644 --- a/lib/silccore/silcpacket.c +++ b/lib/silccore/silcpacket.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 1997 - 2007 Pekka Riikonen + Copyright (C) 1997 - 2008 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -336,7 +336,6 @@ static inline SilcBool silc_packet_stream_read(SilcPacketStream ps, silc_mutex_unlock(ps->lock); if (ret == -1) { /* Cannot read now, do it later. */ - silc_buffer_pull(inbuf, silc_buffer_len(inbuf)); return FALSE; } @@ -394,7 +393,6 @@ static inline SilcBool silc_packet_stream_read(SilcPacketStream ps, if (ret == -1) { /* Cannot read now, do it later. */ - silc_buffer_pull(inbuf, silc_buffer_len(inbuf)); return FALSE; } @@ -887,6 +885,8 @@ void silc_packet_stream_destroy(SilcPacketStream stream) return; if (silc_atomic_sub_int8(&stream->refcnt, 1) > 0) { + if (stream->destroyed) + return; stream->destroyed = TRUE; SILC_LOG_DEBUG(("Marking packet stream %p destroyed", stream)); diff --git a/lib/silcutil/silcsocketstream.c b/lib/silcutil/silcsocketstream.c index e4b59f5a..af8f2c34 100644 --- a/lib/silcutil/silcsocketstream.c +++ b/lib/silcutil/silcsocketstream.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 2005 - 2007 Pekka Riikonen + Copyright (C) 2005 - 2008 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -350,6 +350,7 @@ SilcBool silc_socket_stream_set_qos(SilcStream stream, !limit_sec && !limit_usec) { silc_schedule_task_del_by_context(socket_stream->schedule, socket_stream->qos); + silc_free(socket_stream->qos->buffer); silc_free(socket_stream->qos); socket_stream->qos = NULL; return TRUE; @@ -370,7 +371,8 @@ SilcBool silc_socket_stream_set_qos(SilcStream stream, socket_stream->qos->cur_rate = 0; socket_stream->qos->sock = socket_stream; - socket_stream->qos->buffer = silc_malloc(read_limit_bytes); + socket_stream->qos->buffer = silc_realloc(socket_stream->qos->buffer, + read_limit_bytes); if (!socket_stream->qos->buffer) return FALSE; diff --git a/lib/silcutil/unix/silcunixsocketstream.c b/lib/silcutil/unix/silcunixsocketstream.c index 4b5f0ac1..60d458d4 100644 --- a/lib/silcutil/unix/silcunixsocketstream.c +++ b/lib/silcutil/unix/silcunixsocketstream.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 1997 - 2007 Pekka Riikonen + Copyright (C) 1997 - 2008 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -106,8 +106,9 @@ int silc_socket_stream_read(SilcStream stream, unsigned char *buf, /* If QoS was applied, return the data that was pending. */ if (sock->qos->applied && sock->qos->data_len) { memcpy(buf, qosbuf, sock->qos->data_len); + len = sock->qos->data_len; sock->qos->data_len = 0; - return sock->qos->data_len; + return len; } /* If we have active QoS data pending, return with no data */ @@ -116,7 +117,8 @@ int silc_socket_stream_read(SilcStream stream, unsigned char *buf, return -1; } - /* Read the data from the socket. Never read more than the max limit. */ + /* Read the data from the socket. The qosbuf size is always the max + read limit size. */ len = (buf_len < sock->qos->read_limit_bytes ? buf_len : sock->qos->read_limit_bytes); len = read(sock->sock, qosbuf, len);