Mercurial > hg > nginx
comparison src/event/modules/ngx_epoll_module.c @ 4129:6903dac6ad19
Fixing Linux AIO syscalls return value handling:
syscall(2) uses usual libc convention, it returns -1 on error and
sets errno. Obsolete _syscall(2) returns negative value of error.
Thanks to Hagai Avrahami.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 16 Sep 2011 12:43:16 +0000 |
parents | 159b58f9c0bd |
children | 04751572f900 |
comparison
equal
deleted
inserted
replaced
4128:4b0b0e77dc3d | 4129:6903dac6ad19 |
---|---|
182 * Also we do not use eventfd() in glibc, because glibc supports it | 182 * Also we do not use eventfd() in glibc, because glibc supports it |
183 * since 2.8 version and glibc maps two syscalls eventfd() and eventfd2() | 183 * since 2.8 version and glibc maps two syscalls eventfd() and eventfd2() |
184 * into single eventfd() function with different number of parameters. | 184 * into single eventfd() function with different number of parameters. |
185 */ | 185 */ |
186 | 186 |
187 static long | 187 static int |
188 io_setup(u_int nr_reqs, aio_context_t *ctx) | 188 io_setup(u_int nr_reqs, aio_context_t *ctx) |
189 { | 189 { |
190 return syscall(SYS_io_setup, nr_reqs, ctx); | 190 return syscall(SYS_io_setup, nr_reqs, ctx); |
191 } | 191 } |
192 | 192 |
196 { | 196 { |
197 return syscall(SYS_io_destroy, ctx); | 197 return syscall(SYS_io_destroy, ctx); |
198 } | 198 } |
199 | 199 |
200 | 200 |
201 static long | 201 static int |
202 io_getevents(aio_context_t ctx, long min_nr, long nr, struct io_event *events, | 202 io_getevents(aio_context_t ctx, long min_nr, long nr, struct io_event *events, |
203 struct timespec *tmo) | 203 struct timespec *tmo) |
204 { | 204 { |
205 return syscall(SYS_io_getevents, ctx, min_nr, nr, events, tmo); | 205 return syscall(SYS_io_getevents, ctx, min_nr, nr, events, tmo); |
206 } | 206 } |
245 } | 245 } |
246 | 246 |
247 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, | 247 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
248 "eventfd: %d", ngx_eventfd); | 248 "eventfd: %d", ngx_eventfd); |
249 | 249 |
250 n = io_setup(1024, &ngx_aio_ctx); | 250 if (io_setup(1024, &ngx_aio_ctx) == -1) { |
251 | 251 |
252 if (n != 0) { | 252 ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno, |
253 ngx_log_error(NGX_LOG_EMERG, cycle->log, -n, "io_setup() failed"); | 253 "io_setup() failed"); |
254 return NGX_ERROR; | 254 return NGX_ERROR; |
255 } | 255 } |
256 | 256 |
257 ngx_eventfd_event.data = &ngx_eventfd_conn; | 257 ngx_eventfd_event.data = &ngx_eventfd_conn; |
258 ngx_eventfd_event.handler = ngx_epoll_eventfd_handler; | 258 ngx_eventfd_event.handler = ngx_epoll_eventfd_handler; |
314 | 314 |
315 ep = -1; | 315 ep = -1; |
316 | 316 |
317 #if (NGX_HAVE_FILE_AIO) | 317 #if (NGX_HAVE_FILE_AIO) |
318 | 318 |
319 if (io_destroy(ngx_aio_ctx) != 0) { | 319 if (io_destroy(ngx_aio_ctx) == -1) { |
320 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, | 320 ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno, |
321 "io_destroy() failed"); | 321 "io_destroy() failed"); |
322 } | 322 } |
323 | 323 |
324 ngx_aio_ctx = 0; | 324 ngx_aio_ctx = 0; |
665 #if (NGX_HAVE_FILE_AIO) | 665 #if (NGX_HAVE_FILE_AIO) |
666 | 666 |
667 static void | 667 static void |
668 ngx_epoll_eventfd_handler(ngx_event_t *ev) | 668 ngx_epoll_eventfd_handler(ngx_event_t *ev) |
669 { | 669 { |
670 int n; | 670 int n, events; |
671 long i, events; | 671 long i; |
672 uint64_t ready; | 672 uint64_t ready; |
673 ngx_err_t err; | 673 ngx_err_t err; |
674 ngx_event_t *e; | 674 ngx_event_t *e; |
675 ngx_event_aio_t *aio; | 675 ngx_event_aio_t *aio; |
676 struct io_event event[64]; | 676 struct io_event event[64]; |
736 | 736 |
737 if (events == 0) { | 737 if (events == 0) { |
738 return; | 738 return; |
739 } | 739 } |
740 | 740 |
741 /* events < 0 */ | 741 /* events == -1 */ |
742 ngx_log_error(NGX_LOG_ALERT, ev->log, -events, "io_getevents() failed"); | 742 ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno, |
743 "io_getevents() failed"); | |
743 return; | 744 return; |
744 } | 745 } |
745 } | 746 } |
746 | 747 |
747 #endif | 748 #endif |