Fixed QoS data limit handling in socket stream when reading data.
authorPekka Riikonen <priikone@silcnet.org>
Thu, 10 Apr 2008 15:01:35 +0000 (18:01 +0300)
committerPekka Riikonen <priikone@silcnet.org>
Thu, 10 Apr 2008 15:01:35 +0000 (18:01 +0300)
lib/silccore/silcpacket.c
lib/silcutil/silcsocketstream.c
lib/silcutil/unix/silcunixsocketstream.c

index bea6357939731b0db4ba92ed16cda2cab5e83e9d..08c2a0ac177e591a943c4da5264e09555e848f8a 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  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));
index e4b59f5a601c6d0019632438514f780a48729507..af8f2c34cba0b60f6584b07dd57b10931fe115ab 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  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;
 
index 4b5f0ac11efffb255ed0da5d651c5187ab89ce2a..60d458d4a19bb39be74a42dbd3ca625cf7ee32a6 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  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);