aboutsummaryrefslogtreecommitdiffstats
path: root/lib/events.h
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2006-07-19 18:52:38 +0200
committerWilmer van der Gaast <wilmer@gaast.net>2006-07-19 18:52:38 +0200
commit0aaca60fdc1a6793b438ecc926bd937073d22685 (patch)
tree88af0ce1d2de568fab195386b5d33cddd3f9b6e1 /lib/events.h
parent04026d44c29f2b7d64f81bb2d2d061a7d111662f (diff)
Added some (more) comments to .h files in lib/ and some minor fixes/cleanups.
Diffstat (limited to 'lib/events.h')
-rw-r--r--lib/events.h31
1 files changed, 26 insertions, 5 deletions
diff --git a/lib/events.h b/lib/events.h
index 781fca6a..0588547f 100644
--- a/lib/events.h
+++ b/lib/events.h
@@ -19,11 +19,17 @@
*
*/
-/*
- * Split off the event handling things from proxy.[ch] (and adding timer
- * stuff. This to allow BitlBee to use other libs than GLib for event
- * handling.
- */
+/* This stuff used to be in proxy.c too, but I split it off so BitlBee can
+ use other libraries (like libevent) to handle events. proxy.c is one very
+ nice piece of work from Gaim. It connects to a TCP server in the back-
+ ground and calls a callback function once the connection is ready to use.
+ This function (proxy_connect()) can be found in proxy.c. (It also
+ transparently handles HTTP/SOCKS proxies, when necessary.)
+
+ This file offers some extra event handling toys, which will be handled
+ by GLib or libevent. The advantage of using libevent is that it can use
+ more advanced I/O polling functions like epoll() in recent Linux
+ kernels. This should improve BitlBee's scalability. */
#ifndef _EVENTS_H_
@@ -38,12 +44,15 @@
#include <glib.h>
#include <gmodule.h>
+/* The conditions you can pass to gaim_input_add()/that will be passed to
+ the given callback function. */
typedef enum {
GAIM_INPUT_READ = 1 << 1,
GAIM_INPUT_WRITE = 1 << 2
} b_input_condition;
typedef gboolean (*b_event_handler)(gpointer data, gint fd, b_input_condition cond);
+/* For internal use. */
#define GAIM_READ_COND (G_IO_IN | G_IO_HUP | G_IO_ERR)
#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)
@@ -51,14 +60,26 @@ typedef gboolean (*b_event_handler)(gpointer data, gint fd, b_input_condition co
// #define event_debug( x... ) printf( x )
#define event_debug( x... )
+/* Call this once when the program starts. It'll initialize the event handler
+ library (if necessary) and then return immediately. */
G_MODULE_EXPORT void b_main_init();
+
+/* This one enters the event loop. It shouldn't return until one of the event
+ handlers calls b_main_quit(). */
G_MODULE_EXPORT void b_main_run();
G_MODULE_EXPORT void b_main_quit();
+
+/* Add event handlers (for I/O or a timeout). The event handler will be called
+ every time the event "happens", until your event handler returns FALSE (or
+ until you remove it using b_event_remove(). As usual, the data argument
+ can be used to pass your own data to the event handler. */
G_MODULE_EXPORT gint b_input_add(int fd, b_input_condition cond, b_event_handler func, gpointer data);
G_MODULE_EXPORT gint b_timeout_add(gint timeout, b_event_handler func, gpointer data);
G_MODULE_EXPORT void b_event_remove(gint id);
+/* For now, closesocket() is only a function when using libevent. With GLib
+ it's a preprocessor macro. */
#ifdef EVENTS_LIBEVENT
G_MODULE_EXPORT void closesocket(int fd);
#endif