From fc50d482ae5a7836fbf7c72df168b51d1cf714a5 Mon Sep 17 00:00:00 2001 From: Wilmer van der Gaast Date: Fri, 20 Jan 2006 13:21:24 +0100 Subject: irc_abort() does logging (including a reason) now. --- irc.c | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'irc.c') diff --git a/irc.c b/irc.c index 1055c3c8..f3e926f7 100644 --- a/irc.c +++ b/irc.c @@ -150,11 +150,42 @@ irc_t *irc_new( int fd ) return( irc ); } -void irc_abort( irc_t *irc ) +void irc_abort( irc_t *irc, int immed, char *format, ... ) { + va_list params; + + if( format != NULL ) + { + char *reason; + + va_start( params, format ); + reason = g_strdup_printf( format, params ); + va_end( params ); + + if( !immed ) + irc_write( irc, "ERROR :Closing link: %s", reason ); + + ipc_to_master_str( "OPERMSG :Client exiting: %s@%s [%s]\r\n", + irc->nick, irc->host, reason" ); + + g_free( reason ); + } + else + { + if( !immed ) + irc_write( irc, "ERROR :Closing link" ); + + ipc_to_master_str( "OPERMSG :Client exiting: %s@%s [%s]\r\n", + irc->nick, irc->host, "No reason given" ); + } + irc->status = USTATUS_SHUTDOWN; - if( irc->sendbuffer ) + if( irc->sendbuffer && !immed ) { + /* We won't read from this socket anymore. Instead, we'll connect a timer + to it that should shut down the connection in a second, just in case + bitlbee_.._write doesn't do it first. */ + g_source_remove( irc->r_watch_source_id ); irc->r_watch_source_id = g_timeout_add_full( G_PRIORITY_HIGH, 1000, (GSourceFunc) irc_free, irc, NULL ); } @@ -1622,8 +1653,7 @@ static gboolean irc_userping( gpointer _irc ) if( rv > 0 ) { - irc_write( irc, "ERROR :Closing Link: Ping Timeout: %d seconds", rv ); - irc_free( irc ); + irc_abort( irc, "ERROR :Closing Link: Ping Timeout: %d seconds", rv ); return FALSE; } -- cgit v1.2.3