Mercurial > pidgin.yaz
comparison 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 |
comparison
equal
deleted
inserted
replaced
21129:aed98822d825 | 21130:4ea59c6e57cd |
---|---|
159 MsnSoapConnection *conn = data; | 159 MsnSoapConnection *conn = data; |
160 | 160 |
161 conn->connected = TRUE; | 161 conn->connected = TRUE; |
162 | 162 |
163 if (conn->event_handle == 0) | 163 if (conn->event_handle == 0) |
164 conn->event_handle = g_idle_add(msn_soap_connection_run, conn); | 164 conn->event_handle = purple_timeout_add(0, msn_soap_connection_run, conn); |
165 } | 165 } |
166 | 166 |
167 static void | 167 static void |
168 msn_soap_error_cb(PurpleSslConnection *ssl, PurpleSslErrorType error, | 168 msn_soap_error_cb(PurpleSslConnection *ssl, PurpleSslErrorType error, |
169 gpointer data) | 169 gpointer data) |
258 | 258 |
259 static void | 259 static void |
260 msn_soap_read_cb(gpointer data, gint fd, PurpleInputCondition cond) | 260 msn_soap_read_cb(gpointer data, gint fd, PurpleInputCondition cond) |
261 { | 261 { |
262 MsnSoapConnection *conn = data; | 262 MsnSoapConnection *conn = data; |
263 int count; | 263 int count = 0, cnt; |
264 char buf[8192]; | 264 char buf[8192]; |
265 char *linebreak; | 265 char *linebreak; |
266 char *cursor; | 266 char *cursor; |
267 gboolean handled = FALSE; | 267 gboolean handled = FALSE; |
268 | 268 |
269 g_return_if_fail(cond == PURPLE_INPUT_READ); | 269 if (conn->message == NULL) { |
270 | 270 conn->message = msn_soap_message_new(NULL, NULL); |
271 count = purple_ssl_read(conn->ssl, buf, sizeof(buf)); | 271 } |
272 purple_debug_info("soap", "read %d bytes\n", count); | 272 |
273 if (count < 0 && errno == EAGAIN) | 273 while ((cnt = purple_ssl_read(conn->ssl, buf, sizeof(buf))) > 0) { |
274 return; | 274 purple_debug_info("soap", "read %d bytes\n", cnt); |
275 else if (count <= 0) { | 275 count += cnt; |
276 purple_debug_info("soap", "read: %s\n", g_strerror(errno)); | 276 if (conn->buf == NULL) { |
277 conn->buf = g_string_new_len(buf, cnt); | |
278 } else { | |
279 g_string_append_len(conn->buf, buf, cnt); | |
280 } | |
281 } | |
282 | |
283 if (cnt < 0) { | |
284 if (errno != EAGAIN) { | |
285 purple_debug_info("soap", "read: %s\n", g_strerror(errno)); | |
286 purple_ssl_close(conn->ssl); | |
287 conn->ssl = NULL; | |
288 msn_soap_connection_handle_next(conn); | |
289 return; | |
290 } else if (count == 0) { | |
291 return; | |
292 } | |
293 } | |
294 | |
295 if (cnt == 0 && count == 0) { | |
296 purple_debug_info("soap", "msn_soap_read_cb() called, but no data available?\n"); | |
277 purple_ssl_close(conn->ssl); | 297 purple_ssl_close(conn->ssl); |
278 conn->ssl = NULL; | 298 conn->ssl = NULL; |
279 msn_soap_connection_handle_next(conn); | 299 msn_soap_connection_handle_next(conn); |
280 return; | 300 return; |
281 } | |
282 | |
283 if (conn->message == NULL) { | |
284 conn->message = msn_soap_message_new(NULL, NULL); | |
285 } | |
286 | |
287 if (conn->buf == NULL) { | |
288 conn->buf = g_string_new_len(buf, count); | |
289 } else { | |
290 g_string_append_len(conn->buf, buf, count); | |
291 } | 301 } |
292 | 302 |
293 purple_debug_info("soap", "current %s\n", conn->buf->str); | 303 purple_debug_info("soap", "current %s\n", conn->buf->str); |
294 | 304 |
295 cursor = conn->buf->str + conn->handled_len; | 305 cursor = conn->buf->str + conn->handled_len; |