Browse Source

fdevent: add solaris eventports (fixes #2171)

git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.x@2796 152afb58-edef-0310-8abb-c4023f1b3aa9
svn/tags/lighttpd-1.4.29 lighttpd-1.4.29
Stefan Bühler 11 years ago
parent
commit
f0816d8db2
  1. 1
      NEWS
  2. 2
      configure.ac
  3. 3
      src/Makefile.am
  4. 3
      src/configfile.c
  5. 7
      src/fdevent.c
  6. 15
      src/fdevent.h
  7. 172
      src/fdevent_solaris_port.c
  8. 3
      src/mod_status.c
  9. 5
      src/server.c

1
NEWS

@ -16,6 +16,7 @@ NEWS
* [proc,include_shell] log error if exec shell fails (fixes #2280)
* [*cgi] Use physical base dir (alias, userdir) as DOCUMENT_ROOT in cgi environments (fixes #2216)
* [doc] Move docs to outdated/ subdir and refer to wiki instead (fixes #2248)
* fdevent: add solaris eventports (fixes #2171)
- 1.4.28 - 2010-08-22
* Rename fdevent_event_add to _set to reflect what the function does. Fix some handlers. (fixes #2249)

2
configure.ac

@ -57,7 +57,7 @@ AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS([arpa/inet.h fcntl.h netinet/in.h stdlib.h string.h \
sys/socket.h sys/time.h unistd.h sys/sendfile.h sys/uio.h \
getopt.h sys/epoll.h sys/select.h poll.h sys/poll.h sys/devpoll.h sys/filio.h \
sys/mman.h sys/event.h sys/port.h pwd.h sys/syslimits.h \
sys/mman.h sys/event.h port.h pwd.h sys/syslimits.h \
sys/resource.h sys/un.h syslog.h sys/prctl.h uuid/uuid.h])
dnl Checks for typedefs, structures, and compiler characteristics.

3
src/Makefile.am

@ -64,7 +64,8 @@ common_src=buffer.c log.c \
data_integer.c md5.c data_fastcgi.c \
fdevent_select.c fdevent_libev.c \
fdevent_poll.c fdevent_linux_sysepoll.c \
fdevent_solaris_devpoll.c fdevent_freebsd_kqueue.c \
fdevent_solaris_devpoll.c fdevent_solaris_port.c \
fdevent_freebsd_kqueue.c \
data_config.c bitset.c \
inet_ntop_cache.c crc32.c \
connections-glue.c \

3
src/configfile.c

@ -1212,6 +1212,9 @@ int config_set_defaults(server *srv) {
#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" },

7
src/fdevent.c

@ -50,6 +50,13 @@ fdevents *fdevent_init(server *srv, size_t maxfds, fdevent_handler_t type) {
return NULL;
}
return ev;
case FDEVENT_HANDLER_SOLARIS_PORT:
if (0 != fdevent_solaris_port_init(ev)) {
log_error_write(ev->srv, __FILE__, __LINE__, "S",
"event-handler solaris-eventports failed, try to set server.event-handler = \"poll\" or \"select\"");
return NULL;
}
return ev;
case FDEVENT_HANDLER_FREEBSD_KQUEUE:
if (0 != fdevent_freebsd_kqueue_init(ev)) {
log_error_write(ev->srv, __FILE__, __LINE__, "S",

15
src/fdevent.h

@ -49,16 +49,16 @@
# include <sys/devpoll.h>
#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
# include <sys/event.h>
#endif
#if defined HAVE_SYS_PORT_H && defined HAVE_PORT_CREATE
# define USE_SOLARIS_PORT
# include <sys/port.h>
#endif
#if defined HAVE_LIBEV
# define USE_LIBEV
# include <ev.h>
@ -90,6 +90,7 @@ typedef enum { FDEVENT_HANDLER_UNSET,
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;
@ -153,6 +154,9 @@ typedef struct fdevents {
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;
@ -202,6 +206,7 @@ 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);

172
src/fdevent_solaris_port.c

@ -0,0 +1,172 @@
#include "fdevent.h"
#include "buffer.h"
#include "log.h"
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
#include <fcntl.h>
#ifdef USE_SOLARIS_PORT
static const int SOLARIS_PORT_POLL_READ = POLLIN;
static const int SOLARIS_PORT_POLL_WRITE = POLLOUT;
static const int SOLARIS_PORT_POLL_READ_WRITE = POLLIN & POLLOUT;
static int fdevent_solaris_port_event_del(fdevents *ev, int fde_ndx, int fd) {
if (fde_ndx < 0) return -1;
if (0 != port_dissociate(ev->port_fd, PORT_SOURCE_FD, fd)) {
log_error_write(ev->srv, __FILE__, __LINE__, "SSS",
"port_dissociate failed: ", strerror(errno), ", dying");
SEGFAULT();
return 0;
}
return -1;
}
static int fdevent_solaris_port_event_set(fdevents *ev, int fde_ndx, int fd, int events) {
const int* user_data = NULL;
if ((events & FDEVENT_IN) && (events & FDEVENT_OUT)) {
user_data = &SOLARIS_PORT_POLL_READ_WRITE;
} else if (events & FDEVENT_IN) {
user_data = &SOLARIS_PORT_POLL_READ;
} else if (events & FDEVENT_OUT) {
user_data = &SOLARIS_PORT_POLL_WRITE;
}
if (0 != port_associate(ev->port_fd, PORT_SOURCE_FD, fd, *user_data, (void*) user_data)) {
log_error_write(ev->srv, __FILE__, __LINE__, "SSS",
"port_associate failed: ", strerror(errno), ", dying");
SEGFAULT();
return 0;
}
return fd;
}
static int fdevent_solaris_port_event_get_revent(fdevents *ev, size_t ndx) {
int events = 0, e;
e = ev->port_events[ndx].portev_events;
if (e & POLLIN) events |= FDEVENT_IN;
if (e & POLLOUT) events |= FDEVENT_OUT;
if (e & POLLERR) events |= FDEVENT_ERR;
if (e & POLLHUP) events |= FDEVENT_HUP;
if (e & POLLPRI) events |= FDEVENT_PRI;
if (e & POLLNVAL) events |= FDEVENT_NVAL;
return e;
}
static int fdevent_solaris_port_event_get_fd(fdevents *ev, size_t ndx) {
return ev->port_events[ndx].portev_object;
}
static int fdevent_solaris_port_event_next_fdndx(fdevents *ev, int ndx) {
size_t i;
UNUSED(ev);
i = (ndx < 0) ? 0 : ndx + 1;
return i;
}
static void fdevent_solaris_port_free(fdevents *ev) {
close(ev->port_fd);
free(ev->port_events);
}
/* if there is any error it will return the return values of port_getn, otherwise it will return number of events **/
static int fdevent_solaris_port_poll(fdevents *ev, int timeout_ms) {
int i = 0;
int ret;
unsigned int available_events, wait_for_events = 0;
const int *user_data;
struct timespec timeout;
timeout.tv_sec = timeout_ms/1000L;
timeout.tv_nsec = (timeout_ms % 1000L) * 1000000L;
/* get the number of file descriptors with events */
if ((ret = port_getn(ev->port_fd, ev->port_events, 0, &wait_for_events, &timeout)) < 0) return ret;
/* wait for at least one event */
if (0 == wait_for_events) wait_for_events = 1;
available_events = wait_for_events;
/* get the events of the file descriptors */
if ((ret = port_getn(ev->port_fd, ev->port_events, ev->maxfds, &available_events, &timeout)) < 0) {
/* if errno == ETIME and available_event == wait_for_events we didn't get any events */
/* for other errors we didn't get any events either */
if (!(errno == ETIME && wait_for_events != available_events)) return ret;
}
for (i = 0; i < available_events; ++i) {
user_data = (const int *) ev->port_events[i].portev_user;
if ((ret = port_associate(ev->port_fd, PORT_SOURCE_FD, ev->port_events[i].portev_object,
*user_data, (void*) user_data)) < 0) {
log_error_write(ev->srv, __FILE__, __LINE__, "SSS",
"port_associate failed: ", strerror(errno), ", dying");
SEGFAULT();
return 0;
}
}
return available_events;
}
int fdevent_solaris_port_init(fdevents *ev) {
ev->type = FDEVENT_HANDLER_SOLARIS_PORT;
#define SET(x) \
ev->x = fdevent_solaris_port_##x;
SET(free);
SET(poll);
SET(event_del);
SET(event_set);
SET(event_next_fdndx);
SET(event_get_fd);
SET(event_get_revent);
if ((ev->port_fd = port_create()) < 0) {
log_error_write(ev->srv, __FILE__, __LINE__, "SSS",
"port_create() failed (", strerror(errno), "), try to set server.event-handler = \"poll\" or \"select\"");
return -1;
}
ev->port_events = malloc(ev->maxfds * sizeof(*ev->port_events));
return 0;
}
#else
int fdevent_solaris_port_init(fdevents *ev) {
UNUSED(ev);
log_error_write(ev->srv, __FILE__, __LINE__, "S",
"solaris-eventports not supported, try to set server.event-handler = \"poll\" or \"select\"");
return -1;
}
#endif

3
src/mod_status.c

@ -694,6 +694,9 @@ static handler_t mod_status_handle_server_config(server *srv, connection *con, v
#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

5
src/server.c

@ -393,6 +393,11 @@ static void show_features (void) {
#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

Loading…
Cancel
Save