pidgin/pidgin

iterate on jabber callback when receiving more data than buffer size
iterate-on-receiving-data-in-jabber-callback
16 months ago, Fabrice Bellet
7de5610adb49
iterate on jabber callback when receiving more data than buffer size
--- a/libpurple/protocols/jabber/jabber.c Sun Nov 10 09:52:48 2019 +0000
+++ b/libpurple/protocols/jabber/jabber.c Sun Nov 10 16:32:53 2019 +0100
@@ -595,7 +595,7 @@
return PING_TIMEOUT;
}
-static void
+static gboolean
jabber_recv_cb(GObject *stream, gpointer data)
{
PurpleConnection *gc = data;
@@ -610,7 +610,7 @@
G_POLLABLE_INPUT_STREAM(stream), buf, sizeof(buf) - 1,
js->cancellable, &error);
- if (len > 0) {
+ while (len > 0) {
purple_connection_update_last_received(gc);
#ifdef HAVE_CYRUS_SASL
if (js->sasl_maxbuf > 0) {
@@ -635,7 +635,7 @@
if (js->reinit)
jabber_stream_init(js);
}
- return;
+ return G_SOURCE_CONTINUE;
}
#endif
buf[len] = '\0';
@@ -644,15 +644,17 @@
jabber_parser_process(js, buf, len);
if(js->reinit)
jabber_stream_init(js);
- } else if (len == 0) {
- purple_connection_error(js->gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
- _("Server closed the connection"));
- } else if (error->code != G_IO_ERROR_WOULD_BLOCK &&
- error->code != G_IO_ERROR_CANCELLED) {
+ len = g_pollable_input_stream_read_nonblocking(
+ G_POLLABLE_INPUT_STREAM(stream), buf, sizeof(buf) - 1,
+ js->cancellable, &error);
+ }
+ if (error->code != G_IO_ERROR_WOULD_BLOCK &&
+ error->code != G_IO_ERROR_CANCELLED) {
g_prefix_error(&error, "%s", _("Lost connection with server: "));
purple_connection_g_error(js->gc, error);
}
g_clear_error(&error);
+ return G_SOURCE_CONTINUE;
}
static void