Browse Source

[core] isolate backend fdevent handler defs

personal/stbuehler/1.4.48-mod-proxy-fix
Glenn Strauss 4 years ago
parent
commit
8f3bbd7f13
  1. 2
      src/Makefile.am
  2. 65
      src/configfile.c
  3. 147
      src/fdevent.c
  4. 176
      src/fdevent.h
  5. 3
      src/fdevent_freebsd_kqueue.c
  6. 156
      src/fdevent_impl.h
  7. 3
      src/fdevent_libev.c
  8. 3
      src/fdevent_linux_sysepoll.c
  9. 3
      src/fdevent_poll.c
  10. 3
      src/fdevent_select.c
  11. 3
      src/fdevent_solaris_devpoll.c
  12. 3
      src/fdevent_solaris_port.c
  13. 36
      src/mod_status.c
  14. 66
      src/server.c

2
src/Makefile.am

@ -382,7 +382,7 @@ hdr = server.h base64.h buffer.h network.h log.h keyvalue.h \
fdevent.h gw_backend.h connections.h base.h base_decls.h stat_cache.h \
plugin.h \
etag.h joblist.h array.h vector.h crc32.h \
network_write.h configfile.h \
fdevent_impl.h network_write.h configfile.h \
mod_ssi.h mod_ssi_expr.h inet_ntop_cache.h \
configparser.h mod_ssi_exprparser.h \
rand.h \

65
src/configfile.c

@ -1370,35 +1370,7 @@ int config_set_defaults(server *srv) {
specific_config *s = srv->config_storage[0];
struct stat st1, st2;
struct ev_map { fdevent_handler_t et; const char *name; } event_handlers[] =
{
/* - epoll is most reliable
* - select works everywhere
*/
#ifdef USE_LINUX_EPOLL
{ FDEVENT_HANDLER_LINUX_SYSEPOLL, "linux-sysepoll" },
#endif
#ifdef USE_POLL
{ FDEVENT_HANDLER_POLL, "poll" },
#endif
#ifdef USE_SELECT
{ FDEVENT_HANDLER_SELECT, "select" },
#endif
#ifdef USE_LIBEV
{ FDEVENT_HANDLER_LIBEV, "libev" },
#endif
#ifdef USE_SOLARIS_DEVPOLL
{ FDEVENT_HANDLER_SOLARIS_DEVPOLL,"solaris-devpoll" },
#endif
#ifdef USE_SOLARIS_PORT
{ FDEVENT_HANDLER_SOLARIS_PORT, "solaris-eventports" },
#endif
#ifdef USE_FREEBSD_KQUEUE
{ FDEVENT_HANDLER_FREEBSD_KQUEUE, "freebsd-kqueue" },
{ FDEVENT_HANDLER_FREEBSD_KQUEUE, "kqueue" },
#endif
{ FDEVENT_HANDLER_UNSET, NULL }
};
if (0 != fdevent_config(srv)) return -1;
if (!buffer_string_is_empty(srv->srvconf.changeroot)) {
if (-1 == stat(srv->srvconf.changeroot->ptr, &st1)) {
@ -1502,40 +1474,5 @@ int config_set_defaults(server *srv) {
srv->srvconf.port = s->ssl_enabled ? 443 : 80;
}
if (buffer_string_is_empty(srv->srvconf.event_handler)) {
/* choose a good default
*
* the event_handler list is sorted by 'goodness'
* taking the first available should be the best solution
*/
srv->event_handler = event_handlers[0].et;
if (FDEVENT_HANDLER_UNSET == srv->event_handler) {
log_error_write(srv, __FILE__, __LINE__, "s",
"sorry, there is no event handler for this system");
return -1;
}
} else {
/*
* User override
*/
for (i = 0; event_handlers[i].name; i++) {
if (0 == strcmp(event_handlers[i].name, srv->srvconf.event_handler->ptr)) {
srv->event_handler = event_handlers[i].et;
break;
}
}
if (FDEVENT_HANDLER_UNSET == srv->event_handler) {
log_error_write(srv, __FILE__, __LINE__, "sb",
"the selected event-handler in unknown or not supported:",
srv->srvconf.event_handler );
return -1;
}
}
return 0;
}

147
src/fdevent.c

@ -1,7 +1,8 @@
#include "first.h"
#include "base.h"
#include "fdevent_impl.h"
#include "fdevent.h"
#include "base.h"
#include "buffer.h"
#include "log.h"
@ -20,8 +21,137 @@
static int use_sock_cloexec;
#endif
fdevents *fdevent_init(server *srv, size_t maxfds, int type) {
int fdevent_config(server *srv) {
static const struct ev_map { fdevent_handler_t et; const char *name; } event_handlers[] =
{
/* - epoll is most reliable
* - select works everywhere
*/
#ifdef FDEVENT_USE_LINUX_EPOLL
{ FDEVENT_HANDLER_LINUX_SYSEPOLL, "linux-sysepoll" },
{ FDEVENT_HANDLER_LINUX_SYSEPOLL, "epoll" },
#endif
#ifdef FDEVENT_USE_SOLARIS_PORT
{ FDEVENT_HANDLER_SOLARIS_PORT, "solaris-eventports" },
#endif
#ifdef FDEVENT_USE_SOLARIS_DEVPOLL
{ FDEVENT_HANDLER_SOLARIS_DEVPOLL,"solaris-devpoll" },
#endif
#ifdef FDEVENT_USE_FREEBSD_KQUEUE
{ FDEVENT_HANDLER_FREEBSD_KQUEUE, "freebsd-kqueue" },
{ FDEVENT_HANDLER_FREEBSD_KQUEUE, "kqueue" },
#endif
#ifdef FDEVENT_USE_POLL
{ FDEVENT_HANDLER_POLL, "poll" },
#endif
#ifdef FDEVENT_USE_SELECT
{ FDEVENT_HANDLER_SELECT, "select" },
#endif
#ifdef FDEVENT_USE_LIBEV
{ FDEVENT_HANDLER_LIBEV, "libev" },
#endif
{ FDEVENT_HANDLER_UNSET, NULL }
};
if (buffer_string_is_empty(srv->srvconf.event_handler)) {
/* choose a good default
*
* the event_handler list is sorted by 'goodness'
* taking the first available should be the best solution
*/
srv->event_handler = event_handlers[0].et;
if (FDEVENT_HANDLER_UNSET == srv->event_handler) {
log_error_write(srv, __FILE__, __LINE__, "s",
"sorry, there is no event handler for this system");
return -1;
}
buffer_copy_string(srv->srvconf.event_handler, event_handlers[0].name);
} else {
/*
* User override
*/
for (size_t i = 0; event_handlers[i].name; i++) {
if (0 == strcmp(event_handlers[i].name, srv->srvconf.event_handler->ptr)) {
srv->event_handler = event_handlers[i].et;
break;
}
}
if (FDEVENT_HANDLER_UNSET == srv->event_handler) {
log_error_write(srv, __FILE__, __LINE__, "sb",
"the selected event-handler in unknown or not supported:",
srv->srvconf.event_handler );
return -1;
}
}
#ifdef FDEVENT_USE_SELECT
if (srv->event_handler == FDEVENT_HANDLER_SELECT) {
/* select limits itself
*
* as it is a hard limit and will lead to a segfault we add some safety
* */
srv->max_fds = FD_SETSIZE - 200;
}
else
#endif
{
srv->max_fds = 4096;
}
return 0;
}
const char * fdevent_show_event_handlers(void) {
return
"\nEvent Handlers:\n\n"
#ifdef FDEVENT_USE_SELECT
"\t+ select (generic)\n"
#else
"\t- select (generic)\n"
#endif
#ifdef FDEVENT_USE_POLL
"\t+ poll (Unix)\n"
#else
"\t- poll (Unix)\n"
#endif
#ifdef FDEVENT_USE_LINUX_EPOLL
"\t+ epoll (Linux)\n"
#else
"\t- epoll (Linux)\n"
#endif
#ifdef FDEVENT_USE_SOLARIS_DEVPOLL
"\t+ /dev/poll (Solaris)\n"
#else
"\t- /dev/poll (Solaris)\n"
#endif
#ifdef FDEVENT_USE_SOLARIS_PORT
"\t+ eventports (Solaris)\n"
#else
"\t- eventports (Solaris)\n"
#endif
#ifdef FDEVENT_USE_FREEBSD_KQUEUE
"\t+ kqueue (FreeBSD)\n"
#else
"\t- kqueue (FreeBSD)\n"
#endif
#ifdef FDEVENT_USE_LIBEV
"\t+ libev (generic)\n"
#else
"\t- libev (generic)\n"
#endif
;
}
fdevents *fdevent_init(server *srv) {
fdevents *ev;
int type = srv->event_handler;
size_t maxfds;
#ifdef SOCK_CLOEXEC
/* Test if SOCK_CLOEXEC is supported by kernel.
@ -35,6 +165,15 @@ fdevents *fdevent_init(server *srv, size_t maxfds, int type) {
}
#endif
#ifdef FDEVENT_USE_SELECT
if (type == FDEVENT_HANDLER_SELECT) {
if (srv->max_fds > (int)FD_SETSIZE - 200) {
srv->max_fds = (int)FD_SETSIZE - 200;
}
}
#endif
maxfds = srv->max_fds + 1; /*(+1 for event-handler fd)*/
ev = calloc(1, sizeof(*ev));
force_assert(NULL != ev);
ev->srv = srv;
@ -222,6 +361,10 @@ void fdevent_sched_run(server *srv, fdevents *ev) {
ev->pendclose = NULL;
}
int fdevent_event_get_interest(const fdevents *ev, int fd) {
return fd >= 0 ? ev->fdarray[fd]->events : 0;
}
void fdevent_event_del(fdevents *ev, int *fde_ndx, int fd) {
if (-1 == fd) return;
if ((uintptr_t)ev->fdarray[fd] & 0x3) return;

176
src/fdevent.h

@ -2,61 +2,11 @@
#define _FDEVENT_H_
#include "first.h"
#include "settings.h"
#include "base_decls.h"
#include "settings.h" /* (handler_t) */
#if defined HAVE_STDINT_H
# include <stdint.h>
#elif defined HAVE_INTTYPES_H
# include <inttypes.h>
#endif
#include <sys/types.h>
/* select event-system */
#if defined(HAVE_EPOLL_CTL) && defined(HAVE_SYS_EPOLL_H)
# define USE_LINUX_EPOLL
struct epoll_event; /* declaration */
#endif
/* MacOS 10.3.x has poll.h under /usr/include/, all other unixes
* under /usr/include/sys/ */
#if defined HAVE_POLL && (defined(HAVE_SYS_POLL_H) || defined(HAVE_POLL_H))
# define USE_POLL
struct pollfd; /* declaration */
#endif
#if defined HAVE_SELECT
# ifdef __WIN32
# include <winsock2.h>
# endif
# define USE_SELECT
# ifdef HAVE_SYS_SELECT_H
# include <sys/select.h>
# endif
#endif
#if defined HAVE_SYS_DEVPOLL_H && defined(__sun)
# define USE_SOLARIS_DEVPOLL
struct pollfd; /* declaration */
#endif
#if defined HAVE_PORT_H && defined HAVE_PORT_CREATE && defined(__sun)
# define USE_SOLARIS_PORT
# include <port.h>
#endif
#if defined HAVE_SYS_EVENT_H && defined HAVE_KQUEUE
# define USE_FREEBSD_KQUEUE
struct kevent; /* declaration */
#endif
#if defined HAVE_LIBEV
# define USE_LIBEV
struct ev_loop; /* declaration */
#endif
struct server; /* declaration */
struct fdevents; /* declaration */
typedef struct fdevents fdevents;
typedef handler_t (*fdevent_handler)(struct server *srv, void *ctx, int revents);
@ -77,115 +27,13 @@ typedef handler_t (*fdevent_handler)(struct server *srv, void *ctx, int revents)
#define FDEVENT_STREAM_RESPONSE BV(0)
#define FDEVENT_STREAM_RESPONSE_BUFMIN BV(1)
typedef enum { FD_EVENT_TYPE_UNSET = -1,
FD_EVENT_TYPE_CONNECTION,
FD_EVENT_TYPE_FCGI_CONNECTION,
FD_EVENT_TYPE_DIRWATCH,
FD_EVENT_TYPE_CGI_CONNECTION
} fd_event_t;
typedef enum { FDEVENT_HANDLER_UNSET,
FDEVENT_HANDLER_SELECT,
FDEVENT_HANDLER_POLL,
FDEVENT_HANDLER_LINUX_SYSEPOLL,
FDEVENT_HANDLER_SOLARIS_DEVPOLL,
FDEVENT_HANDLER_SOLARIS_PORT,
FDEVENT_HANDLER_FREEBSD_KQUEUE,
FDEVENT_HANDLER_LIBEV
} fdevent_handler_t;
typedef struct _fdnode {
fdevent_handler handler;
void *ctx;
void *handler_ctx;
int fd;
int events;
} fdnode;
/**
* array of unused fd's
*
*/
typedef struct {
int *ptr;
size_t used;
size_t size;
} buffer_int;
/**
* fd-event handler for select(), poll() and rt-signals on Linux 2.4
*
*/
typedef struct fdevents {
struct server *srv;
fdevent_handler_t type;
fdnode **fdarray;
fdnode *pendclose;
size_t maxfds;
#ifdef USE_LINUX_EPOLL
int epoll_fd;
struct epoll_event *epoll_events;
#endif
#ifdef USE_POLL
struct pollfd *pollfds;
size_t size;
size_t used;
buffer_int unused;
#endif
#ifdef USE_SELECT
fd_set select_read;
fd_set select_write;
fd_set select_error;
fd_set select_set_read;
fd_set select_set_write;
fd_set select_set_error;
int select_max_fd;
#endif
#ifdef USE_SOLARIS_DEVPOLL
int devpoll_fd;
struct pollfd *devpollfds;
#endif
#ifdef USE_SOLARIS_PORT
port_event_t *port_events;
#endif
#ifdef USE_FREEBSD_KQUEUE
int kq_fd;
struct kevent *kq_results;
#endif
#ifdef USE_SOLARIS_PORT
int port_fd;
#endif
#ifdef USE_LIBEV
struct ev_loop *libev_loop;
#endif
int (*reset)(struct fdevents *ev);
void (*free)(struct fdevents *ev);
int (*event_set)(struct fdevents *ev, int fde_ndx, int fd, int events);
int (*event_del)(struct fdevents *ev, int fde_ndx, int fd);
int (*event_get_revent)(struct fdevents *ev, size_t ndx);
int (*event_get_fd)(struct fdevents *ev, size_t ndx);
int (*event_next_fdndx)(struct fdevents *ev, int ndx);
int (*poll)(struct fdevents *ev, int timeout_ms);
} fdevents;
fdevents *fdevent_init(struct server *srv, size_t maxfds, int type);
int fdevent_config(server *srv);
const char * fdevent_show_event_handlers(void);
fdevents *fdevent_init(struct server *srv);
int fdevent_reset(fdevents *ev); /* "init" after fork() */
void fdevent_free(fdevents *ev);
#define fdevent_event_get_interest(ev, fd) \
((fd) >= 0 ? (ev)->fdarray[(fd)]->events : 0)
int fdevent_event_get_interest(const fdevents *ev, int fd);
void fdevent_event_set(fdevents *ev, int *fde_ndx, int fd, int events); /* events can be FDEVENT_IN, FDEVENT_OUT or FDEVENT_IN | FDEVENT_OUT */
void fdevent_event_add(fdevents *ev, int *fde_ndx, int fd, int event); /* events can be FDEVENT_IN or FDEVENT_OUT */
void fdevent_event_clr(fdevents *ev, int *fde_ndx, int fd, int event); /* events can be FDEVENT_IN or FDEVENT_OUT */
@ -229,14 +77,6 @@ void fdevent_close_logger_pipes(void);
void fdevent_breakagelog_logger_pipe(int fd);
void fdevent_clr_logger_pipe_pids(void);
int fdevent_select_init(fdevents *ev);
int fdevent_poll_init(fdevents *ev);
int fdevent_linux_sysepoll_init(fdevents *ev);
int fdevent_solaris_devpoll_init(fdevents *ev);
int fdevent_solaris_port_init(fdevents *ev);
int fdevent_freebsd_kqueue_init(fdevents *ev);
int fdevent_libev_init(fdevents *ev);
int fdevent_ioctl_fionread (int fd, int fdfmt, int *toread);
int fdevent_connect_status(int fd);

3
src/fdevent_freebsd_kqueue.c

@ -1,5 +1,6 @@
#include "first.h"
#include "fdevent_impl.h"
#include "fdevent.h"
#include "buffer.h"
#include "log.h"
@ -12,7 +13,7 @@
#include <errno.h>
#include <fcntl.h>
#ifdef USE_FREEBSD_KQUEUE
#ifdef FDEVENT_USE_FREEBSD_KQUEUE
# include <sys/event.h>
# include <sys/time.h>

156
src/fdevent_impl.h

@ -0,0 +1,156 @@
#ifndef INCLUDED_FDEVENT_IMPL_H
#define INCLUDED_FDEVENT_IMPL_H
#include "first.h"
/* select event-system */
#if defined(HAVE_EPOLL_CTL) && defined(HAVE_SYS_EPOLL_H)
# define FDEVENT_USE_LINUX_EPOLL
struct epoll_event; /* declaration */
#endif
/* MacOS 10.3.x has poll.h under /usr/include/, all other unixes
* under /usr/include/sys/ */
#if defined HAVE_POLL && (defined(HAVE_SYS_POLL_H) || defined(HAVE_POLL_H))
# define FDEVENT_USE_POLL
struct pollfd; /* declaration */
#endif
#if defined HAVE_SELECT
# ifdef __WIN32
# include <winsock2.h>
# endif
# define FDEVENT_USE_SELECT
# ifdef HAVE_SYS_SELECT_H
# include <sys/select.h>
# endif
#endif
#if defined HAVE_SYS_DEVPOLL_H && defined(__sun)
# define FDEVENT_USE_SOLARIS_DEVPOLL
struct pollfd; /* declaration */
#endif
#if defined HAVE_PORT_H && defined HAVE_PORT_CREATE && defined(__sun)
# define FDEVENT_USE_SOLARIS_PORT
# include <port.h>
#endif
#if defined HAVE_SYS_EVENT_H && defined HAVE_KQUEUE
# define FDEVENT_USE_FREEBSD_KQUEUE
struct kevent; /* declaration */
#endif
#if defined HAVE_LIBEV
# define FDEVENT_USE_LIBEV
struct ev_loop; /* declaration */
#endif
#include "base_decls.h"
#include "settings.h" /* (handler_t) */
typedef enum {
FDEVENT_HANDLER_UNSET,
FDEVENT_HANDLER_SELECT,
FDEVENT_HANDLER_POLL,
FDEVENT_HANDLER_LINUX_SYSEPOLL,
FDEVENT_HANDLER_SOLARIS_DEVPOLL,
FDEVENT_HANDLER_SOLARIS_PORT,
FDEVENT_HANDLER_FREEBSD_KQUEUE,
FDEVENT_HANDLER_LIBEV
} fdevent_handler_t;
typedef handler_t (*fdevent_handler)(struct server *srv, void *ctx, int revents);
typedef struct _fdnode {
fdevent_handler handler;
void *ctx;
void *handler_ctx;
int fd;
int events;
} fdnode;
/**
* array of unused fd's
*
*/
#ifdef FDEVENT_USE_POLL
typedef struct {
int *ptr;
size_t used;
size_t size;
} buffer_int;
#endif
struct fdevents {
struct server *srv;
fdevent_handler_t type;
fdnode **fdarray;
fdnode *pendclose;
size_t maxfds;
#ifdef FDEVENT_USE_LINUX_EPOLL
int epoll_fd;
struct epoll_event *epoll_events;
#endif
#ifdef FDEVENT_USE_POLL
struct pollfd *pollfds;
size_t size;
size_t used;
buffer_int unused;
#endif
#ifdef FDEVENT_USE_SELECT
fd_set select_read;
fd_set select_write;
fd_set select_error;
fd_set select_set_read;
fd_set select_set_write;
fd_set select_set_error;
int select_max_fd;
#endif
#ifdef FDEVENT_USE_SOLARIS_DEVPOLL
int devpoll_fd;
struct pollfd *devpollfds;
#endif
#ifdef FDEVENT_USE_SOLARIS_PORT
port_event_t *port_events;
#endif
#ifdef FDEVENT_USE_FREEBSD_KQUEUE
int kq_fd;
struct kevent *kq_results;
#endif
#ifdef FDEVENT_USE_SOLARIS_PORT
int port_fd;
#endif
#ifdef FDEVENT_USE_LIBEV
struct ev_loop *libev_loop;
#endif
int (*reset)(struct fdevents *ev);
void (*free)(struct fdevents *ev);
int (*event_set)(struct fdevents *ev, int fde_ndx, int fd, int events);
int (*event_del)(struct fdevents *ev, int fde_ndx, int fd);
int (*event_get_revent)(struct fdevents *ev, size_t ndx);
int (*event_get_fd)(struct fdevents *ev, size_t ndx);
int (*event_next_fdndx)(struct fdevents *ev, int ndx);
int (*poll)(struct fdevents *ev, int timeout_ms);
};
int fdevent_select_init(struct fdevents *ev);
int fdevent_poll_init(struct fdevents *ev);
int fdevent_linux_sysepoll_init(struct fdevents *ev);
int fdevent_solaris_devpoll_init(struct fdevents *ev);
int fdevent_solaris_port_init(struct fdevents *ev);
int fdevent_freebsd_kqueue_init(struct fdevents *ev);
int fdevent_libev_init(struct fdevents *ev);
#endif

3
src/fdevent_libev.c

@ -2,11 +2,12 @@
#include <stdlib.h>
#include "fdevent_impl.h"
#include "fdevent.h"
#include "buffer.h"
#include "log.h"
#ifdef USE_LIBEV
#ifdef FDEVENT_USE_LIBEV
# include <ev.h>

3
src/fdevent_linux_sysepoll.c

@ -1,5 +1,6 @@
#include "first.h"
#include "fdevent_impl.h"
#include "fdevent.h"
#include "buffer.h"
#include "log.h"
@ -11,7 +12,7 @@
#include <string.h>
#include <errno.h>
#ifdef USE_LINUX_EPOLL
#ifdef FDEVENT_USE_LINUX_EPOLL
# include <sys/epoll.h>

3
src/fdevent_poll.c

@ -1,5 +1,6 @@
#include "first.h"
#include "fdevent_impl.h"
#include "fdevent.h"
#include "buffer.h"
#include "log.h"
@ -11,7 +12,7 @@
#include <string.h>
#include <errno.h>
#ifdef USE_POLL
#ifdef FDEVENT_USE_POLL
# ifdef HAVE_POLL_H
# include <poll.h>

3
src/fdevent_select.c

@ -1,5 +1,6 @@
#include "first.h"
#include "fdevent_impl.h"
#include "fdevent.h"
#include "buffer.h"
#include "log.h"
@ -12,7 +13,7 @@
#include <string.h>
#include <errno.h>
#ifdef USE_SELECT
#ifdef FDEVENT_USE_SELECT
static int fdevent_select_reset(fdevents *ev) {
FD_ZERO(&(ev->select_set_read));

3
src/fdevent_solaris_devpoll.c

@ -1,5 +1,6 @@
#include "first.h"
#include "fdevent_impl.h"
#include "fdevent.h"
#include "buffer.h"
#include "log.h"
@ -12,7 +13,7 @@
#include <errno.h>
#include <fcntl.h>
#ifdef USE_SOLARIS_DEVPOLL
#ifdef FDEVENT_USE_SOLARIS_DEVPOLL
# include <sys/devpoll.h>
# include <sys/ioctl.h>

3
src/fdevent_solaris_port.c

@ -1,5 +1,6 @@
#include "first.h"
#include "fdevent_impl.h"
#include "fdevent.h"
#include "buffer.h"
#include "log.h"
@ -12,7 +13,7 @@
#include <errno.h>
#include <fcntl.h>
#ifdef USE_SOLARIS_PORT
#ifdef FDEVENT_USE_SOLARIS_PORT
static const int SOLARIS_PORT_POLL_READ = POLLIN;
static const int SOLARIS_PORT_POLL_WRITE = POLLOUT;

36
src/mod_status.c

@ -803,35 +803,6 @@ static handler_t mod_status_handle_server_config(server *srv, connection *con, v
buffer *m = p->module_list;
size_t i;
struct ev_map { int et; const char *name; } event_handlers[] =
{
/* - epoll is most reliable
* - select works everywhere
*/
#ifdef USE_LINUX_EPOLL
{ FDEVENT_HANDLER_LINUX_SYSEPOLL, "linux-sysepoll" },
#endif
#ifdef USE_POLL
{ FDEVENT_HANDLER_POLL, "poll" },
#endif
#ifdef USE_SELECT
{ FDEVENT_HANDLER_SELECT, "select" },
#endif
#ifdef USE_LIBEV
{ FDEVENT_HANDLER_LIBEV, "libev" },
#endif
#ifdef USE_SOLARIS_DEVPOLL
{ FDEVENT_HANDLER_SOLARIS_DEVPOLL,"solaris-devpoll" },
#endif
#ifdef USE_SOLARIS_PORT
{ FDEVENT_HANDLER_SOLARIS_PORT, "solaris-eventports" },
#endif
#ifdef USE_FREEBSD_KQUEUE
{ FDEVENT_HANDLER_FREEBSD_KQUEUE, "freebsd-kqueue" },
#endif
{ FDEVENT_HANDLER_UNSET, NULL }
};
buffer_copy_string_len(b, CONST_STR_LEN(
"<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n"
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n"
@ -855,12 +826,7 @@ static handler_t mod_status_handle_server_config(server *srv, connection *con, v
#endif
mod_status_header_append(b, "Network Engine");
for (i = 0; event_handlers[i].name; i++) {
if (event_handlers[i].et == srv->event_handler) {
mod_status_row_append(b, "fd-Event-Handler", event_handlers[i].name);
break;
}
}
mod_status_row_append(b, "fd-Event-Handler", srv->srvconf.event_handler->ptr);
mod_status_header_append(b, "Config-File-Settings");

66
src/server.c

@ -524,45 +524,6 @@ static void show_version (void) {
}
static void show_features (void) {
static const char event_handlers[] = ""
"\nEvent Handlers:\n\n"
#ifdef USE_SELECT
"\t+ select (generic)\n"
#else
"\t- select (generic)\n"
#endif
#ifdef USE_POLL
"\t+ poll (Unix)\n"
#else
"\t- poll (Unix)\n"
#endif
#ifdef USE_LINUX_EPOLL
"\t+ epoll (Linux 2.6)\n"
#else
"\t- epoll (Linux 2.6)\n"
#endif
#ifdef USE_SOLARIS_DEVPOLL
"\t+ /dev/poll (Solaris)\n"
#else
"\t- /dev/poll (Solaris)\n"
#endif
#ifdef USE_SOLARIS_PORT
"\t+ eventports (Solaris)\n"
#else
"\t- eventports (Solaris)\n"
#endif
#ifdef USE_FREEBSD_KQUEUE
"\t+ kqueue (FreeBSD)\n"
#else
"\t- kqueue (FreeBSD)\n"
#endif
#ifdef USE_LIBEV
"\t+ libev (generic)\n"
#else
"\t- libev (generic)\n"
#endif
;
static const char features[] =
"\nFeatures:\n\n"
#ifdef HAVE_IPV6
@ -652,7 +613,7 @@ static void show_features (void) {
#endif
;
show_version();
printf("%s%s%s\n", event_handlers, network_write_show_handlers(), features);
printf("%s%s%s\n", fdevent_show_event_handlers(), network_write_show_handlers(), features);
}
static void show_help (void) {
@ -1217,16 +1178,6 @@ static int server_main (server * const srv, int argc, char **argv) {
}
}
if (srv->event_handler == FDEVENT_HANDLER_SELECT) {
/* select limits itself
*
* as it is a hard limit and will lead to a segfault we add some safety
* */
srv->max_fds = FD_SETSIZE - 200;
} else {
srv->max_fds = 4096;
}
{
#ifdef HAVE_GETRLIMIT
struct rlimit rlim;
@ -1260,14 +1211,10 @@ static int server_main (server * const srv, int argc, char **argv) {
}
}
if (srv->event_handler == FDEVENT_HANDLER_SELECT) {
srv->max_fds = rlim.rlim_cur < (rlim_t)FD_SETSIZE - 200 ? (int)rlim.rlim_cur : (int)FD_SETSIZE - 200;
} else {
srv->max_fds = rlim.rlim_cur;
/*(default upper limit of 4k if server.max-fds not specified)*/
if (i_am_root && 0 == srv->srvconf.max_fds && rlim.rlim_cur > 4096)
srv->max_fds = 4096;
}
/* set core file rlimit, if enable_cores is set */
if (use_rlimit && srv->srvconf.enable_cores && getrlimit(RLIMIT_CORE, &rlim) == 0) {
@ -1275,15 +1222,6 @@ static int server_main (server * const srv, int argc, char **argv) {
setrlimit(RLIMIT_CORE, &rlim);
}
#endif
if (srv->event_handler == FDEVENT_HANDLER_SELECT) {
/* don't raise the limit above FD_SET_SIZE */
if (srv->max_fds > ((int)FD_SETSIZE) - 200) {
log_error_write(srv, __FILE__, __LINE__, "sd",
"can't raise max filedescriptors above", FD_SETSIZE - 200,
"if event-handler is 'select'. Use 'poll' or something else or reduce server.max-fds.");
return -1;
}
}
}
/* we need root-perms for port < 1024 */
@ -1675,7 +1613,7 @@ static int server_main (server * const srv, int argc, char **argv) {
}
#endif
if (NULL == (srv->ev = fdevent_init(srv, srv->max_fds + 1, srv->event_handler))) {
if (NULL == (srv->ev = fdevent_init(srv))) {
log_error_write(srv, __FILE__, __LINE__,
"s", "fdevent_init failed");
return -1;

Loading…
Cancel
Save