Fix: One more fix for disconnect detection
authorDenis Kenzior <denkenz@gmail.com>
Fri, 15 Jan 2010 16:24:01 +0000 (10:24 -0600)
committerMarcel Holtmann <marcel@holtmann.org>
Fri, 15 Jan 2010 20:10:59 +0000 (12:10 -0800)
In situations where lots of data is generated by the remote side (e.g.
phonebook is being read) we can get our ring buffer filled up.  In this
case setting rbytes to zero first and then breaking out of the loop
leads to an erroneous disconnect detection.  The fix is to move setting
of rbytes after we know we still have some space.

gatchat/gatchat.c

index 8af927e..7dfc4cb 100644 (file)
@@ -776,13 +776,12 @@ static gboolean received_data(GIOChannel *channel, GIOCondition cond,
 
        /* Regardless of condition, try to read all the data available */
        do {
-               rbytes = 0;
-
                toread = ring_buffer_avail_no_wrap(chat->buf);
 
                if (toread == 0)
                        break;
 
+               rbytes = 0;
                buf = ring_buffer_write_ptr(chat->buf);
 
                err = g_io_channel_read(channel, (char *) buf, toread, &rbytes);