Changeset b72caac for irc.c


Ignore:
Timestamp:
2006-06-21T16:34:33Z (13 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
59f5c42a
Parents:
3af70b0 (diff), df417ca (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merging libevent branch: Events can now be handles by both glib and libevent.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • irc.c

    r3af70b0 rb72caac  
    2929#include "ipc.h"
    3030
    31 static gboolean irc_userping( gpointer _irc );
     31static gboolean irc_userping( gpointer _irc, int fd, b_input_condition cond );
    3232
    3333GSList *irc_connection_list = NULL;
     
    5454       
    5555        irc->fd = fd;
    56         irc->io_channel = g_io_channel_unix_new( fd );
    57         g_io_channel_set_encoding (irc->io_channel, NULL, NULL);
    58         g_io_channel_set_buffered (irc->io_channel, FALSE);
    59         g_io_channel_set_flags( irc->io_channel, G_IO_FLAG_NONBLOCK, NULL );
    60         irc->r_watch_source_id = g_io_add_watch( irc->io_channel, G_IO_IN | G_IO_ERR | G_IO_HUP, bitlbee_io_current_client_read, irc );
     56        sock_make_nonblocking( irc->fd );
     57       
     58        irc->r_watch_source_id = b_input_add( irc->fd, GAIM_INPUT_READ, bitlbee_io_current_client_read, irc );
    6159       
    6260        irc->status = USTATUS_OFFLINE;
     
    116114
    117115        if( global.conf->ping_interval > 0 && global.conf->ping_timeout > 0 )
    118                 irc->ping_source_id = g_timeout_add( global.conf->ping_interval * 1000, irc_userping, irc );
     116                irc->ping_source_id = b_timeout_add( global.conf->ping_interval * 1000, irc_userping, irc );
    119117       
    120118        irc_write( irc, ":%s NOTICE AUTH :%s", irc->myhost, "BitlBee-IRCd initialized, please go on" );
     
    186184                   bitlbee_.._write doesn't do it first. */
    187185               
    188                 g_source_remove( irc->r_watch_source_id );
    189                 irc->r_watch_source_id = g_timeout_add_full( G_PRIORITY_HIGH, 1000, (GSourceFunc) irc_free, irc, NULL );
     186                b_event_remove( irc->r_watch_source_id );
     187                irc->r_watch_source_id = b_timeout_add( 1000, (b_event_handler) irc_free, irc );
    190188        }
    191189        else
     
    220218       
    221219        if( irc->ping_source_id > 0 )
    222                 g_source_remove( irc->ping_source_id );
    223         g_source_remove( irc->r_watch_source_id );
     220                b_event_remove( irc->ping_source_id );
     221        b_event_remove( irc->r_watch_source_id );
    224222        if( irc->w_watch_source_id > 0 )
    225                 g_source_remove( irc->w_watch_source_id );
    226        
    227         g_io_channel_unref( irc->io_channel );
     223                b_event_remove( irc->w_watch_source_id );
     224       
    228225        irc_connection_list = g_slist_remove( irc_connection_list, irc );
    229226       
     
    275272                        if(user->host!=user->nick) g_free(user->host);
    276273                        if(user->realname!=user->nick) g_free(user->realname);
    277                         gaim_input_remove(user->sendbuf_timer);
     274                        b_event_remove(user->sendbuf_timer);
    278275                                       
    279276                        usertmp = user;
     
    325322       
    326323        if( global.conf->runmode == RUNMODE_INETD || global.conf->runmode == RUNMODE_FORKDAEMON )
    327                 g_main_quit( global.loop );
     324                b_main_quit();
    328325}
    329326
     
    579576        char line[IRC_MAX_LINE+1], *cs;
    580577               
    581         if( irc->quit )
     578        /* Don't try to write anything new anymore when shutting down. */
     579        if( irc->status == USTATUS_SHUTDOWN )
    582580                return;
    583581       
     
    596594        strcat( line, "\r\n" );
    597595       
    598         if( irc->sendbuffer != NULL ) {
     596        if( irc->sendbuffer != NULL )
     597        {
    599598                size = strlen( irc->sendbuffer ) + strlen( line );
    600599                irc->sendbuffer = g_renew ( char, irc->sendbuffer, size + 1 );
    601600                strcpy( ( irc->sendbuffer + strlen( irc->sendbuffer ) ), line );
    602601        }
    603         else
    604                 irc->sendbuffer = g_strdup(line);       
     602        else
     603        {
     604                irc->sendbuffer = g_strdup(line);
     605        }
    605606       
    606607        if( irc->w_watch_source_id == 0 )
    607608        {
    608                 irc->w_watch_source_id = g_io_add_watch( irc->io_channel, G_IO_OUT, bitlbee_io_current_client_write, irc );
     609                /* If the buffer is empty we can probably write, so call the write event handler
     610                   immediately. If it returns TRUE, it should be called again, so add the event to
     611                   the queue. If it's FALSE, we emptied the buffer and saved ourselves some work
     612                   in the event queue. */
     613                if( bitlbee_io_current_client_write( irc, irc->fd, GAIM_INPUT_WRITE ) )
     614                        irc->w_watch_source_id = b_input_add( irc->fd, GAIM_INPUT_WRITE, bitlbee_io_current_client_write, irc );
    609615        }
    610616       
     
    632638                if( now )
    633639                {
    634                         bitlbee_io_current_client_write( irc->io_channel, G_IO_OUT, irc );
     640                        bitlbee_io_current_client_write( irc, irc->fd, GAIM_INPUT_WRITE );
    635641                }
    636642                temp = temp->next;
     
    10351041}
    10361042
    1037 gboolean buddy_send_handler_delayed( gpointer data )
     1043static gboolean buddy_send_handler_delayed( gpointer data, gint fd, b_input_condition cond )
    10381044{
    10391045        user_t *u = data;
     
    10661072                {
    10671073                        /* Flush the buffer */
    1068                         g_source_remove( u->sendbuf_timer );
    1069                         buddy_send_handler_delayed( u );
     1074                        b_event_remove( u->sendbuf_timer );
     1075                        buddy_send_handler_delayed( u, -1, 0 );
    10701076                }
    10711077
     
    10911097               
    10921098                if( u->sendbuf_timer > 0 )
    1093                         g_source_remove( u->sendbuf_timer );
    1094                 u->sendbuf_timer = g_timeout_add( delay, buddy_send_handler_delayed, u );
     1099                        b_event_remove( u->sendbuf_timer );
     1100                u->sendbuf_timer = b_timeout_add( delay, buddy_send_handler_delayed, u );
    10951101        }
    10961102        else
     
    11761182   pongs from the user. When not connected yet, we don't ping but drop the
    11771183   connection when the user fails to connect in IRC_LOGIN_TIMEOUT secs. */
    1178 static gboolean irc_userping( gpointer _irc )
     1184static gboolean irc_userping( gpointer _irc, gint fd, b_input_condition cond )
    11791185{
    11801186        irc_t *irc = _irc;
Note: See TracChangeset for help on using the changeset viewer.