annotate src/lib/ioloop.h @ 22664:fea53c2725c0

director: Fix director_max_parallel_moves/kicks type Should be uint, not time.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Thu, 09 Nov 2017 12:24:16 +0200
parents 05b48dab5d29
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6410
e4eb71ae8e96 Changed .h ifdef/defines to use <NAME>_H format.
Timo Sirainen <tss@iki.fi>
parents: 5937
diff changeset
1 #ifndef IOLOOP_H
e4eb71ae8e96 Changed .h ifdef/defines to use <NAME>_H format.
Timo Sirainen <tss@iki.fi>
parents: 5937
diff changeset
2 #define IOLOOP_H
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3
1431
8a2e1c539faf struct timeval requires sys/time.h
Timo Sirainen <tss@iki.fi>
parents: 1036
diff changeset
4 #include <sys/time.h>
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include <time.h>
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 492
diff changeset
7 struct io;
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 492
diff changeset
8 struct timeout;
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 492
diff changeset
9 struct ioloop;
17188
fd186eff7325 Added io_add_istream() and related functionality for combining the ioloop/istream.
Timo Sirainen <tss@iki.fi>
parents: 17187
diff changeset
10 struct istream;
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 492
diff changeset
11
1729
5bf22d6bb65e Added IO_DIR_NOTIFY and IO_FILE_NOTIFY conditions to io_add(). IO_DIR_NOTIFY
Timo Sirainen <tss@iki.fi>
parents: 1499
diff changeset
12 enum io_condition {
5bf22d6bb65e Added IO_DIR_NOTIFY and IO_FILE_NOTIFY conditions to io_add(). IO_DIR_NOTIFY
Timo Sirainen <tss@iki.fi>
parents: 1499
diff changeset
13 IO_READ = 0x01,
5bf22d6bb65e Added IO_DIR_NOTIFY and IO_FILE_NOTIFY conditions to io_add(). IO_DIR_NOTIFY
Timo Sirainen <tss@iki.fi>
parents: 1499
diff changeset
14 IO_WRITE = 0x02,
4579
40b353def38c OK, so the original kqueue code wasn't actually broken, but it could have
Timo Sirainen <tss@iki.fi>
parents: 4150
diff changeset
15 /* IO_ERROR can be used to check when writable pipe's reader side
40b353def38c OK, so the original kqueue code wasn't actually broken, but it could have
Timo Sirainen <tss@iki.fi>
parents: 4150
diff changeset
16 closes the pipe. For other uses IO_READ should work just as well. */
3613
c4c1b538d8d0 Added IO_ERROR condition that we can watch now.
Timo Sirainen <tss@iki.fi>
parents: 3534
diff changeset
17 IO_ERROR = 0x04,
3534
a9be1824403b New inotify code and notify API change. Patch by Johannes Berg
Timo Sirainen <tss@iki.fi>
parents: 1729
diff changeset
18
a9be1824403b New inotify code and notify API change. Patch by Johannes Berg
Timo Sirainen <tss@iki.fi>
parents: 1729
diff changeset
19 /* internal */
4150
49e024519e22 IO_ERROR and IO_NOTIFY had conflicting values.
Timo Sirainen <tss@iki.fi>
parents: 4039
diff changeset
20 IO_NOTIFY = 0x08
1729
5bf22d6bb65e Added IO_DIR_NOTIFY and IO_FILE_NOTIFY conditions to io_add(). IO_DIR_NOTIFY
Timo Sirainen <tss@iki.fi>
parents: 1499
diff changeset
21 };
5bf22d6bb65e Added IO_DIR_NOTIFY and IO_FILE_NOTIFY conditions to io_add(). IO_DIR_NOTIFY
Timo Sirainen <tss@iki.fi>
parents: 1499
diff changeset
22
5937
772f4e8bd2a9 Changed io_add_notify() API so that it can return "file doesn't exist"
Timo Sirainen <tss@iki.fi>
parents: 5248
diff changeset
23 enum io_notify_result {
7457
940641318f12 Renamed IO_NOTIFY_DISABLED to IO_NOTIFY_NOSUPPORT. IO_NOTIFY_NOSUPPORT is
Timo Sirainen <tss@iki.fi>
parents: 7098
diff changeset
24 /* Notify added successfully */
5937
772f4e8bd2a9 Changed io_add_notify() API so that it can return "file doesn't exist"
Timo Sirainen <tss@iki.fi>
parents: 5248
diff changeset
25 IO_NOTIFY_ADDED,
7457
940641318f12 Renamed IO_NOTIFY_DISABLED to IO_NOTIFY_NOSUPPORT. IO_NOTIFY_NOSUPPORT is
Timo Sirainen <tss@iki.fi>
parents: 7098
diff changeset
26 /* Specified file doesn't exist, can't wait on it */
5937
772f4e8bd2a9 Changed io_add_notify() API so that it can return "file doesn't exist"
Timo Sirainen <tss@iki.fi>
parents: 5248
diff changeset
27 IO_NOTIFY_NOTFOUND,
7457
940641318f12 Renamed IO_NOTIFY_DISABLED to IO_NOTIFY_NOSUPPORT. IO_NOTIFY_NOSUPPORT is
Timo Sirainen <tss@iki.fi>
parents: 7098
diff changeset
28 /* Can't add notify for specified file. Main reasons for this:
940641318f12 Renamed IO_NOTIFY_DISABLED to IO_NOTIFY_NOSUPPORT. IO_NOTIFY_NOSUPPORT is
Timo Sirainen <tss@iki.fi>
parents: 7098
diff changeset
29 a) No notify support at all, b) Only directory notifies supported */
940641318f12 Renamed IO_NOTIFY_DISABLED to IO_NOTIFY_NOSUPPORT. IO_NOTIFY_NOSUPPORT is
Timo Sirainen <tss@iki.fi>
parents: 7098
diff changeset
30 IO_NOTIFY_NOSUPPORT
5937
772f4e8bd2a9 Changed io_add_notify() API so that it can return "file doesn't exist"
Timo Sirainen <tss@iki.fi>
parents: 5248
diff changeset
31 };
772f4e8bd2a9 Changed io_add_notify() API so that it can return "file doesn't exist"
Timo Sirainen <tss@iki.fi>
parents: 5248
diff changeset
32
1036
f782b3319553 Removed useless parameters from io_callback_t and timeout_callback_t.
Timo Sirainen <tss@iki.fi>
parents: 1033
diff changeset
33 typedef void io_callback_t(void *context);
f782b3319553 Removed useless parameters from io_callback_t and timeout_callback_t.
Timo Sirainen <tss@iki.fi>
parents: 1033
diff changeset
34 typedef void timeout_callback_t(void *context);
9494
a442d3c40693 ioloop: Added callback for handling time jumping forwards/backwards.
Timo Sirainen <tss@iki.fi>
parents: 9400
diff changeset
35 typedef void io_loop_time_moved_callback_t(time_t old_time, time_t new_time);
16969
54eb87b7761c Added io_loop_add/remove_switch_callback() to call a callback when ioloop is changed.
Timo Sirainen <tss@iki.fi>
parents: 15994
diff changeset
36 typedef void io_switch_callback_t(struct ioloop *prev_ioloop);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
37
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
38 /* Time when the I/O loop started calling handlers.
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
39 Can be used instead of time(NULL). */
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
40 extern time_t ioloop_time;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
41 extern struct timeval ioloop_timeval;
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
42
3798
be1bac1dd005 Export current_ioloop globally.
Timo Sirainen <tss@iki.fi>
parents: 3613
diff changeset
43 extern struct ioloop *current_ioloop;
20949
efe8424307ff lib: Added ioloop_global_wait_usecs
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20811
diff changeset
44 /* Number of microseconds spent on all the ioloops waiting for themselves. */
efe8424307ff lib: Added ioloop_global_wait_usecs
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20811
diff changeset
45 extern uint64_t ioloop_global_wait_usecs;
3798
be1bac1dd005 Export current_ioloop globally.
Timo Sirainen <tss@iki.fi>
parents: 3613
diff changeset
46
4579
40b353def38c OK, so the original kqueue code wasn't actually broken, but it could have
Timo Sirainen <tss@iki.fi>
parents: 4150
diff changeset
47 /* You can create different handlers for IO_READ and IO_WRITE. IO_READ and
40b353def38c OK, so the original kqueue code wasn't actually broken, but it could have
Timo Sirainen <tss@iki.fi>
parents: 4150
diff changeset
48 IO_ERROR can't use different handlers (and there's no point anyway).
1729
5bf22d6bb65e Added IO_DIR_NOTIFY and IO_FILE_NOTIFY conditions to io_add(). IO_DIR_NOTIFY
Timo Sirainen <tss@iki.fi>
parents: 1499
diff changeset
49
4579
40b353def38c OK, so the original kqueue code wasn't actually broken, but it could have
Timo Sirainen <tss@iki.fi>
parents: 4150
diff changeset
50 Don't try to add multiple handlers for the same type. It's not checked and
40b353def38c OK, so the original kqueue code wasn't actually broken, but it could have
Timo Sirainen <tss@iki.fi>
parents: 4150
diff changeset
51 the behavior will be undefined. */
1729
5bf22d6bb65e Added IO_DIR_NOTIFY and IO_FILE_NOTIFY conditions to io_add(). IO_DIR_NOTIFY
Timo Sirainen <tss@iki.fi>
parents: 1499
diff changeset
52 struct io *io_add(int fd, enum io_condition condition,
20811
1bd9c2258fd9 io: Add source filename
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 19354
diff changeset
53 const char *source_filename,
14045
0308a33d9f99 ioloop: I/O and timeout leak messages now include the io_add()/timeout_add() source line number.
Timo Sirainen <tss@iki.fi>
parents: 13509
diff changeset
54 unsigned int source_linenum,
14629
c93ca5e46a8a Marked functions parameters that are allowed to be NULL. Some APIs were also changed.
Timo Sirainen <tss@iki.fi>
parents: 14577
diff changeset
55 io_callback_t *callback, void *context) ATTR_NULL(5);
4903
204d7edc7cdc Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents: 4579
diff changeset
56 #define io_add(fd, condition, callback, context) \
20811
1bd9c2258fd9 io: Add source filename
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 19354
diff changeset
57 io_add(fd, condition, __FILE__, __LINE__ + \
14921
d3db2ba15d00 Removed CONTEXT_TYPE_SAFETY macro and reimplemented its functionality better.
Timo Sirainen <tss@iki.fi>
parents: 14629
diff changeset
58 CALLBACK_TYPECHECK(callback, void (*)(typeof(context))), \
d3db2ba15d00 Removed CONTEXT_TYPE_SAFETY macro and reimplemented its functionality better.
Timo Sirainen <tss@iki.fi>
parents: 14629
diff changeset
59 (io_callback_t *)callback, context)
14629
c93ca5e46a8a Marked functions parameters that are allowed to be NULL. Some APIs were also changed.
Timo Sirainen <tss@iki.fi>
parents: 14577
diff changeset
60 enum io_notify_result
20811
1bd9c2258fd9 io: Add source filename
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 19354
diff changeset
61 io_add_notify(const char *path, const char *source_filename,
1bd9c2258fd9 io: Add source filename
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 19354
diff changeset
62 unsigned int source_linenum,
18984
d26178d0557a lib: io_add_notify() wasn't setting struct io.source_linenum
Timo Sirainen <tss@iki.fi>
parents: 17853
diff changeset
63 io_callback_t *callback, void *context,
d26178d0557a lib: io_add_notify() wasn't setting struct io.source_linenum
Timo Sirainen <tss@iki.fi>
parents: 17853
diff changeset
64 struct io **io_r) ATTR_NULL(3);
14921
d3db2ba15d00 Removed CONTEXT_TYPE_SAFETY macro and reimplemented its functionality better.
Timo Sirainen <tss@iki.fi>
parents: 14629
diff changeset
65 #define io_add_notify(path, callback, context, io_r) \
20811
1bd9c2258fd9 io: Add source filename
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 19354
diff changeset
66 io_add_notify(path, __FILE__, __LINE__ + \
14921
d3db2ba15d00 Removed CONTEXT_TYPE_SAFETY macro and reimplemented its functionality better.
Timo Sirainen <tss@iki.fi>
parents: 14629
diff changeset
67 CALLBACK_TYPECHECK(callback, void (*)(typeof(context))), \
d3db2ba15d00 Removed CONTEXT_TYPE_SAFETY macro and reimplemented its functionality better.
Timo Sirainen <tss@iki.fi>
parents: 14629
diff changeset
68 (io_callback_t *)callback, context, io_r)
20811
1bd9c2258fd9 io: Add source filename
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 19354
diff changeset
69 struct io *io_add_istream(struct istream *input, const char *source_filename,
1bd9c2258fd9 io: Add source filename
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 19354
diff changeset
70 unsigned int source_linenum,
17188
fd186eff7325 Added io_add_istream() and related functionality for combining the ioloop/istream.
Timo Sirainen <tss@iki.fi>
parents: 17187
diff changeset
71 io_callback_t *callback, void *context) ATTR_NULL(3);
fd186eff7325 Added io_add_istream() and related functionality for combining the ioloop/istream.
Timo Sirainen <tss@iki.fi>
parents: 17187
diff changeset
72 #define io_add_istream(input, callback, context) \
20811
1bd9c2258fd9 io: Add source filename
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 19354
diff changeset
73 io_add_istream(input, __FILE__, __LINE__ + \
17188
fd186eff7325 Added io_add_istream() and related functionality for combining the ioloop/istream.
Timo Sirainen <tss@iki.fi>
parents: 17187
diff changeset
74 CALLBACK_TYPECHECK(callback, void (*)(typeof(context))), \
fd186eff7325 Added io_add_istream() and related functionality for combining the ioloop/istream.
Timo Sirainen <tss@iki.fi>
parents: 17187
diff changeset
75 (io_callback_t *)callback, context)
5937
772f4e8bd2a9 Changed io_add_notify() API so that it can return "file doesn't exist"
Timo Sirainen <tss@iki.fi>
parents: 5248
diff changeset
76
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
77 /* Remove I/O handler, and set io pointer to NULL. */
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
78 void io_remove(struct io **io);
8100
83aef3a6c0a3 Added io_remove_closed().
Timo Sirainen <tss@iki.fi>
parents: 7457
diff changeset
79 /* Like io_remove(), but assume that the file descriptor is already closed.
83aef3a6c0a3 Added io_remove_closed().
Timo Sirainen <tss@iki.fi>
parents: 7457
diff changeset
80 With some backends this simply frees the memory. */
83aef3a6c0a3 Added io_remove_closed().
Timo Sirainen <tss@iki.fi>
parents: 7457
diff changeset
81 void io_remove_closed(struct io **io);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
82
17187
d2a6f57e174f ioloop: Added io_set_pending()
Timo Sirainen <tss@iki.fi>
parents: 16969
diff changeset
83 /* Make sure the I/O callback is called by io_loop_run() even if there isn't
d2a6f57e174f ioloop: Added io_set_pending()
Timo Sirainen <tss@iki.fi>
parents: 16969
diff changeset
84 any input actually pending currently as seen by the OS. This may be useful
d2a6f57e174f ioloop: Added io_set_pending()
Timo Sirainen <tss@iki.fi>
parents: 16969
diff changeset
85 if some of the input has already read into some internal buffer and the
d2a6f57e174f ioloop: Added io_set_pending()
Timo Sirainen <tss@iki.fi>
parents: 16969
diff changeset
86 caller wants to handle it the same way as if the fd itself had input. */
d2a6f57e174f ioloop: Added io_set_pending()
Timo Sirainen <tss@iki.fi>
parents: 16969
diff changeset
87 void io_set_pending(struct io *io);
d2a6f57e174f ioloop: Added io_set_pending()
Timo Sirainen <tss@iki.fi>
parents: 16969
diff changeset
88
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
89 /* Timeout handlers */
14629
c93ca5e46a8a Marked functions parameters that are allowed to be NULL. Some APIs were also changed.
Timo Sirainen <tss@iki.fi>
parents: 14577
diff changeset
90 struct timeout *
20811
1bd9c2258fd9 io: Add source filename
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 19354
diff changeset
91 timeout_add(unsigned int msecs, const char *source_filename,
1bd9c2258fd9 io: Add source filename
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 19354
diff changeset
92 unsigned int source_linenum,
14629
c93ca5e46a8a Marked functions parameters that are allowed to be NULL. Some APIs were also changed.
Timo Sirainen <tss@iki.fi>
parents: 14577
diff changeset
93 timeout_callback_t *callback, void *context) ATTR_NULL(4);
4903
204d7edc7cdc Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents: 4579
diff changeset
94 #define timeout_add(msecs, callback, context) \
20811
1bd9c2258fd9 io: Add source filename
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 19354
diff changeset
95 timeout_add(msecs, __FILE__, __LINE__ + \
14921
d3db2ba15d00 Removed CONTEXT_TYPE_SAFETY macro and reimplemented its functionality better.
Timo Sirainen <tss@iki.fi>
parents: 14629
diff changeset
96 CALLBACK_TYPECHECK(callback, void (*)(typeof(context))) + \
d3db2ba15d00 Removed CONTEXT_TYPE_SAFETY macro and reimplemented its functionality better.
Timo Sirainen <tss@iki.fi>
parents: 14629
diff changeset
97 COMPILE_ERROR_IF_TRUE(__builtin_constant_p(msecs) && \
22464
05b48dab5d29 lib: Add missing parenthesis to timeout_add()'s msecs parameter checks
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21106
diff changeset
98 ((msecs) > 0 && (msecs) < 1000)), \
14921
d3db2ba15d00 Removed CONTEXT_TYPE_SAFETY macro and reimplemented its functionality better.
Timo Sirainen <tss@iki.fi>
parents: 14629
diff changeset
99 (io_callback_t *)callback, context)
14577
a47c95872745 Use timeout_add_short() for sub-second timeouts. Fail at compile time if timeout_add() is <1s.
Timo Sirainen <tss@iki.fi>
parents: 14045
diff changeset
100 struct timeout *
20811
1bd9c2258fd9 io: Add source filename
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 19354
diff changeset
101 timeout_add_short(unsigned int msecs, const char *source_filename,
1bd9c2258fd9 io: Add source filename
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 19354
diff changeset
102 unsigned int source_linenum,
14629
c93ca5e46a8a Marked functions parameters that are allowed to be NULL. Some APIs were also changed.
Timo Sirainen <tss@iki.fi>
parents: 14577
diff changeset
103 timeout_callback_t *callback, void *context) ATTR_NULL(4);
14577
a47c95872745 Use timeout_add_short() for sub-second timeouts. Fail at compile time if timeout_add() is <1s.
Timo Sirainen <tss@iki.fi>
parents: 14045
diff changeset
104 #define timeout_add_short(msecs, callback, context) \
20811
1bd9c2258fd9 io: Add source filename
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 19354
diff changeset
105 timeout_add_short(msecs, __FILE__, __LINE__ + \
14921
d3db2ba15d00 Removed CONTEXT_TYPE_SAFETY macro and reimplemented its functionality better.
Timo Sirainen <tss@iki.fi>
parents: 14629
diff changeset
106 CALLBACK_TYPECHECK(callback, void (*)(typeof(context))), \
d3db2ba15d00 Removed CONTEXT_TYPE_SAFETY macro and reimplemented its functionality better.
Timo Sirainen <tss@iki.fi>
parents: 14629
diff changeset
107 (io_callback_t *)callback, context)
17853
d80395660f27 lib: Added support for setting timeouts at absolute time, rather than relative to current time.
Stephan Bosch <stephan@rename-it.nl>
parents: 17839
diff changeset
108 struct timeout *timeout_add_absolute(const struct timeval *time,
20811
1bd9c2258fd9 io: Add source filename
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 19354
diff changeset
109 const char *source_filename,
17853
d80395660f27 lib: Added support for setting timeouts at absolute time, rather than relative to current time.
Stephan Bosch <stephan@rename-it.nl>
parents: 17839
diff changeset
110 unsigned int source_linenum,
d80395660f27 lib: Added support for setting timeouts at absolute time, rather than relative to current time.
Stephan Bosch <stephan@rename-it.nl>
parents: 17839
diff changeset
111 timeout_callback_t *callback, void *context) ATTR_NULL(4);
d80395660f27 lib: Added support for setting timeouts at absolute time, rather than relative to current time.
Stephan Bosch <stephan@rename-it.nl>
parents: 17839
diff changeset
112 #define timeout_add_absolute(time, callback, context) \
20811
1bd9c2258fd9 io: Add source filename
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 19354
diff changeset
113 timeout_add_absolute(time, __FILE__, __LINE__ + \
17853
d80395660f27 lib: Added support for setting timeouts at absolute time, rather than relative to current time.
Stephan Bosch <stephan@rename-it.nl>
parents: 17839
diff changeset
114 CALLBACK_TYPECHECK(callback, void (*)(typeof(context))), \
d80395660f27 lib: Added support for setting timeouts at absolute time, rather than relative to current time.
Stephan Bosch <stephan@rename-it.nl>
parents: 17839
diff changeset
115 (io_callback_t *)callback, context)
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
116 /* Remove timeout handler, and set timeout pointer to NULL. */
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
117 void timeout_remove(struct timeout **timeout);
7098
becdf2eacdce Use priority queue to implement timeout handling. Added timeout_reset().
Timo Sirainen <tss@iki.fi>
parents: 6410
diff changeset
118 /* Reset timeout so it's next run after now+msecs. */
becdf2eacdce Use priority queue to implement timeout handling. Added timeout_reset().
Timo Sirainen <tss@iki.fi>
parents: 6410
diff changeset
119 void timeout_reset(struct timeout *timeout);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
120
13489
3334c12a2b1a liblib: Added io_loop_time_refresh()
Timo Sirainen <tss@iki.fi>
parents: 12497
diff changeset
121 /* Refresh ioloop_time and ioloop_timeval variables. */
3334c12a2b1a liblib: Added io_loop_time_refresh()
Timo Sirainen <tss@iki.fi>
parents: 12497
diff changeset
122 void io_loop_time_refresh(void);
3334c12a2b1a liblib: Added io_loop_time_refresh()
Timo Sirainen <tss@iki.fi>
parents: 12497
diff changeset
123
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 492
diff changeset
124 void io_loop_run(struct ioloop *ioloop);
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 492
diff changeset
125 void io_loop_stop(struct ioloop *ioloop); /* safe to run in signal handler */
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
126
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3798
diff changeset
127 bool io_loop_is_running(struct ioloop *ioloop);
1033
e37e626902c3 Added io_loop_is_running()
Timo Sirainen <tss@iki.fi>
parents: 953
diff changeset
128
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
129 /* call these if you wish to run the iteration only once */
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 492
diff changeset
130 void io_loop_set_running(struct ioloop *ioloop);
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 492
diff changeset
131 void io_loop_handler_run(struct ioloop *ioloop);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
132
5248
12ac5f685814 Various cleanups to ioloop code.
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
133 struct ioloop *io_loop_create(void);
8634
86c28d14ddeb Added io_loop_set_max_fd_count() to specify how many fds we expect to use.
Timo Sirainen <tss@iki.fi>
parents: 8366
diff changeset
134 /* Specify the maximum number of fds we're expecting to use. */
86c28d14ddeb Added io_loop_set_max_fd_count() to specify how many fds we expect to use.
Timo Sirainen <tss@iki.fi>
parents: 8366
diff changeset
135 void io_loop_set_max_fd_count(struct ioloop *ioloop, unsigned int max_fds);
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
136 /* Destroy I/O loop and set ioloop pointer to NULL. */
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
137 void io_loop_destroy(struct ioloop **ioloop);
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
138
9494
a442d3c40693 ioloop: Added callback for handling time jumping forwards/backwards.
Timo Sirainen <tss@iki.fi>
parents: 9400
diff changeset
139 /* If time moves backwards or jumps forwards call the callback. */
a442d3c40693 ioloop: Added callback for handling time jumping forwards/backwards.
Timo Sirainen <tss@iki.fi>
parents: 9400
diff changeset
140 void io_loop_set_time_moved_callback(struct ioloop *ioloop,
a442d3c40693 ioloop: Added callback for handling time jumping forwards/backwards.
Timo Sirainen <tss@iki.fi>
parents: 9400
diff changeset
141 io_loop_time_moved_callback_t *callback);
a442d3c40693 ioloop: Added callback for handling time jumping forwards/backwards.
Timo Sirainen <tss@iki.fi>
parents: 9400
diff changeset
142
8366
2c111b572eee Don't break if io_remove() or timeout_remove() are called for non-active ioloops.
Timo Sirainen <tss@iki.fi>
parents: 8100
diff changeset
143 /* Change the current_ioloop. */
2c111b572eee Don't break if io_remove() or timeout_remove() are called for non-active ioloops.
Timo Sirainen <tss@iki.fi>
parents: 8100
diff changeset
144 void io_loop_set_current(struct ioloop *ioloop);
16969
54eb87b7761c Added io_loop_add/remove_switch_callback() to call a callback when ioloop is changed.
Timo Sirainen <tss@iki.fi>
parents: 15994
diff changeset
145 /* Call the callback whenever ioloop is changed. */
54eb87b7761c Added io_loop_add/remove_switch_callback() to call a callback when ioloop is changed.
Timo Sirainen <tss@iki.fi>
parents: 15994
diff changeset
146 void io_loop_add_switch_callback(io_switch_callback_t *callback);
54eb87b7761c Added io_loop_add/remove_switch_callback() to call a callback when ioloop is changed.
Timo Sirainen <tss@iki.fi>
parents: 15994
diff changeset
147 void io_loop_remove_switch_callback(io_switch_callback_t *callback);
8366
2c111b572eee Don't break if io_remove() or timeout_remove() are called for non-active ioloops.
Timo Sirainen <tss@iki.fi>
parents: 8100
diff changeset
148
13252
32315c24992c Replaced "ioloop log" with a more generic "ioloop context".
Timo Sirainen <tss@iki.fi>
parents: 12578
diff changeset
149 /* This context is used for all further I/O and timeout callbacks that are
32315c24992c Replaced "ioloop log" with a more generic "ioloop context".
Timo Sirainen <tss@iki.fi>
parents: 12578
diff changeset
150 added until returning to ioloop. When a callback is called, this context is
32315c24992c Replaced "ioloop log" with a more generic "ioloop context".
Timo Sirainen <tss@iki.fi>
parents: 12578
diff changeset
151 again activated. */
32315c24992c Replaced "ioloop log" with a more generic "ioloop context".
Timo Sirainen <tss@iki.fi>
parents: 12578
diff changeset
152 struct ioloop_context *io_loop_context_new(struct ioloop *ioloop);
32315c24992c Replaced "ioloop log" with a more generic "ioloop context".
Timo Sirainen <tss@iki.fi>
parents: 12578
diff changeset
153 void io_loop_context_ref(struct ioloop_context *ctx);
32315c24992c Replaced "ioloop log" with a more generic "ioloop context".
Timo Sirainen <tss@iki.fi>
parents: 12578
diff changeset
154 void io_loop_context_unref(struct ioloop_context **ctx);
32315c24992c Replaced "ioloop log" with a more generic "ioloop context".
Timo Sirainen <tss@iki.fi>
parents: 12578
diff changeset
155 /* Call the activate callback when this context is activated (I/O callback is
32315c24992c Replaced "ioloop log" with a more generic "ioloop context".
Timo Sirainen <tss@iki.fi>
parents: 12578
diff changeset
156 about to be called), and the deactivate callback when the context is
32315c24992c Replaced "ioloop log" with a more generic "ioloop context".
Timo Sirainen <tss@iki.fi>
parents: 12578
diff changeset
157 deactivated (I/O callback has returned). You can add multiple callbacks. */
32315c24992c Replaced "ioloop log" with a more generic "ioloop context".
Timo Sirainen <tss@iki.fi>
parents: 12578
diff changeset
158 void io_loop_context_add_callbacks(struct ioloop_context *ctx,
32315c24992c Replaced "ioloop log" with a more generic "ioloop context".
Timo Sirainen <tss@iki.fi>
parents: 12578
diff changeset
159 io_callback_t *activate,
32315c24992c Replaced "ioloop log" with a more generic "ioloop context".
Timo Sirainen <tss@iki.fi>
parents: 12578
diff changeset
160 io_callback_t *deactivate, void *context);
17839
e588792b4f20 lib: Code cleanup - check io_loop_context_add/remove_callbacks() callback parameters.
Timo Sirainen <tss@iki.fi>
parents: 17188
diff changeset
161 #define io_loop_context_add_callbacks(ctx, activate, deactivate, context) \
e588792b4f20 lib: Code cleanup - check io_loop_context_add/remove_callbacks() callback parameters.
Timo Sirainen <tss@iki.fi>
parents: 17188
diff changeset
162 io_loop_context_add_callbacks(ctx, 1 ? (io_callback_t *)activate : \
e588792b4f20 lib: Code cleanup - check io_loop_context_add/remove_callbacks() callback parameters.
Timo Sirainen <tss@iki.fi>
parents: 17188
diff changeset
163 CALLBACK_TYPECHECK(activate, void (*)(typeof(context))) + \
e588792b4f20 lib: Code cleanup - check io_loop_context_add/remove_callbacks() callback parameters.
Timo Sirainen <tss@iki.fi>
parents: 17188
diff changeset
164 CALLBACK_TYPECHECK(deactivate, void (*)(typeof(context))), \
e588792b4f20 lib: Code cleanup - check io_loop_context_add/remove_callbacks() callback parameters.
Timo Sirainen <tss@iki.fi>
parents: 17188
diff changeset
165 (io_callback_t *)deactivate, context)
13285
c17e4f8ddc81 liblib: io_loop_context_remove_callbacks() now requires also callbacks.
Timo Sirainen <tss@iki.fi>
parents: 13252
diff changeset
166 /* Remove callbacks with the given callbacks and context. */
13252
32315c24992c Replaced "ioloop log" with a more generic "ioloop context".
Timo Sirainen <tss@iki.fi>
parents: 12578
diff changeset
167 void io_loop_context_remove_callbacks(struct ioloop_context *ctx,
13285
c17e4f8ddc81 liblib: io_loop_context_remove_callbacks() now requires also callbacks.
Timo Sirainen <tss@iki.fi>
parents: 13252
diff changeset
168 io_callback_t *activate,
c17e4f8ddc81 liblib: io_loop_context_remove_callbacks() now requires also callbacks.
Timo Sirainen <tss@iki.fi>
parents: 13252
diff changeset
169 io_callback_t *deactivate, void *context);
17839
e588792b4f20 lib: Code cleanup - check io_loop_context_add/remove_callbacks() callback parameters.
Timo Sirainen <tss@iki.fi>
parents: 17188
diff changeset
170 #define io_loop_context_remove_callbacks(ctx, activate, deactivate, context) \
e588792b4f20 lib: Code cleanup - check io_loop_context_add/remove_callbacks() callback parameters.
Timo Sirainen <tss@iki.fi>
parents: 17188
diff changeset
171 io_loop_context_remove_callbacks(ctx, 1 ? (io_callback_t *)activate : \
e588792b4f20 lib: Code cleanup - check io_loop_context_add/remove_callbacks() callback parameters.
Timo Sirainen <tss@iki.fi>
parents: 17188
diff changeset
172 CALLBACK_TYPECHECK(activate, void (*)(typeof(context))) + \
e588792b4f20 lib: Code cleanup - check io_loop_context_add/remove_callbacks() callback parameters.
Timo Sirainen <tss@iki.fi>
parents: 17188
diff changeset
173 CALLBACK_TYPECHECK(deactivate, void (*)(typeof(context))), \
e588792b4f20 lib: Code cleanup - check io_loop_context_add/remove_callbacks() callback parameters.
Timo Sirainen <tss@iki.fi>
parents: 17188
diff changeset
174 (io_callback_t *)deactivate, context)
13286
b6b16c9eb3d5 liblib: Added io_loop_get_current_context()
Timo Sirainen <tss@iki.fi>
parents: 13285
diff changeset
175 /* Returns the current context set to ioloop. */
b6b16c9eb3d5 liblib: Added io_loop_get_current_context()
Timo Sirainen <tss@iki.fi>
parents: 13285
diff changeset
176 struct ioloop_context *io_loop_get_current_context(struct ioloop *ioloop);
12497
1bac1c09201a ioloop: Added support for per-io/timeout callback log prefix automation.
Timo Sirainen <tss@iki.fi>
parents: 9494
diff changeset
177
18994
3083424cafcd lib: Added io_loop_extract_notify_fd()
Timo Sirainen <tss@iki.fi>
parents: 18984
diff changeset
178 /* Returns fd, which contains all of the ioloop's current notifications.
3083424cafcd lib: Added io_loop_extract_notify_fd()
Timo Sirainen <tss@iki.fi>
parents: 18984
diff changeset
179 When it becomes readable, there is a new notification. Calling this function
3083424cafcd lib: Added io_loop_extract_notify_fd()
Timo Sirainen <tss@iki.fi>
parents: 18984
diff changeset
180 stops the existing notifications in the ioloop from working anymore.
3083424cafcd lib: Added io_loop_extract_notify_fd()
Timo Sirainen <tss@iki.fi>
parents: 18984
diff changeset
181 This function's main idea is that the fd can be passed to another process,
3083424cafcd lib: Added io_loop_extract_notify_fd()
Timo Sirainen <tss@iki.fi>
parents: 18984
diff changeset
182 which can use it to find out if an interesting notification happens.
3083424cafcd lib: Added io_loop_extract_notify_fd()
Timo Sirainen <tss@iki.fi>
parents: 18984
diff changeset
183 Returns fd on success, -1 on error. */
3083424cafcd lib: Added io_loop_extract_notify_fd()
Timo Sirainen <tss@iki.fi>
parents: 18984
diff changeset
184 int io_loop_extract_notify_fd(struct ioloop *ioloop);
3083424cafcd lib: Added io_loop_extract_notify_fd()
Timo Sirainen <tss@iki.fi>
parents: 18984
diff changeset
185
21106
97386e9e8c13 lib: Added io_wait_timer
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20949
diff changeset
186 /* IO wait timers can be used to track how much time the io_wait_timer has
97386e9e8c13 lib: Added io_wait_timer
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20949
diff changeset
187 spent on waiting in its ioloops. This is similar to
97386e9e8c13 lib: Added io_wait_timer
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20949
diff changeset
188 io_loop_get_wait_usecs(), but it's easier to use when the wait time needs
97386e9e8c13 lib: Added io_wait_timer
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20949
diff changeset
189 to be tracked across multiple ioloops. */
97386e9e8c13 lib: Added io_wait_timer
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20949
diff changeset
190 struct io_wait_timer *
97386e9e8c13 lib: Added io_wait_timer
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20949
diff changeset
191 io_wait_timer_add(const char *source_filename, unsigned int source_linenum);
97386e9e8c13 lib: Added io_wait_timer
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20949
diff changeset
192 #define io_wait_timer_add() \
97386e9e8c13 lib: Added io_wait_timer
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20949
diff changeset
193 io_wait_timer_add(__FILE__, __LINE__)
97386e9e8c13 lib: Added io_wait_timer
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20949
diff changeset
194 struct io_wait_timer *io_wait_timer_move(struct io_wait_timer **timer);
97386e9e8c13 lib: Added io_wait_timer
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20949
diff changeset
195 void io_wait_timer_remove(struct io_wait_timer **timer);
97386e9e8c13 lib: Added io_wait_timer
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20949
diff changeset
196 uint64_t io_wait_timer_get_usecs(struct io_wait_timer *timer);
97386e9e8c13 lib: Added io_wait_timer
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20949
diff changeset
197
12578
7785af0ca36e Added io_loop_move_io() and io_loop_move_timeout().
Timo Sirainen <tss@iki.fi>
parents: 12497
diff changeset
198 /* Move the given I/O into the current I/O loop if it's not already
7785af0ca36e Added io_loop_move_io() and io_loop_move_timeout().
Timo Sirainen <tss@iki.fi>
parents: 12497
diff changeset
199 there. New I/O is returned, while the old one is freed. */
7785af0ca36e Added io_loop_move_io() and io_loop_move_timeout().
Timo Sirainen <tss@iki.fi>
parents: 12497
diff changeset
200 struct io *io_loop_move_io(struct io **io);
7785af0ca36e Added io_loop_move_io() and io_loop_move_timeout().
Timo Sirainen <tss@iki.fi>
parents: 12497
diff changeset
201 /* Like io_loop_move_io(), but for timeouts. */
7785af0ca36e Added io_loop_move_io() and io_loop_move_timeout().
Timo Sirainen <tss@iki.fi>
parents: 12497
diff changeset
202 struct timeout *io_loop_move_timeout(struct timeout **timeout);
15973
4517f9b201f2 Added io_loop_have_ios()
Timo Sirainen <tss@iki.fi>
parents: 14921
diff changeset
203 /* Returns TRUE if any IOs have been added to the ioloop. */
4517f9b201f2 Added io_loop_have_ios()
Timo Sirainen <tss@iki.fi>
parents: 14921
diff changeset
204 bool io_loop_have_ios(struct ioloop *ioloop);
15994
6daf58f568a0 Added io_loop_have_immediate_timeouts()
Timo Sirainen <tss@iki.fi>
parents: 15973
diff changeset
205 /* Returns TRUE if there is a pending timeout that is going to be run
6daf58f568a0 Added io_loop_have_immediate_timeouts()
Timo Sirainen <tss@iki.fi>
parents: 15973
diff changeset
206 immediately. */
6daf58f568a0 Added io_loop_have_immediate_timeouts()
Timo Sirainen <tss@iki.fi>
parents: 15973
diff changeset
207 bool io_loop_have_immediate_timeouts(struct ioloop *ioloop);
19160
1076679adf9f lib: Added io_loop_get_wait_usecs()
Timo Sirainen <tss@iki.fi>
parents: 18994
diff changeset
208 /* Returns number of microseconds spent on the ioloop waiting itself. */
1076679adf9f lib: Added io_loop_get_wait_usecs()
Timo Sirainen <tss@iki.fi>
parents: 18994
diff changeset
209 uint64_t io_loop_get_wait_usecs(struct ioloop *ioloop);
19354
2f3b58470752 lib: Added io_loop_find_fd_conditions()
Timo Sirainen <tss@iki.fi>
parents: 19160
diff changeset
210 /* Return all io conditions added for the given fd. This needs to scan through
2f3b58470752 lib: Added io_loop_find_fd_conditions()
Timo Sirainen <tss@iki.fi>
parents: 19160
diff changeset
211 all the file ios in the ioloop. */
2f3b58470752 lib: Added io_loop_find_fd_conditions()
Timo Sirainen <tss@iki.fi>
parents: 19160
diff changeset
212 enum io_condition io_loop_find_fd_conditions(struct ioloop *ioloop, int fd);
12497
1bac1c09201a ioloop: Added support for per-io/timeout callback log prefix automation.
Timo Sirainen <tss@iki.fi>
parents: 9494
diff changeset
213
0
3b1985cbc908 Initial revision
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
214 #endif