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.
/* 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);