Mercurial > pidgin
diff libpurple/protocols/msn/soap2.c @ 21130:4ea59c6e57cd
read as much from the fd as possible if we get a read event, hopefully will
fix a problem for people on OS X
author | Ka-Hing Cheung <khc@hxbc.us> |
---|---|
date | Sat, 03 Nov 2007 20:55:15 +0000 |
parents | f51152557d2f |
children | 8fcd795f627e |
line wrap: on
line diff
--- a/libpurple/protocols/msn/soap2.c Sat Nov 03 20:21:59 2007 +0000 +++ b/libpurple/protocols/msn/soap2.c Sat Nov 03 20:55:15 2007 +0000 @@ -161,7 +161,7 @@ conn->connected = TRUE; if (conn->event_handle == 0) - conn->event_handle = g_idle_add(msn_soap_connection_run, conn); + conn->event_handle = purple_timeout_add(0, msn_soap_connection_run, conn); } static void @@ -260,36 +260,46 @@ msn_soap_read_cb(gpointer data, gint fd, PurpleInputCondition cond) { MsnSoapConnection *conn = data; - int count; + int count = 0, cnt; char buf[8192]; char *linebreak; char *cursor; gboolean handled = FALSE; - g_return_if_fail(cond == PURPLE_INPUT_READ); + if (conn->message == NULL) { + conn->message = msn_soap_message_new(NULL, NULL); + } + + while ((cnt = purple_ssl_read(conn->ssl, buf, sizeof(buf))) > 0) { + purple_debug_info("soap", "read %d bytes\n", cnt); + count += cnt; + if (conn->buf == NULL) { + conn->buf = g_string_new_len(buf, cnt); + } else { + g_string_append_len(conn->buf, buf, cnt); + } + } - count = purple_ssl_read(conn->ssl, buf, sizeof(buf)); - purple_debug_info("soap", "read %d bytes\n", count); - if (count < 0 && errno == EAGAIN) - return; - else if (count <= 0) { - purple_debug_info("soap", "read: %s\n", g_strerror(errno)); + if (cnt < 0) { + if (errno != EAGAIN) { + purple_debug_info("soap", "read: %s\n", g_strerror(errno)); + purple_ssl_close(conn->ssl); + conn->ssl = NULL; + msn_soap_connection_handle_next(conn); + return; + } else if (count == 0) { + return; + } + } + + if (cnt == 0 && count == 0) { + purple_debug_info("soap", "msn_soap_read_cb() called, but no data available?\n"); purple_ssl_close(conn->ssl); conn->ssl = NULL; msn_soap_connection_handle_next(conn); return; } - if (conn->message == NULL) { - conn->message = msn_soap_message_new(NULL, NULL); - } - - if (conn->buf == NULL) { - conn->buf = g_string_new_len(buf, count); - } else { - g_string_append_len(conn->buf, buf, count); - } - purple_debug_info("soap", "current %s\n", conn->buf->str); cursor = conn->buf->str + conn->handled_len;