aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2006-05-07 20:07:43 +0200
committerWilmer van der Gaast <wilmer@gaast.net>2006-05-07 20:07:43 +0200
commita0d04d6253cf70877a11156059209e1f9a2efe31 (patch)
treec320551f230a030d83748797e8a5de0f5953a1fa
parent64d1f45ed9ccfd90ba17592ac980dcb3436f9548 (diff)
Got rid of all GLib GIOChannel-related calls outside proxy.c
-rw-r--r--bitlbee.c55
-rw-r--r--bitlbee.h5
-rw-r--r--ipc.c29
-rw-r--r--irc.c28
-rw-r--r--irc.h1
5 files changed, 49 insertions, 69 deletions
diff --git a/bitlbee.c b/bitlbee.c
index 3aca30c5..fb04897d 100644
--- a/bitlbee.c
+++ b/bitlbee.c
@@ -33,7 +33,7 @@
#include <stdio.h>
#include <errno.h>
-gboolean bitlbee_io_new_client( GIOChannel *source, GIOCondition condition, gpointer data );
+void bitlbee_io_new_client( gpointer data, gint source, GaimInputCondition 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 = gaim_input_add( global.listen_socket, GAIM_INPUT_READ, bitlbee_io_new_client, NULL );
#ifndef _WIN32
if( !global.conf->nofork )
@@ -146,34 +144,28 @@ int bitlbee_inetd_init()
return( 0 );
}
-gboolean bitlbee_io_current_client_read( GIOChannel *source, GIOCondition condition, gpointer data )
+void bitlbee_io_current_client_read( gpointer data, gint source, GaimInputCondition 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 )
{
irc_abort( irc, 1, "Connection reset by peer" );
- return FALSE;
+ goto no_more_events;
}
else if( st < 0 )
{
if( sockerr_again() )
{
- return TRUE;
+ return;
}
else
{
irc_abort( irc, 1, "Read error: %s", strerror( errno ) );
- return FALSE;
+ goto no_more_events;
}
}
@@ -194,27 +186,31 @@ gboolean bitlbee_io_current_client_read( GIOChannel *source, GIOCondition condit
if( !g_slist_find( irc_connection_list, irc ) )
{
log_message( LOGLVL_WARNING, "Abnormal termination of connection with fd %d.", irc->fd );
- return FALSE;
+ goto no_more_events;
}
/* Very naughty, go read the RFCs! >:) */
if( irc->readbuffer && ( strlen( irc->readbuffer ) > 1024 ) )
{
irc_abort( irc, 0, "Maximum line length exceeded" );
- return FALSE;
+ goto no_more_events;
}
- return TRUE;
+ return;
+
+no_more_events:
+ gaim_input_remove( irc->r_watch_source_id );
+ irc->r_watch_source_id = 0;
}
-gboolean bitlbee_io_current_client_write( GIOChannel *source, GIOCondition condition, gpointer data )
+void bitlbee_io_current_client_write( gpointer data, gint source, GaimInputCondition cond )
{
irc_t *irc = data;
int st, size;
char *temp;
if( irc->sendbuffer == NULL )
- return( FALSE );
+ goto no_more_events;
size = strlen( irc->sendbuffer );
st = write( irc->fd, irc->sendbuffer, size );
@@ -222,23 +218,22 @@ gboolean bitlbee_io_current_client_write( GIOChannel *source, GIOCondition condi
if( st == 0 || ( st < 0 && !sockerr_again() ) )
{
irc_abort( irc, 1, "Write error: %s", strerror( errno ) );
- return FALSE;
+ goto no_more_events;
}
else if( st < 0 ) /* && sockerr_again() */
{
- return TRUE;
+ return;
}
if( st == size )
{
g_free( irc->sendbuffer );
irc->sendbuffer = NULL;
- irc->w_watch_source_id = 0;
if( irc->status == USTATUS_SHUTDOWN )
irc_free( irc );
- return( FALSE );
+ goto no_more_events;
}
else
{
@@ -246,13 +241,17 @@ gboolean bitlbee_io_current_client_write( GIOChannel *source, GIOCondition condi
g_free( irc->sendbuffer );
irc->sendbuffer = temp;
- return( TRUE );
+ return;
}
+
+no_more_events:
+ gaim_input_remove( irc->w_watch_source_id );
+ irc->w_watch_source_id = 0;
}
-gboolean bitlbee_io_new_client( GIOChannel *source, GIOCondition condition, gpointer data )
+void bitlbee_io_new_client( gpointer data, gint source, GaimInputCondition 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;
@@ -260,7 +259,7 @@ gboolean bitlbee_io_new_client( GIOChannel *source, GIOCondition condition, gpoi
if( new_socket == -1 )
{
log_message( LOGLVL_WARNING, "Could not accept new connection: %s", strerror( errno ) );
- return TRUE;
+ return;
}
if( global.conf->runmode == RUNMODE_FORKDAEMON )
@@ -319,8 +318,6 @@ gboolean bitlbee_io_new_client( GIOChannel *source, GIOCondition condition, gpoi
log_message( LOGLVL_INFO, "Creating new connection with fd %d.", new_socket );
irc_new( new_socket );
}
-
- return TRUE;
}
void bitlbee_shutdown( gpointer data )
diff --git a/bitlbee.h b/bitlbee.h
index 4da87ec6..00e5ce97 100644
--- a/bitlbee.h
+++ b/bitlbee.h
@@ -111,6 +111,7 @@ extern char *CONF_FILE;
#include "query.h"
#include "sock.h"
#include "util.h"
+#include "proxy.h"
typedef struct global {
/* In forked mode, child processes store the fd of the IPC socket here. */
@@ -127,8 +128,8 @@ typedef struct global {
int bitlbee_daemon_init( void );
int bitlbee_inetd_init( void );
-gboolean bitlbee_io_current_client_read( GIOChannel *source, GIOCondition condition, gpointer data );
-gboolean bitlbee_io_current_client_write( GIOChannel *source, GIOCondition condition, gpointer data );
+void bitlbee_io_current_client_read( gpointer data, gint source, GaimInputCondition cond );
+void bitlbee_io_current_client_write( gpointer data, gint source, GaimInputCondition cond );
void root_command_string( irc_t *irc, user_t *u, char *command, int flags );
void root_command( irc_t *irc, char *command[] );
diff --git a/ipc.c b/ipc.c
index 48bd574a..c16acd72 100644
--- a/ipc.c
+++ b/ipc.c
@@ -462,25 +462,21 @@ void ipc_master_set_statefile( char *fn )
}
-static gboolean new_ipc_client (GIOChannel *gio, GIOCondition cond, gpointer data)
+static void new_ipc_client( gpointer data, gint serversock, GaimInputCondition cond )
{
struct bitlbee_child *child = g_new0( struct bitlbee_child, 1 );
- int serversock;
-
- serversock = g_io_channel_unix_get_fd(gio);
-
- child->ipc_fd = accept(serversock, NULL, 0);
-
- if (child->ipc_fd == -1) {
+
+ child->ipc_fd = accept( serversock, NULL, 0 );
+
+ if( child->ipc_fd == -1 )
+ {
log_message( LOGLVL_WARNING, "Unable to accept connection on UNIX domain socket: %s", strerror(errno) );
- return TRUE;
+ return;
}
child->ipc_inpa = gaim_input_add( child->ipc_fd, GAIM_INPUT_READ, ipc_master_read, child );
-
+
child_list = g_slist_append( child_list, child );
-
- return TRUE;
}
#ifndef _WIN32
@@ -488,7 +484,6 @@ int ipc_master_listen_socket()
{
struct sockaddr_un un_addr;
int serversock;
- GIOChannel *gio;
/* Clean up old socket files that were hanging around.. */
if (unlink(IPCSOCKET) == -1 && errno != ENOENT) {
@@ -516,14 +511,8 @@ int ipc_master_listen_socket()
return 0;
}
- gio = g_io_channel_unix_new(serversock);
+ gaim_input_add( serversock, GAIM_INPUT_READ, new_ipc_client, NULL );
- if (gio == NULL) {
- log_message( LOGLVL_WARNING, "Unable to create IO channel for unix socket" );
- return 0;
- }
-
- g_io_add_watch(gio, G_IO_IN, new_ipc_client, NULL);
return 1;
}
#else
diff --git a/irc.c b/irc.c
index 44fc9ad3..53dea8ba 100644
--- a/irc.c
+++ b/irc.c
@@ -53,15 +53,9 @@ irc_t *irc_new( int fd )
irc = g_new0( irc_t, 1 );
irc->fd = fd;
- irc->io_channel = g_io_channel_unix_new( fd );
-#ifdef GLIB2
- g_io_channel_set_encoding (irc->io_channel, NULL, NULL);
- g_io_channel_set_buffered (irc->io_channel, FALSE);
- g_io_channel_set_flags( irc->io_channel, G_IO_FLAG_NONBLOCK, NULL );
-#else
- fcntl( irc->fd, F_SETFL, O_NONBLOCK);
-#endif
- 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 );
+ sock_make_nonblocking( irc->fd );
+
+ irc->r_watch_source_id = gaim_input_add( irc->fd, GAIM_INPUT_READ, bitlbee_io_current_client_read, irc );
irc->status = USTATUS_OFFLINE;
irc->last_pong = gettime();
@@ -228,7 +222,6 @@ void irc_free(irc_t * irc)
if( irc->w_watch_source_id > 0 )
g_source_remove( irc->w_watch_source_id );
- g_io_channel_unref( irc->io_channel );
irc_connection_list = g_slist_remove( irc_connection_list, irc );
for (account = irc->accounts; account; account = account->next) {
@@ -599,19 +592,20 @@ void irc_vawrite( irc_t *irc, char *format, va_list params )
}
strcat( line, "\r\n" );
- if( irc->sendbuffer != NULL ) {
+ if( irc->sendbuffer != NULL )
+ {
size = strlen( irc->sendbuffer ) + strlen( line );
irc->sendbuffer = g_renew ( char, irc->sendbuffer, size + 1 );
strcpy( ( irc->sendbuffer + strlen( irc->sendbuffer ) ), line );
}
- else
- irc->sendbuffer = g_strdup(line);
-
- if( irc->w_watch_source_id == 0 )
+ else
{
- irc->w_watch_source_id = g_io_add_watch( irc->io_channel, G_IO_OUT, bitlbee_io_current_client_write, irc );
+ irc->sendbuffer = g_strdup(line);
}
+ if( irc->w_watch_source_id == 0 )
+ irc->w_watch_source_id = gaim_input_add( irc->fd, GAIM_INPUT_WRITE, bitlbee_io_current_client_write, irc );
+
return;
}
@@ -635,7 +629,7 @@ void irc_write_all( int now, char *format, ... )
irc_vawrite( temp->data, format, params );
if( now )
{
- bitlbee_io_current_client_write( irc->io_channel, G_IO_OUT, irc );
+ bitlbee_io_current_client_write( irc, irc->fd, GAIM_INPUT_WRITE );
}
temp = temp->next;
}
diff --git a/irc.h b/irc.h
index 86721058..394e1d54 100644
--- a/irc.h
+++ b/irc.h
@@ -92,7 +92,6 @@ typedef struct irc
struct help *help;
struct set *set;
- GIOChannel *io_channel;
gint r_watch_source_id;
gint w_watch_source_id;
gint ping_source_id;