aboutsummaryrefslogtreecommitdiffstats
path: root/protocols/events_libevent.c
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2006-05-14 01:28:31 +0200
committerWilmer van der Gaast <wilmer@gaast.net>2006-05-14 01:28:31 +0200
commit3f199fcf6242fc0cc0e4e767ce2a505792d80fef (patch)
tree3d62ed0e3d2ebb7d7604a4dba866801aadb4cbe8 /protocols/events_libevent.c
parent0356ae3aa10bb6556d0ea881988831cad5e71f38 (diff)
Added a closesocket() that properly removes event handlers before closing a socket.
Diffstat (limited to 'protocols/events_libevent.c')
-rw-r--r--protocols/events_libevent.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/protocols/events_libevent.c b/protocols/events_libevent.c
index 6e1ed98e..ad1864d2 100644
--- a/protocols/events_libevent.c
+++ b/protocols/events_libevent.c
@@ -29,6 +29,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include <sys/types.h>
#include "proxy.h"
@@ -216,3 +217,19 @@ gboolean b_event_remove_by_data( gpointer data )
event_debug( "FALSE!\n" );
return FALSE;
}
+
+void closesocket( int fd )
+{
+ struct b_event_data *b_ev;
+
+ /* Since epoll() (the main reason we use libevent) automatically removes sockets from
+ the epoll() list when a socket gets closed and some modules have a habit of
+ closing sockets before removing event handlers, our and libevent's administration
+ get a little bit messed up. So this little function will remove the handlers
+ properly before closing a socket. */
+
+ if( ( b_ev = g_hash_table_lookup( read_hash, &fd ) ) || ( b_ev = g_hash_table_lookup( write_hash, &fd ) ) )
+ b_event_remove( b_ev->id );
+
+ close( fd );
+}