[ecf8fa8] | 1 | /* |
---|
| 2 | * nogaim |
---|
| 3 | * |
---|
| 4 | * Copyright (C) 2006 Wilmer van der Gaast and others |
---|
| 5 | * |
---|
| 6 | * This program is free software; you can redistribute it and/or modify |
---|
| 7 | * it under the terms of the GNU General Public License as published by |
---|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
---|
| 9 | * (at your option) any later version. |
---|
| 10 | * |
---|
| 11 | * This program is distributed in the hope that it will be useful, |
---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 14 | * GNU General Public License for more details. |
---|
| 15 | * |
---|
| 16 | * You should have received a copy of the GNU General Public License |
---|
| 17 | * along with this program; if not, write to the Free Software |
---|
[6f10697] | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
---|
[ecf8fa8] | 19 | * |
---|
| 20 | */ |
---|
| 21 | |
---|
[0aaca60] | 22 | /* This stuff used to be in proxy.c too, but I split it off so BitlBee can |
---|
| 23 | use other libraries (like libevent) to handle events. proxy.c is one very |
---|
| 24 | nice piece of work from Gaim. It connects to a TCP server in the back- |
---|
| 25 | ground and calls a callback function once the connection is ready to use. |
---|
| 26 | This function (proxy_connect()) can be found in proxy.c. (It also |
---|
| 27 | transparently handles HTTP/SOCKS proxies, when necessary.) |
---|
[5ebff60] | 28 | |
---|
[0aaca60] | 29 | This file offers some extra event handling toys, which will be handled |
---|
| 30 | by GLib or libevent. The advantage of using libevent is that it can use |
---|
| 31 | more advanced I/O polling functions like epoll() in recent Linux |
---|
| 32 | kernels. This should improve BitlBee's scalability. */ |
---|
[ecf8fa8] | 33 | |
---|
| 34 | |
---|
| 35 | #ifndef _EVENTS_H_ |
---|
| 36 | #define _EVENTS_H_ |
---|
| 37 | |
---|
| 38 | #include <sys/types.h> |
---|
| 39 | #include <sys/socket.h> |
---|
| 40 | #include <netdb.h> |
---|
| 41 | #include <netinet/in.h> |
---|
| 42 | #include <glib.h> |
---|
| 43 | #include <gmodule.h> |
---|
| 44 | |
---|
[9ff5737] | 45 | /* The conditions you can pass to b_input_add()/that will be passed to |
---|
[0aaca60] | 46 | the given callback function. */ |
---|
[ecf8fa8] | 47 | typedef enum { |
---|
[e046390] | 48 | B_EV_IO_READ = 1 << 0, |
---|
[5ebff60] | 49 | B_EV_IO_WRITE = 1 << 1, |
---|
| 50 | B_EV_FLAG_FORCE_ONCE = 1 << 16, |
---|
| 51 | B_EV_FLAG_FORCE_REPEAT = 1 << 17, |
---|
[ba9edaa] | 52 | } b_input_condition; |
---|
| 53 | typedef gboolean (*b_event_handler)(gpointer data, gint fd, b_input_condition cond); |
---|
[ecf8fa8] | 54 | |
---|
[0aaca60] | 55 | /* For internal use. */ |
---|
[ecf8fa8] | 56 | #define GAIM_READ_COND (G_IO_IN | G_IO_HUP | G_IO_ERR) |
---|
| 57 | #define GAIM_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL) |
---|
| 58 | #define GAIM_ERR_COND (G_IO_HUP | G_IO_ERR | G_IO_NVAL) |
---|
| 59 | |
---|
[1e8f42b] | 60 | /* #define event_debug( ... ) printf( __VA_ARGS__ ) */ |
---|
| 61 | #define event_debug(...) |
---|
[fc2ee0f] | 62 | |
---|
[0aaca60] | 63 | /* Call this once when the program starts. It'll initialize the event handler |
---|
| 64 | library (if necessary) and then return immediately. */ |
---|
[ba9edaa] | 65 | G_MODULE_EXPORT void b_main_init(); |
---|
[0aaca60] | 66 | |
---|
| 67 | /* This one enters the event loop. It shouldn't return until one of the event |
---|
| 68 | handlers calls b_main_quit(). */ |
---|
[ba9edaa] | 69 | G_MODULE_EXPORT void b_main_run(); |
---|
| 70 | G_MODULE_EXPORT void b_main_quit(); |
---|
[ecf8fa8] | 71 | |
---|
[0aaca60] | 72 | |
---|
| 73 | /* Add event handlers (for I/O or a timeout). The event handler will be called |
---|
| 74 | every time the event "happens", until your event handler returns FALSE (or |
---|
| 75 | until you remove it using b_event_remove(). As usual, the data argument |
---|
| 76 | can be used to pass your own data to the event handler. */ |
---|
[ba9edaa] | 77 | G_MODULE_EXPORT gint b_input_add(int fd, b_input_condition cond, b_event_handler func, gpointer data); |
---|
| 78 | G_MODULE_EXPORT gint b_timeout_add(gint timeout, b_event_handler func, gpointer data); |
---|
| 79 | G_MODULE_EXPORT void b_event_remove(gint id); |
---|
[ecf8fa8] | 80 | |
---|
[25b5a4a] | 81 | /* With libevent, this one also cleans up event handlers if that wasn't already |
---|
| 82 | done (the caller is expected to do so but may miss it sometimes). */ |
---|
[3f199fc] | 83 | G_MODULE_EXPORT void closesocket(int fd); |
---|
| 84 | |
---|
[ecf8fa8] | 85 | #endif /* _EVENTS_H_ */ |
---|