Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib/ioloop.h @ 9354:687ac828b964 HEAD
lib-index: modseqs weren't tracked properly within session when changes were done.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 01 Sep 2009 13:05:03 -0400 |
parents | 86c28d14ddeb |
children |
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 | 3 |
1431
8a2e1c539faf
struct timeval requires sys/time.h
Timo Sirainen <tss@iki.fi>
parents:
1036
diff
changeset
|
4 #include <sys/time.h> |
0 | 5 #include <time.h> |
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; |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
492
diff
changeset
|
10 |
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
|
11 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
|
12 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
|
13 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
|
14 /* 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
|
15 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
|
16 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
|
17 |
a9be1824403b
New inotify code and notify API change. Patch by Johannes Berg
Timo Sirainen <tss@iki.fi>
parents:
1729
diff
changeset
|
18 /* internal */ |
4150
49e024519e22
IO_ERROR and IO_NOTIFY had conflicting values.
Timo Sirainen <tss@iki.fi>
parents:
4039
diff
changeset
|
19 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
|
20 }; |
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 |
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
|
22 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
|
23 /* 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
|
24 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
|
25 /* 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
|
26 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
|
27 /* 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
|
28 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
|
29 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
|
30 }; |
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 |
1036
f782b3319553
Removed useless parameters from io_callback_t and timeout_callback_t.
Timo Sirainen <tss@iki.fi>
parents:
1033
diff
changeset
|
32 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
|
33 typedef void timeout_callback_t(void *context); |
0 | 34 |
35 /* Time when the I/O loop started calling handlers. | |
36 Can be used instead of time(NULL). */ | |
37 extern time_t ioloop_time; | |
38 extern struct timeval ioloop_timeval; | |
492
efa46e28a0d7
Fixes to timezone handling which were handling quite badly. added
Timo Sirainen <tss@iki.fi>
parents:
389
diff
changeset
|
39 extern struct timezone ioloop_timezone; |
0 | 40 |
3798
be1bac1dd005
Export current_ioloop globally.
Timo Sirainen <tss@iki.fi>
parents:
3613
diff
changeset
|
41 extern struct ioloop *current_ioloop; |
be1bac1dd005
Export current_ioloop globally.
Timo Sirainen <tss@iki.fi>
parents:
3613
diff
changeset
|
42 |
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
|
43 /* 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
|
44 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
|
45 |
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
|
46 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
|
47 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
|
48 struct io *io_add(int fd, enum io_condition 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
|
49 io_callback_t *callback, void *context); |
4903
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4579
diff
changeset
|
50 #define io_add(fd, condition, callback, context) \ |
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4579
diff
changeset
|
51 CONTEXT_CALLBACK(io_add, io_callback_t, \ |
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4579
diff
changeset
|
52 callback, context, fd, condition) |
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
|
53 enum io_notify_result io_add_notify(const char *path, io_callback_t *callback, |
772f4e8bd2a9
Changed io_add_notify() API so that it can return "file doesn't exist"
Timo Sirainen <tss@iki.fi>
parents:
5248
diff
changeset
|
54 void *context, struct io **io_r); |
772f4e8bd2a9
Changed io_add_notify() API so that it can return "file doesn't exist"
Timo Sirainen <tss@iki.fi>
parents:
5248
diff
changeset
|
55 #ifdef CONTEXT_TYPE_SAFETY |
772f4e8bd2a9
Changed io_add_notify() API so that it can return "file doesn't exist"
Timo Sirainen <tss@iki.fi>
parents:
5248
diff
changeset
|
56 # define io_add_notify(path, callback, context, io_r) \ |
772f4e8bd2a9
Changed io_add_notify() API so that it can return "file doesn't exist"
Timo Sirainen <tss@iki.fi>
parents:
5248
diff
changeset
|
57 ({(void)(1 ? 0 : callback(context)); \ |
772f4e8bd2a9
Changed io_add_notify() API so that it can return "file doesn't exist"
Timo Sirainen <tss@iki.fi>
parents:
5248
diff
changeset
|
58 io_add_notify(path, (io_callback_t *)callback, context, io_r); }) |
772f4e8bd2a9
Changed io_add_notify() API so that it can return "file doesn't exist"
Timo Sirainen <tss@iki.fi>
parents:
5248
diff
changeset
|
59 #else |
772f4e8bd2a9
Changed io_add_notify() API so that it can return "file doesn't exist"
Timo Sirainen <tss@iki.fi>
parents:
5248
diff
changeset
|
60 # define io_add_notify(path, callback, context, io_r) \ |
772f4e8bd2a9
Changed io_add_notify() API so that it can return "file doesn't exist"
Timo Sirainen <tss@iki.fi>
parents:
5248
diff
changeset
|
61 io_add_notify(path, (io_callback_t *)callback, context, io_r) |
772f4e8bd2a9
Changed io_add_notify() API so that it can return "file doesn't exist"
Timo Sirainen <tss@iki.fi>
parents:
5248
diff
changeset
|
62 #endif |
772f4e8bd2a9
Changed io_add_notify() API so that it can return "file doesn't exist"
Timo Sirainen <tss@iki.fi>
parents:
5248
diff
changeset
|
63 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
64 /* 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
|
65 void io_remove(struct io **io); |
8100 | 66 /* Like io_remove(), but assume that the file descriptor is already closed. |
67 With some backends this simply frees the memory. */ | |
68 void io_remove_closed(struct io **io); | |
0 | 69 |
70 /* Timeout handlers */ | |
1499
e850252cdc7e
Removed I/O priorities. They were pretty much useless and were just getting
Timo Sirainen <tss@iki.fi>
parents:
1431
diff
changeset
|
71 struct timeout *timeout_add(unsigned int msecs, timeout_callback_t *callback, |
953
411006be3c66
Naming change for function typedefs.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
72 void *context); |
4903
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4579
diff
changeset
|
73 #define timeout_add(msecs, callback, context) \ |
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4579
diff
changeset
|
74 CONTEXT_CALLBACK(timeout_add, timeout_callback_t, \ |
204d7edc7cdc
Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents:
4579
diff
changeset
|
75 callback, context, msecs) |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
76 /* 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
|
77 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
|
78 /* 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
|
79 void timeout_reset(struct timeout *timeout); |
0 | 80 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
492
diff
changeset
|
81 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
|
82 void io_loop_stop(struct ioloop *ioloop); /* safe to run in signal handler */ |
0 | 83 |
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
|
84 bool io_loop_is_running(struct ioloop *ioloop); |
1033 | 85 |
0 | 86 /* 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
|
87 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
|
88 void io_loop_handler_run(struct ioloop *ioloop); |
0 | 89 |
5248
12ac5f685814
Various cleanups to ioloop code.
Timo Sirainen <tss@iki.fi>
parents:
4903
diff
changeset
|
90 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
|
91 /* 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
|
92 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
|
93 /* 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
|
94 void io_loop_destroy(struct ioloop **ioloop); |
0 | 95 |
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
|
96 /* 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
|
97 void io_loop_set_current(struct ioloop *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
|
98 |
0 | 99 #endif |