0
|
1 #ifndef __IOLOOP_H
|
|
2 #define __IOLOOP_H
|
|
3
|
|
4 #include <time.h>
|
|
5
|
|
6 #define IO_READ (1 << 0)
|
|
7 #define IO_WRITE (1 << 1)
|
|
8
|
|
9 #define IO_PRIORITY_LOW 100
|
|
10 #define IO_PRIORITY_DEFAULT 0
|
|
11 #define IO_PRIORITY_HIGH -100
|
|
12
|
|
13 typedef void (*IOFunc) (void *user_data, int fd, IO io);
|
|
14 typedef void (*TimeoutFunc) (void *user_data, Timeout timeout);
|
|
15
|
|
16 /* Time when the I/O loop started calling handlers.
|
|
17 Can be used instead of time(NULL). */
|
|
18 extern time_t ioloop_time;
|
|
19 extern struct timeval ioloop_timeval;
|
|
20
|
|
21 /* I/O listeners - you can create different handlers for IO_READ and IO_WRITE,
|
|
22 but make sure you don't create multiple handlers of same type, it's not
|
|
23 checked and removing one will stop the other from working as well. */
|
|
24 IO io_add(int fd, int condition, IOFunc func, void *user_data);
|
|
25 IO io_add_priority(int fd, int priority, int condition,
|
|
26 IOFunc func, void *user_data);
|
|
27 void io_remove(IO io);
|
|
28
|
|
29 /* Timeout handlers */
|
|
30 Timeout timeout_add(int msecs, TimeoutFunc func, void *user_data);
|
|
31 void timeout_remove(Timeout timeout);
|
|
32
|
|
33 void io_loop_run(IOLoop ioloop);
|
|
34 void io_loop_stop(IOLoop ioloop); /* safe to run in signal handler */
|
|
35
|
|
36 /* call these if you wish to run the iteration only once */
|
|
37 void io_loop_set_running(IOLoop ioloop);
|
|
38 void io_loop_handler_run(IOLoop ioloop);
|
|
39
|
|
40 IOLoop io_loop_create(void);
|
|
41 void io_loop_destroy(IOLoop ioloop);
|
|
42
|
|
43 #endif
|