Changeset f1c2b21 for irc.c


Ignore:
Timestamp:
2010-07-10T15:08:02Z (9 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
e92c4f4
Parents:
534e406
Message:

Cleanup. Move some code to a more appropriate location, and show the old
connection a quit message instead of just breaking the connection.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • irc.c

    r534e406 rf1c2b21  
    619619}
    620620
     621/* Flush sendbuffer if you can. If it fails, fail silently and let some
     622   I/O event handler clean up. */
     623void irc_flush( irc_t *irc )
     624{
     625        ssize_t n;
     626        size_t len;
     627       
     628        if( irc->sendbuffer == NULL )
     629                return;
     630       
     631        len = strlen( irc->sendbuffer );
     632        if( ( n = send( irc->fd, irc->sendbuffer, len, 0 ) ) == len )
     633        {
     634                g_free( irc->sendbuffer );
     635                irc->sendbuffer = NULL;
     636               
     637                b_event_remove( irc->w_watch_source_id );
     638                irc->w_watch_source_id = 0;
     639        }
     640        else if( n > 0 )
     641        {
     642                char *s = g_strdup( irc->sendbuffer + n );
     643                g_free( irc->sendbuffer );
     644                irc->sendbuffer = s;
     645        }
     646        /* Otherwise something went wrong and we don't currently care
     647           what the error was. We may or may not succeed later, we
     648           were just trying to flush the buffer immediately. */
     649}
     650
     651/* Meant for takeover functionality. Transfer an IRC connection to a different
     652   socket. */
     653void irc_switch_fd( irc_t *irc, int fd )
     654{
     655        irc_write( irc, "ERROR :Transferring session to a new connection" );
     656        irc_flush( irc ); /* Write it now or forget about it forever. */
     657       
     658        if( irc->sendbuffer )
     659        {
     660                b_event_remove( irc->w_watch_source_id );
     661                g_free( irc->sendbuffer );
     662                irc->sendbuffer = irc->w_watch_source_id = 0;
     663        }
     664       
     665        b_event_remove( irc->r_watch_source_id );
     666        closesocket( irc->fd );
     667        irc->fd = fd;
     668        irc->r_watch_source_id = b_input_add( irc->fd, B_EV_IO_READ, bitlbee_io_current_client_read, irc );
     669}
     670
     671void irc_sync( irc_t *irc )
     672{
     673        GSList *l;
     674       
     675        irc_write( irc, ":%s!%s@%s MODE %s :+%s", irc->user->nick,
     676                   irc->user->user, irc->user->host, irc->user->nick,
     677                   irc->umode );
     678       
     679        for( l = irc->channels; l; l = l->next )
     680        {
     681                irc_channel_t *ic = l->data;
     682                if( ic->flags & IRC_CHANNEL_JOINED )
     683                        irc_send_join( ic, irc->user );
     684        }
     685}
     686
     687void irc_desync( irc_t *irc )
     688{
     689        GSList *l;
     690       
     691        for( l = irc->channels; l; l = l->next )
     692                irc_channel_del_user( l->data, irc->user, IRC_CDU_KICK,
     693                                      "Switching to old session" );
     694       
     695        irc_write( irc, ":%s!%s@%s MODE %s :-%s", irc->user->nick,
     696                   irc->user->user, irc->user->host, irc->user->nick,
     697                   irc->umode );
     698}
     699
    621700int irc_check_login( irc_t *irc )
    622701{
Note: See TracChangeset for help on using the changeset viewer.