diff options
author | Wilmer van der Gaast <wilmer@gaast.net> | 2008-01-12 17:24:38 +0000 |
---|---|---|
committer | Wilmer van der Gaast <wilmer@gaast.net> | 2008-01-12 17:24:38 +0000 |
commit | 59f527b6eefaae452533170f52a96903ef63a209 (patch) | |
tree | 8731e7b8bf82ba45d78aca3f85ba9e9997cd4407 /protocols/msn/sb.c | |
parent | e64de00bf2d99962182243983e8c09decaa36eb4 (diff) |
When a switchboard connection dies (at the TCP level) and there are still
queued messages, they will now be moved back to the main queue and a new
sb will be created to try to send the messages again. I hope this will
solve some/most/all of the "Closing switchboard with unsent messages"
problems, but can't be sure since this problem isn't very easy to reproduce.
At least it should solve the ones caused by keeping spare switchboards
around. Also enabling switchboard debugging output if configured with
--debug=1, at least for now this will be useful.
Diffstat (limited to 'protocols/msn/sb.c')
-rw-r--r-- | protocols/msn/sb.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/protocols/msn/sb.c b/protocols/msn/sb.c index 8c0afca6..cdf2e8ad 100644 --- a/protocols/msn/sb.c +++ b/protocols/msn/sb.c @@ -276,16 +276,59 @@ gboolean msn_sb_connected( gpointer data, gint source, b_input_condition cond ) static gboolean msn_sb_callback( gpointer data, gint source, b_input_condition cond ) { struct msn_switchboard *sb = data; + struct im_connection *ic = sb->ic; + struct msn_data *md = ic->proto_data; if( msn_handler( sb->handler ) == -1 ) { + time_t now = time( NULL ); + + if( now - md->first_sb_failure > 600 ) + { + /* It's not really the first one, but the start of this "series". + With this, the warning below will be shown only if this happens + at least three times in ten minutes. This algorithm isn't + perfect, but for this purpose it will do. */ + md->first_sb_failure = now; + md->sb_failures = 0; + } + debug( "Error: Switchboard died" ); + if( ++ md->sb_failures >= 3 ) + imcb_log( ic, "Warning: Many switchboard failures on MSN connection. " + "There might be problems delivering your messages." ); + + if( sb->msgq != NULL ) + { + char buf[1024]; + + if( md->msgq == NULL ) + { + md->msgq = sb->msgq; + } + else + { + GSList *l; + + for( l = md->msgq; l->next; l = l->next ); + l->next = sb->msgq; + } + sb->msgq = NULL; + + debug( "Moved queued messages back to the main queue, creating a new switchboard to retry." ); + g_snprintf( buf, sizeof( buf ), "XFR %d SB\r\n", ++md->trId ); + if( !msn_write( ic, buf, strlen( buf ) ) ) + return FALSE; + } + msn_sb_destroy( sb ); return FALSE; } else + { return TRUE; + } } static int msn_sb_command( gpointer data, char **cmd, int num_parts ) |