aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorulim <a.sporto+bee@gmail.com>2007-12-05 02:30:50 +0100
committerulim <a.sporto+bee@gmail.com>2007-12-05 02:30:50 +0100
commit8076ec04b1b5699f8266fa0e2e17456974ced554 (patch)
treec53680ef30c2368e99f396e5e147b9c08437e46e /lib
parentdce390357114e30a424106c99e49cef1e682e1af (diff)
parent793cc254ad2479d95d00266d6cb7ab2bcd158834 (diff)
merges from upstream/release
ulim 2007-12-04 Follow rename of jabber_chat_by_jid from upstrem ulim 2007-12-04 Merged in current devel Wilmer van der Gaast 2007-12-02 Imported setuid() patch from Simo Leone <simo@archlinux...> with some Wilmer van der Gaast 2007-12-02 Forgot to return something in jabber_chat_join_failed(). Wilmer van der Gaast 2007-12-02 Merging a change I should've pulled before committing three other changes. Wilmer van der Gaast 2007-12-02 Added charset checks on incoming msgs (from the IRC side) to prevent possible Wilmer van der Gaast 2007-12-02 Handling of presence-error packets (only useful for groupchats now), moved Wilmer van der Gaast 2007-12-02 Defining DEBUG via CFLAGS so that it'll always be there, even when a file ulim 2007-12-04 Jabber file transfer now also with sending! You can't use a proxy yet when Wilmer van der Gaast 2007-12-02 Removed retarded printf() (ARGH) and moved the event handling handling of Wilmer van der Gaast 2007-11-29 printf() in daemons considered harmful. Wilmer van der Gaast 2007-11-28 Fixed the epoll+ForkDaemon combination. The libevent event handling
Diffstat (limited to 'lib')
-rw-r--r--lib/events.h4
-rw-r--r--lib/events_libevent.c51
2 files changed, 43 insertions, 12 deletions
diff --git a/lib/events.h b/lib/events.h
index 0588547f..4baea7b6 100644
--- a/lib/events.h
+++ b/lib/events.h
@@ -44,7 +44,7 @@
#include <glib.h>
#include <gmodule.h>
-/* The conditions you can pass to gaim_input_add()/that will be passed to
+/* The conditions you can pass to b_input_add()/that will be passed to
the given callback function. */
typedef enum {
GAIM_INPUT_READ = 1 << 1,
@@ -57,7 +57,7 @@ typedef gboolean (*b_event_handler)(gpointer data, gint fd, b_input_condition co
#define GAIM_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL)
#define GAIM_ERR_COND (G_IO_HUP | G_IO_ERR | G_IO_NVAL)
-// #define event_debug( x... ) printf( x )
+/* #define event_debug( x... ) printf( x ) */
#define event_debug( x... )
/* Call this once when the program starts. It'll initialize the event handler
diff --git a/lib/events_libevent.c b/lib/events_libevent.c
index f2b4d15c..d3403152 100644
--- a/lib/events_libevent.c
+++ b/lib/events_libevent.c
@@ -31,12 +31,12 @@
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
-#include "proxy.h"
-
#include <sys/time.h>
#include <event.h>
+#include "proxy.h"
-static guint id_next;
+static void b_main_restart();
+static guint id_next = 1;
static GHashTable *id_hash;
static int quitting = 0;
@@ -47,6 +47,9 @@ static int quitting = 0;
static GHashTable *read_hash;
static GHashTable *write_hash;
+struct event_base *leh;
+struct event_base *old_leh;
+
struct b_event_data
{
guint id;
@@ -58,9 +61,16 @@ struct b_event_data
void b_main_init()
{
- event_init();
+ if( leh != NULL )
+ {
+ /* Clean up the hash tables? */
+
+ b_main_restart();
+ old_leh = leh;
+ }
+
+ leh = event_init();
- id_next = 1;
id_hash = g_hash_table_new( g_int_hash, g_int_equal );
read_hash = g_hash_table_new( g_int_hash, g_int_equal );
write_hash = g_hash_table_new( g_int_hash, g_int_equal );
@@ -68,19 +78,40 @@ void b_main_init()
void b_main_run()
{
- event_dispatch();
+ /* This while loop is necessary to exit the event loop and start a
+ different one (necessary for ForkDaemon mode). */
+ while( event_base_dispatch( leh ) == 0 && !quitting )
+ {
+ if( old_leh != NULL )
+ {
+ /* For some reason this just isn't allowed...
+ Possibly a bug in older versions, will see later.
+ event_base_free( old_leh ); */
+ old_leh = NULL;
+ }
+
+ event_debug( "New event loop.\n" );
+ }
}
-void b_main_quit()
+static void b_main_restart()
{
struct timeval tv;
- /* libevent sometimes generates events before really quitting,
+ memset( &tv, 0, sizeof( struct timeval ) );
+ event_base_loopexit( leh, &tv );
+
+ event_debug( "b_main_restart()\n" );
+}
+
+void b_main_quit()
+{
+ /* Tell b_main_run() that it shouldn't restart the loop. Also,
+ libevent sometimes generates events before really quitting,
we want to stop them. */
quitting = 1;
- memset( &tv, 0, sizeof( struct timeval ) );
- event_loopexit( &tv );
+ b_main_restart();
}
static void b_event_passthrough( int fd, short event, void *data )