47
47
the behavior will be undefined. */
48
48
struct io *io_add(int fd, enum io_condition condition,
49
49
unsigned int source_linenum,
50
io_callback_t *callback, void *context);
50
io_callback_t *callback, void *context) ATTR_NULL(5);
51
51
#define io_add(fd, condition, callback, context) \
52
CONTEXT_CALLBACK(io_add, io_callback_t, \
53
callback, context, fd, condition, __LINE__)
54
enum io_notify_result io_add_notify(const char *path, io_callback_t *callback,
55
void *context, struct io **io_r);
56
#ifdef CONTEXT_TYPE_SAFETY
57
# define io_add_notify(path, callback, context, io_r) \
58
({(void)(1 ? 0 : callback(context)); \
59
io_add_notify(path, (io_callback_t *)callback, context, io_r); })
61
# define io_add_notify(path, callback, context, io_r) \
62
io_add_notify(path, (io_callback_t *)callback, context, io_r)
52
io_add(fd, condition, __LINE__ + \
53
CALLBACK_TYPECHECK(callback, void (*)(typeof(context))), \
54
(io_callback_t *)callback, context)
56
io_add_notify(const char *path, io_callback_t *callback,
57
void *context, struct io **io_r) ATTR_NULL(3);
58
#define io_add_notify(path, callback, context, io_r) \
59
io_add_notify(path + \
60
CALLBACK_TYPECHECK(callback, void (*)(typeof(context))), \
61
(io_callback_t *)callback, context, io_r)
65
63
/* Remove I/O handler, and set io pointer to NULL. */
66
64
void io_remove(struct io **io);
69
67
void io_remove_closed(struct io **io);
71
69
/* Timeout handlers */
72
struct timeout *timeout_add(unsigned int msecs, unsigned int source_linenum,
73
timeout_callback_t *callback, void *context);
71
timeout_add(unsigned int msecs, unsigned int source_linenum,
72
timeout_callback_t *callback, void *context) ATTR_NULL(4);
74
73
#define timeout_add(msecs, callback, context) \
75
CONTEXT_CALLBACK(timeout_add, timeout_callback_t, \
76
callback, context, msecs, __LINE__)
74
timeout_add(msecs, __LINE__ + \
75
CALLBACK_TYPECHECK(callback, void (*)(typeof(context))) + \
76
COMPILE_ERROR_IF_TRUE(__builtin_constant_p(msecs) && \
77
(msecs > 0 && msecs < 1000)), \
78
(io_callback_t *)callback, context)
80
timeout_add_short(unsigned int msecs, unsigned int source_linenum,
81
timeout_callback_t *callback, void *context) ATTR_NULL(4);
82
#define timeout_add_short(msecs, callback, context) \
83
timeout_add_short(msecs, __LINE__ + \
84
CALLBACK_TYPECHECK(callback, void (*)(typeof(context))), \
85
(io_callback_t *)callback, context)
77
86
/* Remove timeout handler, and set timeout pointer to NULL. */
78
87
void timeout_remove(struct timeout **timeout);
79
88
/* Reset timeout so it's next run after now+msecs. */
128
137
struct io *io_loop_move_io(struct io **io);
129
138
/* Like io_loop_move_io(), but for timeouts. */
130
139
struct timeout *io_loop_move_timeout(struct timeout **timeout);
140
/* Returns TRUE if any IOs have been added to the ioloop. */
141
bool io_loop_have_ios(struct ioloop *ioloop);
142
/* Returns TRUE if there is a pending timeout that is going to be run
144
bool io_loop_have_immediate_timeouts(struct ioloop *ioloop);