Changeset a0d04d6
- Timestamp:
- 2006-05-07T18:07:43Z (18 years ago)
- Branches:
- master
- Children:
- ecf8fa8
- Parents:
- 64d1f45
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
bitlbee.c
r64d1f45 ra0d04d6 34 34 #include <errno.h> 35 35 36 gboolean bitlbee_io_new_client( GIOChannel *source, GIOCondition condition, gpointer data);36 void bitlbee_io_new_client( gpointer data, gint source, GaimInputCondition condition ); 37 37 38 38 int bitlbee_daemon_init() … … 44 44 #endif 45 45 int i; 46 GIOChannel *ch;47 46 FILE *fp; 48 47 … … 91 90 } 92 91 93 ch = g_io_channel_unix_new( global.listen_socket ); 94 global.listen_watch_source_id = g_io_add_watch( ch, G_IO_IN, bitlbee_io_new_client, NULL ); 92 global.listen_watch_source_id = gaim_input_add( global.listen_socket, GAIM_INPUT_READ, bitlbee_io_new_client, NULL ); 95 93 96 94 #ifndef _WIN32 … … 147 145 } 148 146 149 gboolean bitlbee_io_current_client_read( GIOChannel *source, GIOCondition condition, gpointer data)147 void bitlbee_io_current_client_read( gpointer data, gint source, GaimInputCondition cond ) 150 148 { 151 149 irc_t *irc = data; … … 153 151 int st; 154 152 155 if( condition & G_IO_ERR || condition & G_IO_HUP )156 {157 irc_abort( irc, 1, "Read error" );158 return FALSE;159 }160 161 153 st = read( irc->fd, line, sizeof( line ) - 1 ); 162 154 if( st == 0 ) 163 155 { 164 156 irc_abort( irc, 1, "Connection reset by peer" ); 165 return FALSE;157 goto no_more_events; 166 158 } 167 159 else if( st < 0 ) … … 169 161 if( sockerr_again() ) 170 162 { 171 return TRUE;163 return; 172 164 } 173 165 else 174 166 { 175 167 irc_abort( irc, 1, "Read error: %s", strerror( errno ) ); 176 return FALSE;168 goto no_more_events; 177 169 } 178 170 } … … 195 187 { 196 188 log_message( LOGLVL_WARNING, "Abnormal termination of connection with fd %d.", irc->fd ); 197 return FALSE;189 goto no_more_events; 198 190 } 199 191 … … 202 194 { 203 195 irc_abort( irc, 0, "Maximum line length exceeded" ); 204 return FALSE; 205 } 206 207 return TRUE; 208 } 209 210 gboolean bitlbee_io_current_client_write( GIOChannel *source, GIOCondition condition, gpointer data ) 196 goto no_more_events; 197 } 198 199 return; 200 201 no_more_events: 202 gaim_input_remove( irc->r_watch_source_id ); 203 irc->r_watch_source_id = 0; 204 } 205 206 void bitlbee_io_current_client_write( gpointer data, gint source, GaimInputCondition cond ) 211 207 { 212 208 irc_t *irc = data; … … 215 211 216 212 if( irc->sendbuffer == NULL ) 217 return( FALSE );213 goto no_more_events; 218 214 219 215 size = strlen( irc->sendbuffer ); … … 223 219 { 224 220 irc_abort( irc, 1, "Write error: %s", strerror( errno ) ); 225 return FALSE;221 goto no_more_events; 226 222 } 227 223 else if( st < 0 ) /* && sockerr_again() */ 228 224 { 229 return TRUE;225 return; 230 226 } 231 227 … … 234 230 g_free( irc->sendbuffer ); 235 231 irc->sendbuffer = NULL; 236 irc->w_watch_source_id = 0;237 232 238 233 if( irc->status == USTATUS_SHUTDOWN ) 239 234 irc_free( irc ); 240 235 241 return( FALSE );236 goto no_more_events; 242 237 } 243 238 else … … 247 242 irc->sendbuffer = temp; 248 243 249 return( TRUE ); 250 } 251 } 252 253 gboolean bitlbee_io_new_client( GIOChannel *source, GIOCondition condition, gpointer data ) 254 { 255 size_t size = sizeof( struct sockaddr_in ); 244 return; 245 } 246 247 no_more_events: 248 gaim_input_remove( irc->w_watch_source_id ); 249 irc->w_watch_source_id = 0; 250 } 251 252 void bitlbee_io_new_client( gpointer data, gint source, GaimInputCondition condition ) 253 { 254 socklen_t size = sizeof( struct sockaddr_in ); 256 255 struct sockaddr_in conn_info; 257 256 int new_socket = accept( global.listen_socket, (struct sockaddr *) &conn_info, &size ); … … 261 260 { 262 261 log_message( LOGLVL_WARNING, "Could not accept new connection: %s", strerror( errno ) ); 263 return TRUE;262 return; 264 263 } 265 264 … … 320 319 irc_new( new_socket ); 321 320 } 322 323 return TRUE;324 321 } 325 322 -
bitlbee.h
r64d1f45 ra0d04d6 112 112 #include "sock.h" 113 113 #include "util.h" 114 #include "proxy.h" 114 115 115 116 typedef struct global { … … 128 129 int bitlbee_inetd_init( void ); 129 130 130 gboolean bitlbee_io_current_client_read( GIOChannel *source, GIOCondition condition, gpointer data);131 gboolean bitlbee_io_current_client_write( GIOChannel *source, GIOCondition condition, gpointer data);131 void bitlbee_io_current_client_read( gpointer data, gint source, GaimInputCondition cond ); 132 void bitlbee_io_current_client_write( gpointer data, gint source, GaimInputCondition cond ); 132 133 133 134 void root_command_string( irc_t *irc, user_t *u, char *command, int flags ); -
ipc.c
r64d1f45 ra0d04d6 463 463 464 464 465 static gboolean new_ipc_client (GIOChannel *gio, GIOCondition cond, gpointer data)465 static void new_ipc_client( gpointer data, gint serversock, GaimInputCondition cond ) 466 466 { 467 467 struct bitlbee_child *child = g_new0( struct bitlbee_child, 1 ); 468 int serversock; 469 470 serversock = g_io_channel_unix_get_fd(gio); 471 472 child->ipc_fd = accept(serversock, NULL, 0); 473 474 if (child->ipc_fd == -1) { 468 469 child->ipc_fd = accept( serversock, NULL, 0 ); 470 471 if( child->ipc_fd == -1 ) 472 { 475 473 log_message( LOGLVL_WARNING, "Unable to accept connection on UNIX domain socket: %s", strerror(errno) ); 476 return TRUE;474 return; 477 475 } 478 476 479 477 child->ipc_inpa = gaim_input_add( child->ipc_fd, GAIM_INPUT_READ, ipc_master_read, child ); 480 478 481 479 child_list = g_slist_append( child_list, child ); 482 483 return TRUE;484 480 } 485 481 … … 489 485 struct sockaddr_un un_addr; 490 486 int serversock; 491 GIOChannel *gio;492 487 493 488 /* Clean up old socket files that were hanging around.. */ … … 517 512 } 518 513 519 gio = g_io_channel_unix_new(serversock); 520 521 if (gio == NULL) { 522 log_message( LOGLVL_WARNING, "Unable to create IO channel for unix socket" ); 523 return 0; 524 } 525 526 g_io_add_watch(gio, G_IO_IN, new_ipc_client, NULL); 514 gaim_input_add( serversock, GAIM_INPUT_READ, new_ipc_client, NULL ); 515 527 516 return 1; 528 517 } -
irc.c
r64d1f45 ra0d04d6 54 54 55 55 irc->fd = fd; 56 irc->io_channel = g_io_channel_unix_new( fd ); 57 #ifdef GLIB2 58 g_io_channel_set_encoding (irc->io_channel, NULL, NULL); 59 g_io_channel_set_buffered (irc->io_channel, FALSE); 60 g_io_channel_set_flags( irc->io_channel, G_IO_FLAG_NONBLOCK, NULL ); 61 #else 62 fcntl( irc->fd, F_SETFL, O_NONBLOCK); 63 #endif 64 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 = gaim_input_add( irc->fd, GAIM_INPUT_READ, bitlbee_io_current_client_read, irc ); 65 59 66 60 irc->status = USTATUS_OFFLINE; … … 229 223 g_source_remove( irc->w_watch_source_id ); 230 224 231 g_io_channel_unref( irc->io_channel );232 225 irc_connection_list = g_slist_remove( irc_connection_list, irc ); 233 226 … … 600 593 strcat( line, "\r\n" ); 601 594 602 if( irc->sendbuffer != NULL ) { 595 if( irc->sendbuffer != NULL ) 596 { 603 597 size = strlen( irc->sendbuffer ) + strlen( line ); 604 598 irc->sendbuffer = g_renew ( char, irc->sendbuffer, size + 1 ); 605 599 strcpy( ( irc->sendbuffer + strlen( irc->sendbuffer ) ), line ); 606 600 } 607 else 608 irc->sendbuffer = g_strdup(line); 601 else 602 { 603 irc->sendbuffer = g_strdup(line); 604 } 609 605 610 606 if( irc->w_watch_source_id == 0 ) 611 { 612 irc->w_watch_source_id = g_io_add_watch( irc->io_channel, G_IO_OUT, bitlbee_io_current_client_write, irc ); 613 } 607 irc->w_watch_source_id = gaim_input_add( irc->fd, GAIM_INPUT_WRITE, bitlbee_io_current_client_write, irc ); 614 608 615 609 return; … … 636 630 if( now ) 637 631 { 638 bitlbee_io_current_client_write( irc ->io_channel, G_IO_OUT, irc);632 bitlbee_io_current_client_write( irc, irc->fd, GAIM_INPUT_WRITE ); 639 633 } 640 634 temp = temp->next; -
irc.h
r64d1f45 ra0d04d6 93 93 struct set *set; 94 94 95 GIOChannel *io_channel;96 95 gint r_watch_source_id; 97 96 gint w_watch_source_id;
Note: See TracChangeset
for help on using the changeset viewer.