source: lib/events.h @ c467adc

Last change on this file since c467adc was 5ebff60, checked in by dequis <dx@…>, at 2015-02-20T22:50:54Z

Reindent everything to K&R style with tabs

Used uncrustify, with the configuration file in ./doc/uncrustify.cfg

Commit author set to "Indent <please@…>" so that it's easier to
skip while doing git blame.

  • Property mode set to 100644
File size: 3.4 KB
Line 
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
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19 *
20 */
21
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.)
28
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. */
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
45/* The conditions you can pass to b_input_add()/that will be passed to
46   the given callback function. */
47typedef enum {
48        B_EV_IO_READ = 1 << 0,
49                B_EV_IO_WRITE = 1 << 1,
50                B_EV_FLAG_FORCE_ONCE = 1 << 16,
51                B_EV_FLAG_FORCE_REPEAT = 1 << 17,
52} b_input_condition;
53typedef gboolean (*b_event_handler)(gpointer data, gint fd, b_input_condition cond);
54
55/* For internal use. */
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
60/* #define event_debug( x... ) printf( x ) */
61#define event_debug(x ...)
62
63/* Call this once when the program starts. It'll initialize the event handler
64   library (if necessary) and then return immediately. */
65G_MODULE_EXPORT void b_main_init();
66
67/* This one enters the event loop. It shouldn't return until one of the event
68   handlers calls b_main_quit(). */
69G_MODULE_EXPORT void b_main_run();
70G_MODULE_EXPORT void b_main_quit();
71
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. */
77G_MODULE_EXPORT gint b_input_add(int fd, b_input_condition cond, b_event_handler func, gpointer data);
78G_MODULE_EXPORT gint b_timeout_add(gint timeout, b_event_handler func, gpointer data);
79G_MODULE_EXPORT void b_event_remove(gint id);
80
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). */
83G_MODULE_EXPORT void closesocket(int fd);
84
85#endif /* _EVENTS_H_ */
Note: See TracBrowser for help on using the repository browser.