version 1.1.1.1, 2013/10/14 10:32:47
|
version 1.1.1.2, 2014/06/15 20:20:06
|
Line 23 fdevents *fdevent_init(server *srv, size_t maxfds, fde
|
Line 23 fdevents *fdevent_init(server *srv, size_t maxfds, fde
|
switch(type) { |
switch(type) { |
case FDEVENT_HANDLER_POLL: |
case FDEVENT_HANDLER_POLL: |
if (0 != fdevent_poll_init(ev)) { |
if (0 != fdevent_poll_init(ev)) { |
log_error_write(ev->srv, __FILE__, __LINE__, "S", | log_error_write(srv, __FILE__, __LINE__, "S", |
"event-handler poll failed"); |
"event-handler poll failed"); |
| goto error; |
return NULL; | |
} |
} |
return ev; |
return ev; |
case FDEVENT_HANDLER_SELECT: |
case FDEVENT_HANDLER_SELECT: |
if (0 != fdevent_select_init(ev)) { |
if (0 != fdevent_select_init(ev)) { |
log_error_write(ev->srv, __FILE__, __LINE__, "S", | log_error_write(srv, __FILE__, __LINE__, "S", |
"event-handler select failed"); |
"event-handler select failed"); |
return NULL; | goto error; |
} |
} |
return ev; |
return ev; |
case FDEVENT_HANDLER_LINUX_SYSEPOLL: |
case FDEVENT_HANDLER_LINUX_SYSEPOLL: |
if (0 != fdevent_linux_sysepoll_init(ev)) { |
if (0 != fdevent_linux_sysepoll_init(ev)) { |
log_error_write(ev->srv, __FILE__, __LINE__, "S", | log_error_write(srv, __FILE__, __LINE__, "S", |
"event-handler linux-sysepoll failed, try to set server.event-handler = \"poll\" or \"select\""); |
"event-handler linux-sysepoll failed, try to set server.event-handler = \"poll\" or \"select\""); |
return NULL; | goto error; |
} |
} |
return ev; |
return ev; |
case FDEVENT_HANDLER_SOLARIS_DEVPOLL: |
case FDEVENT_HANDLER_SOLARIS_DEVPOLL: |
if (0 != fdevent_solaris_devpoll_init(ev)) { |
if (0 != fdevent_solaris_devpoll_init(ev)) { |
log_error_write(ev->srv, __FILE__, __LINE__, "S", | log_error_write(srv, __FILE__, __LINE__, "S", |
"event-handler solaris-devpoll failed, try to set server.event-handler = \"poll\" or \"select\""); |
"event-handler solaris-devpoll failed, try to set server.event-handler = \"poll\" or \"select\""); |
return NULL; | goto error; |
} |
} |
return ev; |
return ev; |
case FDEVENT_HANDLER_SOLARIS_PORT: |
case FDEVENT_HANDLER_SOLARIS_PORT: |
if (0 != fdevent_solaris_port_init(ev)) { |
if (0 != fdevent_solaris_port_init(ev)) { |
log_error_write(ev->srv, __FILE__, __LINE__, "S", | log_error_write(srv, __FILE__, __LINE__, "S", |
"event-handler solaris-eventports failed, try to set server.event-handler = \"poll\" or \"select\""); |
"event-handler solaris-eventports failed, try to set server.event-handler = \"poll\" or \"select\""); |
return NULL; | goto error; |
} |
} |
return ev; |
return ev; |
case FDEVENT_HANDLER_FREEBSD_KQUEUE: |
case FDEVENT_HANDLER_FREEBSD_KQUEUE: |
if (0 != fdevent_freebsd_kqueue_init(ev)) { |
if (0 != fdevent_freebsd_kqueue_init(ev)) { |
log_error_write(ev->srv, __FILE__, __LINE__, "S", | log_error_write(srv, __FILE__, __LINE__, "S", |
"event-handler freebsd-kqueue failed, try to set server.event-handler = \"poll\" or \"select\""); |
"event-handler freebsd-kqueue failed, try to set server.event-handler = \"poll\" or \"select\""); |
return NULL; | goto error; |
} |
} |
return ev; |
return ev; |
case FDEVENT_HANDLER_LIBEV: |
case FDEVENT_HANDLER_LIBEV: |
if (0 != fdevent_libev_init(ev)) { |
if (0 != fdevent_libev_init(ev)) { |
log_error_write(ev->srv, __FILE__, __LINE__, "S", | log_error_write(srv, __FILE__, __LINE__, "S", |
"event-handler libev failed, try to set server.event-handler = \"poll\" or \"select\""); |
"event-handler libev failed, try to set server.event-handler = \"poll\" or \"select\""); |
return NULL; | goto error; |
} |
} |
return ev; |
return ev; |
case FDEVENT_HANDLER_UNSET: |
case FDEVENT_HANDLER_UNSET: |
break; |
break; |
} |
} |
|
|
log_error_write(ev->srv, __FILE__, __LINE__, "S", | error: |
| free(ev->fdarray); |
| free(ev); |
| |
| log_error_write(srv, __FILE__, __LINE__, "S", |
"event-handler is unknown, try to set server.event-handler = \"poll\" or \"select\""); |
"event-handler is unknown, try to set server.event-handler = \"poll\" or \"select\""); |
return NULL; |
return NULL; |
} |
} |
Line 133 int fdevent_unregister(fdevents *ev, int fd) {
|
Line 136 int fdevent_unregister(fdevents *ev, int fd) {
|
if (!ev) return 0; |
if (!ev) return 0; |
fdn = ev->fdarray[fd]; |
fdn = ev->fdarray[fd]; |
|
|
assert(fdn->events == 0); | force_assert(fdn->events == 0); |
|
|
fdnode_free(fdn); |
fdnode_free(fdn); |
|
|
Line 197 void * fdevent_get_context(fdevents *ev, int fd) {
|
Line 200 void * fdevent_get_context(fdevents *ev, int fd) {
|
return ev->fdarray[fd]->ctx; |
return ev->fdarray[fd]->ctx; |
} |
} |
|
|
int fdevent_fcntl_set(fdevents *ev, int fd) { | void fd_close_on_exec(int fd) { |
#ifdef FD_CLOEXEC |
#ifdef FD_CLOEXEC |
/* close fd on exec (cgi) */ | if (fd < 0) return; |
fcntl(fd, F_SETFD, FD_CLOEXEC); | force_assert(-1 != fcntl(fd, F_SETFD, FD_CLOEXEC)); |
| #else |
| UNUSED(fd); |
#endif |
#endif |
|
} |
|
|
|
int fdevent_fcntl_set(fdevents *ev, int fd) { |
|
fd_close_on_exec(fd); |
if ((ev) && (ev->fcntl_set)) return ev->fcntl_set(ev, fd); |
if ((ev) && (ev->fcntl_set)) return ev->fcntl_set(ev, fd); |
#ifdef O_NONBLOCK |
#ifdef O_NONBLOCK |
return fcntl(fd, F_SETFL, O_NONBLOCK | O_RDWR); |
return fcntl(fd, F_SETFL, O_NONBLOCK | O_RDWR); |