Mercurial > dovecot > core-2.2
annotate src/lib/ioloop-poll.c @ 23007:36e01285b5b8
lib: buffer - Improve header comment for buffer_insert() and buffer_delete().
author | Stephan Bosch <stephan.bosch@dovecot.fi> |
---|---|
date | Mon, 18 Mar 2019 00:52:37 +0100 |
parents | cb108f786fb4 |
children |
rev | line source |
---|---|
22713
cb108f786fb4
Updated copyright notices to include the year 2018.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents:
22161
diff
changeset
|
1 /* Copyright (c) 2002-2018 Dovecot authors, see the included COPYING file */ |
0 | 2 |
805
5ac361acb316
Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents:
676
diff
changeset
|
3 /* @UNSAFE: whole file */ |
5ac361acb316
Marked all non-trivial buffer modifications with @UNSAFE tag. Several
Timo Sirainen <tss@iki.fi>
parents:
676
diff
changeset
|
4 |
0 | 5 #include "lib.h" |
13529
cf77e448295c
Renamed lib/*-internal.h files to lib/*-private.h for consistency.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
6 #include "ioloop-private.h" |
0 | 7 |
676
3e23fa94f762
select() support was broken. Also changed the way it's built.
Timo Sirainen <tss@iki.fi>
parents:
536
diff
changeset
|
8 #ifdef IOLOOP_POLL |
3e23fa94f762
select() support was broken. Also changed the way it's built.
Timo Sirainen <tss@iki.fi>
parents:
536
diff
changeset
|
9 |
3961
3a2d31358d55
If DEBUG is enabled, make sure the fd is still open when removing the I/O
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
10 #include <fcntl.h> |
0 | 11 #include <sys/poll.h> |
12 | |
3483
84a4f150bd00
data -> context/ctx naming convention replaces
Timo Sirainen <tss@iki.fi>
parents:
3298
diff
changeset
|
13 struct ioloop_handler_context { |
3861
398dcca97d24
Cleanup + removed compiler warnings with 64bit systems
Timo Sirainen <tss@iki.fi>
parents:
3614
diff
changeset
|
14 unsigned int fds_count, fds_pos; |
0 | 15 struct pollfd *fds; |
16 | |
3861
398dcca97d24
Cleanup + removed compiler warnings with 64bit systems
Timo Sirainen <tss@iki.fi>
parents:
3614
diff
changeset
|
17 unsigned int idx_count; |
0 | 18 int *fd_index; |
19 }; | |
20 | |
8634
86c28d14ddeb
Added io_loop_set_max_fd_count() to specify how many fds we expect to use.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
21 void io_loop_handler_init(struct ioloop *ioloop, unsigned int initial_fd_count) |
0 | 22 { |
3483
84a4f150bd00
data -> context/ctx naming convention replaces
Timo Sirainen <tss@iki.fi>
parents:
3298
diff
changeset
|
23 struct ioloop_handler_context *ctx; |
0 | 24 |
5248
12ac5f685814
Various cleanups to ioloop code.
Timo Sirainen <tss@iki.fi>
parents:
4971
diff
changeset
|
25 ioloop->handler_context = ctx = i_new(struct ioloop_handler_context, 1); |
8634
86c28d14ddeb
Added io_loop_set_max_fd_count() to specify how many fds we expect to use.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
26 ctx->fds_count = initial_fd_count; |
5248
12ac5f685814
Various cleanups to ioloop code.
Timo Sirainen <tss@iki.fi>
parents:
4971
diff
changeset
|
27 ctx->fds = i_new(struct pollfd, ctx->fds_count); |
0 | 28 |
8634
86c28d14ddeb
Added io_loop_set_max_fd_count() to specify how many fds we expect to use.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
29 ctx->idx_count = initial_fd_count; |
5248
12ac5f685814
Various cleanups to ioloop code.
Timo Sirainen <tss@iki.fi>
parents:
4971
diff
changeset
|
30 ctx->fd_index = i_new(int, ctx->idx_count); |
3861
398dcca97d24
Cleanup + removed compiler warnings with 64bit systems
Timo Sirainen <tss@iki.fi>
parents:
3614
diff
changeset
|
31 memset(ctx->fd_index, 0xff, sizeof(int) * ctx->idx_count); |
0 | 32 } |
33 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
899
diff
changeset
|
34 void io_loop_handler_deinit(struct ioloop *ioloop) |
0 | 35 { |
5248
12ac5f685814
Various cleanups to ioloop code.
Timo Sirainen <tss@iki.fi>
parents:
4971
diff
changeset
|
36 i_free(ioloop->handler_context->fds); |
12ac5f685814
Various cleanups to ioloop code.
Timo Sirainen <tss@iki.fi>
parents:
4971
diff
changeset
|
37 i_free(ioloop->handler_context->fd_index); |
12ac5f685814
Various cleanups to ioloop code.
Timo Sirainen <tss@iki.fi>
parents:
4971
diff
changeset
|
38 i_free(ioloop->handler_context); |
0 | 39 } |
40 | |
3614 | 41 #define IO_POLL_ERROR (POLLERR | POLLHUP | POLLNVAL) |
42 #define IO_POLL_INPUT (POLLIN | POLLPRI | IO_POLL_ERROR) | |
43 #define IO_POLL_OUTPUT (POLLOUT | IO_POLL_ERROR) | |
0 | 44 |
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
|
45 void io_loop_handle_add(struct io_file *io) |
0 | 46 { |
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
|
47 struct ioloop_handler_context *ctx = io->io.ioloop->handler_context; |
5248
12ac5f685814
Various cleanups to ioloop code.
Timo Sirainen <tss@iki.fi>
parents:
4971
diff
changeset
|
48 enum io_condition condition = io->io.condition; |
3861
398dcca97d24
Cleanup + removed compiler warnings with 64bit systems
Timo Sirainen <tss@iki.fi>
parents:
3614
diff
changeset
|
49 unsigned int old_count; |
9731
111812403bea
ioloop poll: Added assert to catch double-io_add()s.
Timo Sirainen <tss@iki.fi>
parents:
9494
diff
changeset
|
50 int index, old_events, fd = io->fd; |
0 | 51 |
3861
398dcca97d24
Cleanup + removed compiler warnings with 64bit systems
Timo Sirainen <tss@iki.fi>
parents:
3614
diff
changeset
|
52 if ((unsigned int)fd >= ctx->idx_count) { |
0 | 53 /* grow the fd -> index array */ |
3861
398dcca97d24
Cleanup + removed compiler warnings with 64bit systems
Timo Sirainen <tss@iki.fi>
parents:
3614
diff
changeset
|
54 old_count = ctx->idx_count; |
0 | 55 |
3861
398dcca97d24
Cleanup + removed compiler warnings with 64bit systems
Timo Sirainen <tss@iki.fi>
parents:
3614
diff
changeset
|
56 ctx->idx_count = nearest_power((unsigned int) fd+1); |
1500 | 57 |
22140
8089604afa5a
global: Use i_realloc_type() wherever possible
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
58 ctx->fd_index = i_realloc_type(ctx->fd_index, int, |
8089604afa5a
global: Use i_realloc_type() wherever possible
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
59 old_count, ctx->idx_count); |
3861
398dcca97d24
Cleanup + removed compiler warnings with 64bit systems
Timo Sirainen <tss@iki.fi>
parents:
3614
diff
changeset
|
60 memset(ctx->fd_index + old_count, 0xff, |
398dcca97d24
Cleanup + removed compiler warnings with 64bit systems
Timo Sirainen <tss@iki.fi>
parents:
3614
diff
changeset
|
61 sizeof(int) * (ctx->idx_count-old_count)); |
0 | 62 } |
63 | |
3861
398dcca97d24
Cleanup + removed compiler warnings with 64bit systems
Timo Sirainen <tss@iki.fi>
parents:
3614
diff
changeset
|
64 if (ctx->fds_pos >= ctx->fds_count) { |
0 | 65 /* grow the fd array */ |
3861
398dcca97d24
Cleanup + removed compiler warnings with 64bit systems
Timo Sirainen <tss@iki.fi>
parents:
3614
diff
changeset
|
66 old_count = ctx->fds_count; |
941
4d6b69558add
Added old_size parameter to p_realloc() - we rarely need it and this way
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
67 |
3861
398dcca97d24
Cleanup + removed compiler warnings with 64bit systems
Timo Sirainen <tss@iki.fi>
parents:
3614
diff
changeset
|
68 ctx->fds_count = nearest_power(ctx->fds_count+1); |
1500 | 69 |
22140
8089604afa5a
global: Use i_realloc_type() wherever possible
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
70 ctx->fds = i_realloc_type(ctx->fds, struct pollfd, |
8089604afa5a
global: Use i_realloc_type() wherever possible
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
21390
diff
changeset
|
71 old_count, ctx->fds_count); |
0 | 72 } |
73 | |
3483
84a4f150bd00
data -> context/ctx naming convention replaces
Timo Sirainen <tss@iki.fi>
parents:
3298
diff
changeset
|
74 if (ctx->fd_index[fd] != -1) { |
0 | 75 /* update existing pollfd */ |
3483
84a4f150bd00
data -> context/ctx naming convention replaces
Timo Sirainen <tss@iki.fi>
parents:
3298
diff
changeset
|
76 index = ctx->fd_index[fd]; |
0 | 77 } else { |
78 /* add new pollfd */ | |
3483
84a4f150bd00
data -> context/ctx naming convention replaces
Timo Sirainen <tss@iki.fi>
parents:
3298
diff
changeset
|
79 index = ctx->fds_pos++; |
0 | 80 |
3483
84a4f150bd00
data -> context/ctx naming convention replaces
Timo Sirainen <tss@iki.fi>
parents:
3298
diff
changeset
|
81 ctx->fd_index[fd] = index; |
84a4f150bd00
data -> context/ctx naming convention replaces
Timo Sirainen <tss@iki.fi>
parents:
3298
diff
changeset
|
82 ctx->fds[index].fd = fd; |
84a4f150bd00
data -> context/ctx naming convention replaces
Timo Sirainen <tss@iki.fi>
parents:
3298
diff
changeset
|
83 ctx->fds[index].events = 0; |
84a4f150bd00
data -> context/ctx naming convention replaces
Timo Sirainen <tss@iki.fi>
parents:
3298
diff
changeset
|
84 ctx->fds[index].revents = 0; |
0 | 85 } |
86 | |
9731
111812403bea
ioloop poll: Added assert to catch double-io_add()s.
Timo Sirainen <tss@iki.fi>
parents:
9494
diff
changeset
|
87 old_events = ctx->fds[index].events; |
22161
f9c89c5172a5
-Wstrict-bool warning fixes
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22140
diff
changeset
|
88 if ((condition & IO_READ) != 0) |
3483
84a4f150bd00
data -> context/ctx naming convention replaces
Timo Sirainen <tss@iki.fi>
parents:
3298
diff
changeset
|
89 ctx->fds[index].events |= IO_POLL_INPUT; |
22161
f9c89c5172a5
-Wstrict-bool warning fixes
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22140
diff
changeset
|
90 if ((condition & IO_WRITE) != 0) |
3483
84a4f150bd00
data -> context/ctx naming convention replaces
Timo Sirainen <tss@iki.fi>
parents:
3298
diff
changeset
|
91 ctx->fds[index].events |= IO_POLL_OUTPUT; |
22161
f9c89c5172a5
-Wstrict-bool warning fixes
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22140
diff
changeset
|
92 if ((condition & IO_ERROR) != 0) |
3613
c4c1b538d8d0
Added IO_ERROR condition that we can watch now.
Timo Sirainen <tss@iki.fi>
parents:
3527
diff
changeset
|
93 ctx->fds[index].events |= IO_POLL_ERROR; |
9731
111812403bea
ioloop poll: Added assert to catch double-io_add()s.
Timo Sirainen <tss@iki.fi>
parents:
9494
diff
changeset
|
94 i_assert(ctx->fds[index].events != old_events); |
0 | 95 } |
96 | |
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
|
97 void io_loop_handle_remove(struct io_file *io, bool closed ATTR_UNUSED) |
0 | 98 { |
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
|
99 struct ioloop_handler_context *ctx = io->io.ioloop->handler_context; |
5248
12ac5f685814
Various cleanups to ioloop code.
Timo Sirainen <tss@iki.fi>
parents:
4971
diff
changeset
|
100 enum io_condition condition = io->io.condition; |
2480
ac93896adcc3
Internal I/O loop API change in preparation for epoll support. Patch by
Timo Sirainen <tss@iki.fi>
parents:
1741
diff
changeset
|
101 int index, fd = io->fd; |
0 | 102 |
3483
84a4f150bd00
data -> context/ctx naming convention replaces
Timo Sirainen <tss@iki.fi>
parents:
3298
diff
changeset
|
103 index = ctx->fd_index[fd]; |
3861
398dcca97d24
Cleanup + removed compiler warnings with 64bit systems
Timo Sirainen <tss@iki.fi>
parents:
3614
diff
changeset
|
104 i_assert(index >= 0 && (unsigned int) index < ctx->fds_count); |
0 | 105 |
3961
3a2d31358d55
If DEBUG is enabled, make sure the fd is still open when removing the I/O
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
106 #ifdef DEBUG |
8100 | 107 if (!closed) { |
108 /* io_remove() is required to be called before fd is closed. | |
109 This is required by epoll/kqueue, but since poll is more | |
110 commonly used while developing, this check here should catch | |
111 the error early enough not to cause problems for kqueue | |
112 users. */ | |
113 if (fcntl(io->fd, F_GETFD, 0) < 0) { | |
114 if (errno == EBADF) | |
115 i_panic("io_remove(%d) called too late", io->fd); | |
116 else | |
117 i_error("fcntl(%d, F_GETFD) failed: %m", io->fd); | |
118 } | |
3961
3a2d31358d55
If DEBUG is enabled, make sure the fd is still open when removing the I/O
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
119 } |
3a2d31358d55
If DEBUG is enabled, make sure the fd is still open when removing the I/O
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
120 #endif |
5248
12ac5f685814
Various cleanups to ioloop code.
Timo Sirainen <tss@iki.fi>
parents:
4971
diff
changeset
|
121 i_free(io); |
3961
3a2d31358d55
If DEBUG is enabled, make sure the fd is still open when removing the I/O
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
122 |
22161
f9c89c5172a5
-Wstrict-bool warning fixes
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22140
diff
changeset
|
123 if ((condition & IO_READ) != 0) { |
3483
84a4f150bd00
data -> context/ctx naming convention replaces
Timo Sirainen <tss@iki.fi>
parents:
3298
diff
changeset
|
124 ctx->fds[index].events &= ~(POLLIN|POLLPRI); |
84a4f150bd00
data -> context/ctx naming convention replaces
Timo Sirainen <tss@iki.fi>
parents:
3298
diff
changeset
|
125 ctx->fds[index].revents &= ~(POLLIN|POLLPRI); |
1496
aa1e8b09b580
Clear old poll revents when removing the IO. Just extra sanity check.
Timo Sirainen <tss@iki.fi>
parents:
1399
diff
changeset
|
126 } |
22161
f9c89c5172a5
-Wstrict-bool warning fixes
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22140
diff
changeset
|
127 if ((condition & IO_WRITE) != 0) { |
3483
84a4f150bd00
data -> context/ctx naming convention replaces
Timo Sirainen <tss@iki.fi>
parents:
3298
diff
changeset
|
128 ctx->fds[index].events &= ~POLLOUT; |
84a4f150bd00
data -> context/ctx naming convention replaces
Timo Sirainen <tss@iki.fi>
parents:
3298
diff
changeset
|
129 ctx->fds[index].revents &= ~POLLOUT; |
1496
aa1e8b09b580
Clear old poll revents when removing the IO. Just extra sanity check.
Timo Sirainen <tss@iki.fi>
parents:
1399
diff
changeset
|
130 } |
0 | 131 |
3483
84a4f150bd00
data -> context/ctx naming convention replaces
Timo Sirainen <tss@iki.fi>
parents:
3298
diff
changeset
|
132 if ((ctx->fds[index].events & (POLLIN|POLLOUT)) == 0) { |
0 | 133 /* remove the whole pollfd */ |
3483
84a4f150bd00
data -> context/ctx naming convention replaces
Timo Sirainen <tss@iki.fi>
parents:
3298
diff
changeset
|
134 ctx->fd_index[ctx->fds[index].fd] = -1; |
84a4f150bd00
data -> context/ctx naming convention replaces
Timo Sirainen <tss@iki.fi>
parents:
3298
diff
changeset
|
135 if (--ctx->fds_pos == (unsigned int) index) |
0 | 136 return; /* removing last one */ |
137 | |
138 /* move the last pollfd over the removed one */ | |
3483
84a4f150bd00
data -> context/ctx naming convention replaces
Timo Sirainen <tss@iki.fi>
parents:
3298
diff
changeset
|
139 ctx->fds[index] = ctx->fds[ctx->fds_pos]; |
84a4f150bd00
data -> context/ctx naming convention replaces
Timo Sirainen <tss@iki.fi>
parents:
3298
diff
changeset
|
140 ctx->fd_index[ctx->fds[index].fd] = index; |
0 | 141 } |
142 } | |
143 | |
17187
d2a6f57e174f
ioloop: Added io_set_pending()
Timo Sirainen <tss@iki.fi>
parents:
17130
diff
changeset
|
144 void io_loop_handler_run_internal(struct ioloop *ioloop) |
0 | 145 { |
3483
84a4f150bd00
data -> context/ctx naming convention replaces
Timo Sirainen <tss@iki.fi>
parents:
3298
diff
changeset
|
146 struct ioloop_handler_context *ctx = ioloop->handler_context; |
0 | 147 struct pollfd *pollfd; |
148 struct timeval tv; | |
5248
12ac5f685814
Various cleanups to ioloop code.
Timo Sirainen <tss@iki.fi>
parents:
4971
diff
changeset
|
149 struct io_file *io; |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3861
diff
changeset
|
150 int msecs, ret; |
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3861
diff
changeset
|
151 bool call; |
0 | 152 |
153 /* get the time left for next timeout task */ | |
9494
a442d3c40693
ioloop: Added callback for handling time jumping forwards/backwards.
Timo Sirainen <tss@iki.fi>
parents:
8634
diff
changeset
|
154 msecs = io_loop_get_wait_time(ioloop, &tv); |
12129
4a5e2be6e112
poll: Added a workaround for AIX to get it to notice IO_ERRORs
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
155 #ifdef _AIX |
4a5e2be6e112
poll: Added a workaround for AIX to get it to notice IO_ERRORs
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
156 if (msecs > 1000) { |
4a5e2be6e112
poll: Added a workaround for AIX to get it to notice IO_ERRORs
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
157 /* AIX seems to check IO_POLL_ERRORs only at the beginning of |
4a5e2be6e112
poll: Added a workaround for AIX to get it to notice IO_ERRORs
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
158 the poll() call, not during it. keep timeouts short enough |
4a5e2be6e112
poll: Added a workaround for AIX to get it to notice IO_ERRORs
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
159 so that we'll notice them pretty quickly. */ |
4a5e2be6e112
poll: Added a workaround for AIX to get it to notice IO_ERRORs
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
160 msecs = 1000; |
4a5e2be6e112
poll: Added a workaround for AIX to get it to notice IO_ERRORs
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
161 } |
4a5e2be6e112
poll: Added a workaround for AIX to get it to notice IO_ERRORs
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
162 #endif |
0 | 163 |
3483
84a4f150bd00
data -> context/ctx naming convention replaces
Timo Sirainen <tss@iki.fi>
parents:
3298
diff
changeset
|
164 ret = poll(ctx->fds, ctx->fds_pos, msecs); |
0 | 165 if (ret < 0 && errno != EINTR) |
2569
554f1324a435
Added epoll support if --with-ioloop=epoll is given. Patch by Andrey Panin.
Timo Sirainen <tss@iki.fi>
parents:
2496
diff
changeset
|
166 i_fatal("poll(): %m"); |
0 | 167 |
168 /* execute timeout handlers */ | |
7098
becdf2eacdce
Use priority queue to implement timeout handling. Added timeout_reset().
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
169 io_loop_handle_timeouts(ioloop); |
0 | 170 |
171 if (ret <= 0 || !ioloop->running) { | |
172 /* no I/O events */ | |
173 return; | |
174 } | |
175 | |
5248
12ac5f685814
Various cleanups to ioloop code.
Timo Sirainen <tss@iki.fi>
parents:
4971
diff
changeset
|
176 io = ioloop->io_files; |
12ac5f685814
Various cleanups to ioloop code.
Timo Sirainen <tss@iki.fi>
parents:
4971
diff
changeset
|
177 for (; io != NULL && ret > 0; io = ioloop->next_io_file) { |
12ac5f685814
Various cleanups to ioloop code.
Timo Sirainen <tss@iki.fi>
parents:
4971
diff
changeset
|
178 ioloop->next_io_file = io->next; |
0 | 179 |
3483
84a4f150bd00
data -> context/ctx naming convention replaces
Timo Sirainen <tss@iki.fi>
parents:
3298
diff
changeset
|
180 pollfd = &ctx->fds[ctx->fd_index[io->fd]]; |
1499
e850252cdc7e
Removed I/O priorities. They were pretty much useless and were just getting
Timo Sirainen <tss@iki.fi>
parents:
1497
diff
changeset
|
181 if (pollfd->revents != 0) { |
e850252cdc7e
Removed I/O priorities. They were pretty much useless and were just getting
Timo Sirainen <tss@iki.fi>
parents:
1497
diff
changeset
|
182 if (pollfd->revents & POLLNVAL) { |
e850252cdc7e
Removed I/O priorities. They were pretty much useless and were just getting
Timo Sirainen <tss@iki.fi>
parents:
1497
diff
changeset
|
183 i_error("invalid I/O fd %d, callback %p", |
5248
12ac5f685814
Various cleanups to ioloop code.
Timo Sirainen <tss@iki.fi>
parents:
4971
diff
changeset
|
184 io->fd, (void *) io->io.callback); |
4971
0c93af60fa9d
If we get POLLNVAL, disable events completely for the io so we don't just loop forever.
Timo Sirainen <tss@iki.fi>
parents:
4573
diff
changeset
|
185 pollfd->events = 0; |
1504 | 186 pollfd->revents = 0; |
3298
ed7e4f7a2315
If we get POLLNVAL, call the callback anyway so it hopefully gets rid of the
Timo Sirainen <tss@iki.fi>
parents:
2569
diff
changeset
|
187 call = TRUE; |
5248
12ac5f685814
Various cleanups to ioloop code.
Timo Sirainen <tss@iki.fi>
parents:
4971
diff
changeset
|
188 } else if ((io->io.condition & |
1499
e850252cdc7e
Removed I/O priorities. They were pretty much useless and were just getting
Timo Sirainen <tss@iki.fi>
parents:
1497
diff
changeset
|
189 (IO_READ|IO_WRITE)) == (IO_READ|IO_WRITE)) { |
e850252cdc7e
Removed I/O priorities. They were pretty much useless and were just getting
Timo Sirainen <tss@iki.fi>
parents:
1497
diff
changeset
|
190 call = TRUE; |
e850252cdc7e
Removed I/O priorities. They were pretty much useless and were just getting
Timo Sirainen <tss@iki.fi>
parents:
1497
diff
changeset
|
191 pollfd->revents = 0; |
22161
f9c89c5172a5
-Wstrict-bool warning fixes
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22140
diff
changeset
|
192 } else if ((io->io.condition & IO_READ) != 0) { |
1499
e850252cdc7e
Removed I/O priorities. They were pretty much useless and were just getting
Timo Sirainen <tss@iki.fi>
parents:
1497
diff
changeset
|
193 call = (pollfd->revents & IO_POLL_INPUT) != 0; |
e850252cdc7e
Removed I/O priorities. They were pretty much useless and were just getting
Timo Sirainen <tss@iki.fi>
parents:
1497
diff
changeset
|
194 pollfd->revents &= ~IO_POLL_INPUT; |
22161
f9c89c5172a5
-Wstrict-bool warning fixes
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22140
diff
changeset
|
195 } else if ((io->io.condition & IO_WRITE) != 0) { |
1499
e850252cdc7e
Removed I/O priorities. They were pretty much useless and were just getting
Timo Sirainen <tss@iki.fi>
parents:
1497
diff
changeset
|
196 call = (pollfd->revents & IO_POLL_OUTPUT) != 0; |
e850252cdc7e
Removed I/O priorities. They were pretty much useless and were just getting
Timo Sirainen <tss@iki.fi>
parents:
1497
diff
changeset
|
197 pollfd->revents &= ~IO_POLL_OUTPUT; |
22161
f9c89c5172a5
-Wstrict-bool warning fixes
Timo Sirainen <timo.sirainen@dovecot.fi>
parents:
22140
diff
changeset
|
198 } else if ((io->io.condition & IO_ERROR) != 0) { |
3613
c4c1b538d8d0
Added IO_ERROR condition that we can watch now.
Timo Sirainen <tss@iki.fi>
parents:
3527
diff
changeset
|
199 call = (pollfd->revents & IO_POLL_ERROR) != 0; |
c4c1b538d8d0
Added IO_ERROR condition that we can watch now.
Timo Sirainen <tss@iki.fi>
parents:
3527
diff
changeset
|
200 pollfd->revents &= ~IO_POLL_ERROR; |
1503 | 201 } else { |
202 call = FALSE; | |
1499
e850252cdc7e
Removed I/O priorities. They were pretty much useless and were just getting
Timo Sirainen <tss@iki.fi>
parents:
1497
diff
changeset
|
203 } |
e850252cdc7e
Removed I/O priorities. They were pretty much useless and were just getting
Timo Sirainen <tss@iki.fi>
parents:
1497
diff
changeset
|
204 |
1504 | 205 if (pollfd->revents == 0) |
206 ret--; | |
207 | |
12497
1bac1c09201a
ioloop: Added support for per-io/timeout callback log prefix automation.
Timo Sirainen <tss@iki.fi>
parents:
12129
diff
changeset
|
208 if (call) |
1bac1c09201a
ioloop: Added support for per-io/timeout callback log prefix automation.
Timo Sirainen <tss@iki.fi>
parents:
12129
diff
changeset
|
209 io_loop_call_io(&io->io); |
0 | 210 } |
211 } | |
212 } | |
676
3e23fa94f762
select() support was broken. Also changed the way it's built.
Timo Sirainen <tss@iki.fi>
parents:
536
diff
changeset
|
213 |
3e23fa94f762
select() support was broken. Also changed the way it's built.
Timo Sirainen <tss@iki.fi>
parents:
536
diff
changeset
|
214 #endif |