# HG changeset patch # User Christian Hammond # Date 1077007424 0 # Node ID 084ed9f7ac19700baf9c52f975eaecb8c2f85c94 # Parent 319448d52b33faf1b305c7c5062d5ed8ea2714f1 [gaim-migrate @ 9004] Soem tweaks from Scott Lamb for the event loop code. committer: Tailor Script diff -r 319448d52b33 -r 084ed9f7ac19 src/eventloop.c --- a/src/eventloop.c Tue Feb 17 06:16:49 2004 +0000 +++ b/src/eventloop.c Tue Feb 17 08:43:44 2004 +0000 @@ -34,7 +34,7 @@ return ops->timeout_add(interval, function, data); } -gint +guint gaim_input_add(int source, GaimInputCondition condition, GaimInputFunction func, gpointer user_data) { GaimEventLoopUiOps *ops = gaim_eventloop_get_ui_ops(); @@ -43,7 +43,7 @@ } void -gaim_input_remove(gint tag) +gaim_input_remove(guint tag) { GaimEventLoopUiOps *ops = gaim_eventloop_get_ui_ops(); diff -r 319448d52b33 -r 084ed9f7ac19 src/eventloop.h --- a/src/eventloop.h Tue Feb 17 06:16:49 2004 +0000 +++ b/src/eventloop.h Tue Feb 17 08:43:44 2004 +0000 @@ -57,14 +57,14 @@ * Adds an input handler. * @see gaim_input_add, g_io_add_watch_full */ - gint (*input_add)(int source, GaimInputCondition cond, - GaimInputFunction func, gpointer user_data); + guint (*input_add)(int fd, GaimInputCondition cond, + GaimInputFunction func, gpointer user_data); /** * Removes an input handler. * @see gaim_input_remove, g_source_remove */ - void (*input_remove)(gint handle); + void (*input_remove)(guint handle); }; /**************************************************************************/ @@ -85,7 +85,7 @@ /** * Adds an input handler. * - * @param source The input source. + * @param fd The input file descriptor. * @param cond The condition type. * @param func The callback function for data. * @param user_data User-specified data. @@ -93,15 +93,16 @@ * @return The resulting handle. * @see g_io_add_watch_full */ -gint gaim_input_add(int source, GaimInputCondition cond, - GaimInputFunction func, gpointer user_data); +guint gaim_input_add(int fd, GaimInputCondition cond, + GaimInputFunction func, gpointer user_data); /** * Removes an input handler. * - * @param handle The handle of the input handler. + * @param handle The handle of the input handler. Note that this is the return + * value from gaim_input_add, not the file descriptor. */ -void gaim_input_remove(gint handle); +void gaim_input_remove(guint handle); /*@}*/ diff -r 319448d52b33 -r 084ed9f7ac19 src/gtkeventloop.c --- a/src/gtkeventloop.c Tue Feb 17 06:16:49 2004 +0000 +++ b/src/gtkeventloop.c Tue Feb 17 08:43:44 2004 +0000 @@ -63,7 +63,7 @@ return TRUE; } -static gint gaim_gtk_input_add(gint source, GaimInputCondition condition, GaimInputFunction function, +static guint gaim_gtk_input_add(gint fd, GaimInputCondition condition, GaimInputFunction function, gpointer data) { GaimGtkIOClosure *closure = g_new0(GaimGtkIOClosure, 1); @@ -78,21 +78,21 @@ if (condition & GAIM_INPUT_WRITE) cond |= GAIM_GTK_WRITE_COND; - channel = g_io_channel_unix_new(source); + channel = g_io_channel_unix_new(fd); closure->result = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond, gaim_gtk_io_invoke, closure, gaim_gtk_io_destroy); #if 0 gaim_debug(GAIM_DEBUG_MISC, "gtk_eventloop", "CLOSURE: adding input watcher %d for fd %d\n", - closure->result, source); + closure->result, fd); #endif g_io_channel_unref(channel); return closure->result; } -static void gaim_gtk_input_remove(gint tag) +static void gaim_gtk_input_remove(guint tag) { /* gaim_debug(GAIM_DEBUG_MISC, "proxy", "CLOSURE: removing input watcher %d\n", tag); */ diff -r 319448d52b33 -r 084ed9f7ac19 src/session.c --- a/src/session.c Tue Feb 17 06:16:49 2004 +0000 +++ b/src/session.c Tue Feb 17 08:43:44 2004 +0000 @@ -46,31 +46,38 @@ /* ICE belt'n'braces stuff */ +struct ice_connection_info { + IceConn connection; + guint input_id; +}; + static void ice_process_messages(gpointer data, gint fd, GaimInputCondition condition) { - IceConn connection = (IceConn)data; + struct ice_connection_info *conninfo = (struct ice_connection_info*) data; IceProcessMessagesStatus status; /* please don't block... please! */ - status = IceProcessMessages(connection, NULL, NULL); + status = IceProcessMessages(conninfo->connection, NULL, NULL); if (status == IceProcessMessagesIOError) { gaim_debug(GAIM_DEBUG_INFO, "Session Management", "ICE IO error, closing connection... "); /* IO error, please disconnect */ - IceSetShutdownNegotiation(connection, False); - IceCloseConnection(connection); + IceSetShutdownNegotiation(conninfo->connection, False); + IceCloseConnection(conninfo->connection); gaim_debug(GAIM_DEBUG_INFO, NULL, "done.\n"); /* cancel the handler */ - gaim_input_remove(IceConnectionNumber(connection)); + gaim_input_remove(conninfo->input_id); } } static void ice_connection_watch(IceConn connection, IcePointer client_data, Bool opening, IcePointer *watch_data) { + struct ice_connection_info *conninfo = NULL; + if (opening) { gaim_debug(GAIM_DEBUG_INFO, "Session Management", "Handling new ICE connection... "); @@ -78,15 +85,21 @@ /* ensure ICE connection is not passed to child processes */ fcntl(IceConnectionNumber(connection), F_SETFD, FD_CLOEXEC); + conninfo = g_new(struct ice_connection_info, 1); + conninfo->connection = connection; + /* watch the connection */ - gaim_input_add(IceConnectionNumber(connection), GAIM_INPUT_READ, - ice_process_messages, connection); + conninfo->input_id = gaim_input_add(IceConnectionNumber(connection), GAIM_INPUT_READ, + ice_process_messages, conninfo); + *watch_data = conninfo; } else { gaim_debug(GAIM_DEBUG_INFO, "Session Management", "Handling closed ICE connection... "); - /* stop watching it */ - gaim_input_remove(IceConnectionNumber(connection)); + /* get the input ID back and stop watching it */ + conninfo = (struct ice_connection_info*) *watch_data; + gaim_input_remove(conninfo->input_id); + g_free(conninfo); } gaim_debug(GAIM_DEBUG_INFO, NULL, "done.\n");