diff options
author | Wilmer van der Gaast <wilmer@gaast.net> | 2006-06-21 18:34:33 +0200 |
---|---|---|
committer | Wilmer van der Gaast <wilmer@gaast.net> | 2006-06-21 18:34:33 +0200 |
commit | b72caac09b5944ee9954eb18262fe45228665570 (patch) | |
tree | b44353f8ab3d23702f49e129d53b787952fe6546 /bitlbee.c | |
parent | 3af70b06b2f0fb0fb41a041f6d86e3711b9eea3f (diff) | |
parent | df417ca6657bc824e1dbd4a6026284656a42ce40 (diff) |
Merging libevent branch: Events can now be handles by both glib and libevent.
Diffstat (limited to 'bitlbee.c')
-rw-r--r-- | bitlbee.c | 40 |
1 files changed, 17 insertions, 23 deletions
@@ -33,7 +33,7 @@ #include <stdio.h> #include <errno.h> -gboolean bitlbee_io_new_client( GIOChannel *source, GIOCondition condition, gpointer data ); +static gboolean bitlbee_io_new_client( gpointer data, gint fd, b_input_condition condition ); int bitlbee_daemon_init() { @@ -43,7 +43,6 @@ int bitlbee_daemon_init() struct sockaddr_in listen_addr; #endif int i; - GIOChannel *ch; FILE *fp; log_link( LOGLVL_ERROR, LOGOUTPUT_SYSLOG ); @@ -90,8 +89,7 @@ int bitlbee_daemon_init() return( -1 ); } - ch = g_io_channel_unix_new( global.listen_socket ); - global.listen_watch_source_id = g_io_add_watch( ch, G_IO_IN, bitlbee_io_new_client, NULL ); + global.listen_watch_source_id = b_input_add( global.listen_socket, GAIM_INPUT_READ, bitlbee_io_new_client, NULL ); #ifndef _WIN32 if( !global.conf->nofork ) @@ -146,18 +144,12 @@ int bitlbee_inetd_init() return( 0 ); } -gboolean bitlbee_io_current_client_read( GIOChannel *source, GIOCondition condition, gpointer data ) +gboolean bitlbee_io_current_client_read( gpointer data, gint fd, b_input_condition cond ) { irc_t *irc = data; char line[513]; int st; - if( condition & G_IO_ERR || condition & G_IO_HUP ) - { - irc_abort( irc, 1, "Read error" ); - return FALSE; - } - st = read( irc->fd, line, sizeof( line ) - 1 ); if( st == 0 ) { @@ -193,7 +185,7 @@ gboolean bitlbee_io_current_client_read( GIOChannel *source, GIOCondition condit /* Normally, irc_process() shouldn't call irc_free() but irc_abort(). Just in case: */ if( !g_slist_find( irc_connection_list, irc ) ) { - log_message( LOGLVL_WARNING, "Abnormal termination of connection with fd %d.", irc->fd ); + log_message( LOGLVL_WARNING, "Abnormal termination of connection with fd %d.", fd ); return FALSE; } @@ -207,14 +199,14 @@ gboolean bitlbee_io_current_client_read( GIOChannel *source, GIOCondition condit return TRUE; } -gboolean bitlbee_io_current_client_write( GIOChannel *source, GIOCondition condition, gpointer data ) +gboolean bitlbee_io_current_client_write( gpointer data, gint fd, b_input_condition cond ) { irc_t *irc = data; int st, size; char *temp; if( irc->sendbuffer == NULL ) - return( FALSE ); + return FALSE; size = strlen( irc->sendbuffer ); st = write( irc->fd, irc->sendbuffer, size ); @@ -238,7 +230,7 @@ gboolean bitlbee_io_current_client_write( GIOChannel *source, GIOCondition condi if( irc->status & USTATUS_SHUTDOWN ) irc_free( irc ); - return( FALSE ); + return FALSE; } else { @@ -246,13 +238,13 @@ gboolean bitlbee_io_current_client_write( GIOChannel *source, GIOCondition condi g_free( irc->sendbuffer ); irc->sendbuffer = temp; - return( TRUE ); + return TRUE; } } -gboolean bitlbee_io_new_client( GIOChannel *source, GIOCondition condition, gpointer data ) +static gboolean bitlbee_io_new_client( gpointer data, gint fd, b_input_condition condition ) { - size_t size = sizeof( struct sockaddr_in ); + socklen_t size = sizeof( struct sockaddr_in ); struct sockaddr_in conn_info; int new_socket = accept( global.listen_socket, (struct sockaddr *) &conn_info, &size ); pid_t client_pid = 0; @@ -285,7 +277,7 @@ gboolean bitlbee_io_new_client( GIOChannel *source, GIOCondition condition, gpoi child = g_new0( struct bitlbee_child, 1 ); child->pid = client_pid; child->ipc_fd = fds[0]; - child->ipc_inpa = gaim_input_add( child->ipc_fd, GAIM_INPUT_READ, ipc_master_read, child ); + child->ipc_inpa = b_input_add( child->ipc_fd, GAIM_INPUT_READ, ipc_master_read, child ); child_list = g_slist_append( child_list, child ); log_message( LOGLVL_INFO, "Creating new subprocess with pid %d.", client_pid ); @@ -300,14 +292,14 @@ gboolean bitlbee_io_new_client( GIOChannel *source, GIOCondition condition, gpoi /* Close the listening socket, we're a client. */ close( global.listen_socket ); - g_source_remove( global.listen_watch_source_id ); + b_event_remove( global.listen_watch_source_id ); /* Make the connection. */ irc = irc_new( new_socket ); /* We can store the IPC fd there now. */ global.listen_socket = fds[1]; - global.listen_watch_source_id = gaim_input_add( fds[1], GAIM_INPUT_READ, ipc_child_read, irc ); + global.listen_watch_source_id = b_input_add( fds[1], GAIM_INPUT_READ, ipc_child_read, irc ); close( fds[0] ); @@ -323,12 +315,14 @@ gboolean bitlbee_io_new_client( GIOChannel *source, GIOCondition condition, gpoi return TRUE; } -void bitlbee_shutdown( gpointer data ) +gboolean bitlbee_shutdown( gpointer data, gint fd, b_input_condition cond ) { /* Try to save data for all active connections (if desired). */ while( irc_connection_list != NULL ) irc_free( irc_connection_list->data ); /* We'll only reach this point when not running in inetd mode: */ - g_main_quit( global.loop ); + b_main_quit(); + + return FALSE; } |