Mercurial > pidgin.yaz
comparison libpurple/protocols/msn/soap2.c @ 23507:0a762c2271ac
Patch from tomgr to resend once if the connection is down, fixes #5379
author | Ka-Hing Cheung <khc@hxbc.us> |
---|---|
date | Wed, 14 May 2008 04:39:54 +0000 |
parents | d756a0477c06 |
children | 06b491a23d19 |
comparison
equal
deleted
inserted
replaced
23506:d756a0477c06 | 23507:0a762c2271ac |
---|---|
80 MsnSoapMessage *message, const char *host, const char *path, | 80 MsnSoapMessage *message, const char *host, const char *path, |
81 MsnSoapCallback cb, gpointer cb_data, gboolean first); | 81 MsnSoapCallback cb, gpointer cb_data, gboolean first); |
82 | 82 |
83 static void msn_soap_request_destroy(MsnSoapRequest *req); | 83 static void msn_soap_request_destroy(MsnSoapRequest *req); |
84 static void msn_soap_connection_sanitize(MsnSoapConnection *conn, gboolean disconnect); | 84 static void msn_soap_connection_sanitize(MsnSoapConnection *conn, gboolean disconnect); |
85 static gboolean msn_soap_write_cb_internal(gpointer data, gint fd, PurpleInputCondition cond, gboolean initial); | |
85 | 86 |
86 static gboolean | 87 static gboolean |
87 msn_soap_cleanup_each(gpointer key, gpointer value, gpointer data) | 88 msn_soap_cleanup_each(gpointer key, gpointer value, gpointer data) |
88 { | 89 { |
89 MsnSoapConnection *conn = value; | 90 MsnSoapConnection *conn = value; |
418 } | 419 } |
419 | 420 |
420 static void | 421 static void |
421 msn_soap_write_cb(gpointer data, gint fd, PurpleInputCondition cond) | 422 msn_soap_write_cb(gpointer data, gint fd, PurpleInputCondition cond) |
422 { | 423 { |
424 msn_soap_write_cb_internal(data, fd, cond, FALSE); | |
425 } | |
426 | |
427 static gboolean | |
428 msn_soap_write_cb_internal(gpointer data, gint fd, PurpleInputCondition cond, | |
429 gboolean initial) | |
430 { | |
423 MsnSoapConnection *conn = data; | 431 MsnSoapConnection *conn = data; |
424 int written; | 432 int written; |
425 | 433 |
426 g_return_if_fail(cond == PURPLE_INPUT_WRITE); | 434 if (cond != PURPLE_INPUT_WRITE) return TRUE; |
427 | 435 |
428 written = purple_ssl_write(conn->ssl, conn->buf->str + conn->handled_len, | 436 written = purple_ssl_write(conn->ssl, conn->buf->str + conn->handled_len, |
429 conn->buf->len - conn->handled_len); | 437 conn->buf->len - conn->handled_len); |
430 | 438 |
431 if (written < 0 && errno == EAGAIN) | 439 if (written < 0 && errno == EAGAIN) |
432 return; | 440 return TRUE; |
433 else if (written <= 0) { | 441 else if (written <= 0) { |
434 purple_ssl_close(conn->ssl); | 442 purple_ssl_close(conn->ssl); |
435 conn->ssl = NULL; | 443 conn->ssl = NULL; |
436 msn_soap_connection_handle_next(conn); | 444 if (!initial) msn_soap_connection_handle_next(conn); |
437 return; | 445 return FALSE; |
438 } | 446 } |
439 | 447 |
440 conn->handled_len += written; | 448 conn->handled_len += written; |
441 | 449 |
442 if (conn->handled_len < conn->buf->len) | 450 if (conn->handled_len < conn->buf->len) |
443 return; | 451 return TRUE; |
444 | 452 |
445 /* we are done! */ | 453 /* we are done! */ |
446 g_string_free(conn->buf, TRUE); | 454 g_string_free(conn->buf, TRUE); |
447 conn->buf = NULL; | 455 conn->buf = NULL; |
448 conn->handled_len = 0; | 456 conn->handled_len = 0; |
452 conn->close_when_done = FALSE; | 460 conn->close_when_done = FALSE; |
453 | 461 |
454 purple_input_remove(conn->event_handle); | 462 purple_input_remove(conn->event_handle); |
455 conn->event_handle = purple_input_add(conn->ssl->fd, PURPLE_INPUT_READ, | 463 conn->event_handle = purple_input_add(conn->ssl->fd, PURPLE_INPUT_READ, |
456 msn_soap_read_cb, conn); | 464 msn_soap_read_cb, conn); |
465 return TRUE; | |
457 } | 466 } |
458 | 467 |
459 static gboolean | 468 static gboolean |
460 msn_soap_connection_run(gpointer data) | 469 msn_soap_connection_run(gpointer data) |
461 { | 470 { |
503 conn->handled_len = 0; | 512 conn->handled_len = 0; |
504 conn->current_request = req; | 513 conn->current_request = req; |
505 | 514 |
506 conn->event_handle = purple_input_add(conn->ssl->fd, | 515 conn->event_handle = purple_input_add(conn->ssl->fd, |
507 PURPLE_INPUT_WRITE, msn_soap_write_cb, conn); | 516 PURPLE_INPUT_WRITE, msn_soap_write_cb, conn); |
508 msn_soap_write_cb(conn, conn->ssl->fd, PURPLE_INPUT_WRITE); | 517 if (!msn_soap_write_cb_internal(conn, conn->ssl->fd, PURPLE_INPUT_WRITE, TRUE)) { |
518 /* Not connected => reconnect and retry */ | |
519 purple_debug_info("soap", "not connected, reconnecting"); | |
520 | |
521 conn->connected = FALSE; | |
522 conn->current_request = NULL; | |
523 msn_soap_connection_sanitize(conn, FALSE); | |
524 | |
525 g_queue_push_head(conn->queue, req); | |
526 conn->event_handle = purple_timeout_add(0, msn_soap_connection_run, conn); | |
527 } | |
509 | 528 |
510 g_free(body); | 529 g_free(body); |
511 } | 530 } |
512 } | 531 } |
513 | 532 |