changeset 260:5dacbb4daaf6

nginx-0.0.2-2004-02-17-20:53:12 import
author Igor Sysoev <igor@sysoev.ru>
date Tue, 17 Feb 2004 17:53:12 +0000
parents d30f2c39caae
children bdd631bf1a1c
files auto/modules auto/options auto/os/freebsd auto/sources src/event/modules/ngx_rtsig_module.c src/event/modules/ngx_sigio_module.c src/event/ngx_event.c src/event/ngx_event_accept.c
diffstat 7 files changed, 132 insertions(+), 173 deletions(-) [+]
line wrap: on
line diff
--- a/auto/modules
+++ b/auto/modules
@@ -1,3 +1,9 @@
+
+if [ $EVENT_RTSIG = YES ]; then
+    have=HAVE_RTSIG . auto/have
+    EVENT_MODULES="$EVENT_MODULES $RTSIG_MODULE"
+    CORE_SRCS="$CORE_SRCS $RTSIG_SRCS"
+fi
 
 if [ $EVENT_SELECT = NO -a $EVENT_FOUND = NO ]; then
     EVENT_SELECT=YES
@@ -20,21 +26,24 @@ fi
 
 
 if [ $TEST_BUILD_DEVPOLL = YES ]; then
-    CFLAGS="$CFLAGS -D HAVE_DEVPOLL=1 -D TEST_BUILD_DEVPOLL=1"
+    have=HAVE_DEVPOLL . auto/have
+    have=TEST_BUILD_DEVPOLL . auto/have
     EVENT_MODULES="$EVENT_MODULES $DEVPOLL_MODULE"
     CORE_SRCS="$CORE_SRCS $DEVPOLL_SRCS"
 fi
 
 if [ $TEST_BUILD_EPOLL = YES ]; then
-    CFLAGS="$CFLAGS -D HAVE_EPOLL=1 -D TEST_BUILD_EPOLL=1"
+    have=HAVE_EPOLL . auto/have
+    have=TEST_BUILD_EPOLL . auto/have
     EVENT_MODULES="$EVENT_MODULES $EPOLL_MODULE"
     CORE_SRCS="$CORE_SRCS $EPOLL_SRCS"
 fi
 
-if [ $TEST_BUILD_SIGIO = YES ]; then
-    CFLAGS="$CFLAGS -D HAVE_SIGIO=1 -D TEST_BUILD_SIGIO=1"
-    EVENT_MODULES="$EVENT_MODULES $SIGIO_MODULE"
-    CORE_SRCS="$CORE_SRCS $SIGIO_SRCS"
+if [ $TEST_BUILD_RTSIG = YES ]; then
+    have=HAVE_RTSIG . auto/have
+    have=TEST_BUILD_RTSIG . auto/have
+    EVENT_MODULES="$EVENT_MODULES $RTSIG_MODULE"
+    CORE_SRCS="$CORE_SRCS $RTSIG_SRCS"
 fi
 
 
--- a/auto/options
+++ b/auto/options
@@ -6,10 +6,11 @@ OBJS=objs
 
 TEST_BUILD_DEVPOLL=NO
 TEST_BUILD_EPOLL=NO
-TEST_BUILD_SIGIO=NO
+TEST_BUILD_RTSIG=NO
 
 EVENT_FOUND=NO
 
+EVENT_RTSIG=NO
 EVENT_SELECT=NO
 EVENT_POLL=NO
 EVENT_AIO=NO
@@ -43,6 +44,7 @@ do
 
         --builddir=*)                    OBJS="$value"              ;;
 
+        --with-rtsig_module)             EVENT_RTSIG=YES            ;;
         --with-select_module)            EVENT_SELECT=YES           ;;
         --without-select_module)         EVENT_SELECT=NONE          ;;
         --with-poll_module)              EVENT_POLL=YES             ;;
@@ -63,7 +65,7 @@ do
 
         --test-build-devpoll)            TEST_BUILD_DEVPOLL=YES     ;;
         --test-build-epoll)              TEST_BUILD_EPOLL=YES       ;;
-        --test-build-sigio)              TEST_BUILD_SIGIO=YES       ;;
+        --test-build-rtsig)              TEST_BUILD_RTSIG=YES       ;;
 
         *)
             echo "$0: error: invalid option \"$option\""
--- a/auto/os/freebsd
+++ b/auto/os/freebsd
@@ -4,6 +4,9 @@ CORE_DEPS="$UNIX_DEPS $FREEBSD_DEPS"
 CORE_SRCS="$UNIX_SRCS $FREEBSD_SRCS"
 
 
+# __FreeBSD_version is the best way to learn when
+# some capability appeared or became safe to use
+
 version=`grep "#define __FreeBSD_version" /usr/include/osreldate.h \
          | sed -e 's/^.* \(.*\)$/\1/'`
 
--- a/auto/sources
+++ b/auto/sources
@@ -76,8 +76,8 @@ DEVPOLL_SRCS=src/event/modules/ngx_devpo
 EPOLL_MODULE=ngx_epoll_module
 EPOLL_SRCS=src/event/modules/ngx_epoll_module.c
 
-SIGIO_MODULE=ngx_sigio_module
-SIGIO_SRCS=src/event/modules/ngx_sigio_module.c
+RTSIG_MODULE=ngx_rtsig_module
+RTSIG_SRCS=src/event/modules/ngx_rtsig_module.c
 
 IOCP_MODULE=ngx_iocp_module
 IOCP_SRCS=src/event/modules/ngx_iocp_module.c
rename from src/event/modules/ngx_sigio_module.c
rename to src/event/modules/ngx_rtsig_module.c
--- a/src/event/modules/ngx_sigio_module.c
+++ b/src/event/modules/ngx_rtsig_module.c
@@ -9,88 +9,101 @@
 #include <ngx_event.h>
 
 
-#if (TEST_BUILD_SIGIO)
+#if (TEST_BUILD_RTSIG)
 
 #define F_SETSIG  10
+#define SIGRTMIN  33
+#define si_fd     __spare__[0]
 
-#define POLL_IN   POLLIN
-#define POLL_OUT  POLLOUT
+int sigwaitinfo(const sigset_t *set, siginfo_t *info);
+
+int sigtimedwait(const sigset_t *set, siginfo_t *info,
+                 const struct timespec *timeout);
+
+int sigwaitinfo(const sigset_t *set, siginfo_t *info)
+{
+    return -1;
+}
+
+int sigtimedwait(const sigset_t *set, siginfo_t *info,
+                 const struct timespec *timeout)
+{
+    return -1;
+}
 
 #endif
 
 
 typedef struct {
     int  signo;
-} ngx_sigio_conf_t;
+} ngx_rtsig_conf_t;
 
 
-static int ngx_sigio_init(ngx_cycle_t *cycle);
-static void ngx_sigio_done(ngx_cycle_t *cycle);
-static int ngx_sigio_add_event(ngx_event_t *ev, int event, u_int flags);
-static int ngx_sigio_del_event(ngx_event_t *ev, int event, u_int flags);
-static int ngx_sigio_add_connection(ngx_connection_t *c);
-static int ngx_sigio_del_connection(ngx_connection_t *c);
-static int ngx_sigio_process_events(ngx_log_t *log);
+static int ngx_rtsig_init(ngx_cycle_t *cycle);
+static void ngx_rtsig_done(ngx_cycle_t *cycle);
+static int ngx_rtsig_add_connection(ngx_connection_t *c);
+static int ngx_rtsig_del_connection(ngx_connection_t *c);
+static int ngx_rtsig_process_events(ngx_log_t *log);
 
-static void *ngx_sigio_create_conf(ngx_cycle_t *cycle);
-static char *ngx_sigio_init_conf(ngx_cycle_t *cycle, void *conf);
+static void *ngx_rtsig_create_conf(ngx_cycle_t *cycle);
+static char *ngx_rtsig_init_conf(ngx_cycle_t *cycle, void *conf);
 
 
 static sigset_t  set;
 
 
-static ngx_str_t      sigio_name = ngx_string("sigio");
+static ngx_str_t      rtsig_name = ngx_string("rtsig");
 
-static ngx_command_t  ngx_sigio_commands[] = {
+static ngx_command_t  ngx_rtsig_commands[] = {
 
-    {ngx_string("sigio_signal"),
+    {ngx_string("rtsig_signo"),
      NGX_EVENT_CONF|NGX_CONF_TAKE1,
      ngx_conf_set_num_slot,
      0,
-     offsetof(ngx_sigio_conf_t, signo),
+     offsetof(ngx_rtsig_conf_t, signo),
      NULL},
 
     ngx_null_command
 };
 
 
-ngx_event_module_t  ngx_sigio_module_ctx = {
-    &sigio_name,
-    ngx_sigio_create_conf,               /* create configuration */
-    ngx_sigio_init_conf,                 /* init configuration */
+ngx_event_module_t  ngx_rtsig_module_ctx = {
+    &rtsig_name,
+    ngx_rtsig_create_conf,               /* create configuration */
+    ngx_rtsig_init_conf,                 /* init configuration */
 
     {
-        ngx_sigio_add_event,             /* add an event */
-        ngx_sigio_del_event,             /* delete an event */
-        ngx_sigio_add_event,             /* enable an event */
-        ngx_sigio_del_event,             /* disable an event */
-        ngx_sigio_add_connection,        /* add an connection */
-        ngx_sigio_del_connection,        /* delete an connection */
-        ngx_sigio_process_events,        /* process the events */
-        ngx_sigio_init,                  /* init the events */
-        ngx_sigio_done,                  /* done the events */
+        NULL,                            /* add an event */
+        NULL,                            /* delete an event */
+        NULL,                            /* enable an event */
+        NULL,                            /* disable an event */
+        ngx_rtsig_add_connection,        /* add an connection */
+        ngx_rtsig_del_connection,        /* delete an connection */
+        ngx_rtsig_process_events,        /* process the events */
+        ngx_rtsig_init,                  /* init the events */
+        ngx_rtsig_done,                  /* done the events */
     }
 
 };
 
-ngx_module_t  ngx_sigio_module = {
+ngx_module_t  ngx_rtsig_module = {
     NGX_MODULE,
-    &ngx_sigio_module_ctx,               /* module context */
-    ngx_sigio_commands,                  /* module directives */
+    &ngx_rtsig_module_ctx,               /* module context */
+    ngx_rtsig_commands,                  /* module directives */
     NGX_EVENT_MODULE,                      /* module type */
     NULL,                                  /* init module */
     NULL                                   /* init child */
 };
 
 
-static int ngx_sigio_init(ngx_cycle_t *cycle)
+static int ngx_rtsig_init(ngx_cycle_t *cycle)
 {
-    ngx_sigio_conf_t  *sgcf;
+    ngx_rtsig_conf_t  *rtscf;
 
-    sgcf = ngx_event_get_conf(cycle->conf_ctx, ngx_sigio_module);
+    rtscf = ngx_event_get_conf(cycle->conf_ctx, ngx_rtsig_module);
 
     sigemptyset(&set);
-    sigaddset(&set, sgcf->signo);
+    sigaddset(&set, rtscf->signo);
     sigaddset(&set, SIGIO);
 
     if (sigprocmask(SIG_BLOCK, &set, NULL) == -1) {
@@ -101,7 +114,7 @@ static int ngx_sigio_init(ngx_cycle_t *c
 
     ngx_io = ngx_os_io;
 
-    ngx_event_actions = ngx_sigio_module_ctx.actions;
+    ngx_event_actions = ngx_rtsig_module_ctx.actions;
 
     ngx_event_flags = NGX_USE_SIGIO_EVENT;
 
@@ -109,45 +122,19 @@ static int ngx_sigio_init(ngx_cycle_t *c
 }
 
 
-static void ngx_sigio_done(ngx_cycle_t *cycle)
+static void ngx_rtsig_done(ngx_cycle_t *cycle)
 {
 }
 
 
-static int ngx_sigio_add_event(ngx_event_t *ev, int event, u_int flags)
+static int ngx_rtsig_add_connection(ngx_connection_t *c)
 {
-    ngx_connection_t    *c;
+    ngx_rtsig_conf_t  *rtscf;
 
-    c = ev->data;
+    rtscf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_rtsig_module);
 
     ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
-                   "sigio add event: fd:%d ev:%04X", c->fd, event);
-
-    return NGX_OK;
-}
-
-
-static int ngx_sigio_del_event(ngx_event_t *ev, int event, u_int flags)
-{
-    ngx_connection_t    *c;
-
-    c = ev->data;
-
-    ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
-                   "sigio del event: fd:%d ev:%04X", c->fd, event);
-
-    return NGX_OK;
-}
-
-
-static int ngx_sigio_add_connection(ngx_connection_t *c)
-{
-    ngx_sigio_conf_t  *sgcf;
-
-    sgcf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_sigio_module);
-
-    ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
-                   "sigio add connection: fd:%d signo:%d", c->fd, sgcf->signo);
+                   "rtsig add connection: fd:%d signo:%d", c->fd, rtscf->signo);
 
     if (fcntl(c->fd, F_SETFL, O_RDWR|O_NONBLOCK|O_ASYNC) == -1) {
         ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno,
@@ -155,7 +142,7 @@ static int ngx_sigio_add_connection(ngx_
         return NGX_ERROR;
     }
 
-    if (fcntl(c->fd, F_SETSIG, sgcf->signo) == -1) {
+    if (fcntl(c->fd, F_SETSIG, rtscf->signo) == -1) {
         ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno,
                       "fcntl(F_SETSIG) failed");
         return NGX_ERROR;
@@ -182,7 +169,7 @@ static int ngx_sigio_add_connection(ngx_
 }
 
 
-static int ngx_sigio_del_connection(ngx_connection_t *c)
+static int ngx_rtsig_del_connection(ngx_connection_t *c)
 {
     c->read->active = 0;
     c->write->active = 0;
@@ -191,7 +178,7 @@ static int ngx_sigio_del_connection(ngx_
 }
 
 
-int ngx_sigio_process_events(ngx_log_t *log)
+int ngx_rtsig_process_events(ngx_log_t *log)
 {
     int                 signo;
     ngx_int_t           instance, i;
@@ -205,7 +192,7 @@ int ngx_sigio_process_events(ngx_log_t *
     struct sigaction    sa;
     ngx_connection_t   *c;
     ngx_epoch_msec_t    delta;
-    ngx_sigio_conf_t   *sgcf;
+    ngx_rtsig_conf_t   *rtscf;
 
     timer = ngx_event_find_timer();
     ngx_old_elapsed_msec = ngx_elapsed_msec;
@@ -215,7 +202,7 @@ int ngx_sigio_process_events(ngx_log_t *
         ts.tv_nsec = (timer % 1000) * 1000000;
     }
 
-    ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0, "sigio timer: %d", timer);
+    ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0, "rtsig timer: %d", timer);
 
     if (timer) {
         signo = sigtimedwait(&set, &si, &ts);
@@ -235,8 +222,9 @@ int ngx_sigio_process_events(ngx_log_t *
     delta = ngx_elapsed_msec;
     ngx_elapsed_msec = tv.tv_sec * 1000 + tv.tv_usec / 1000 - ngx_start_msec;
 
-    if (err == -1) {
-        ngx_log_error(NGX_LOG_ALERT, c->log, err,
+    if (signo == -1) {
+        ngx_log_error((err == NGX_EINTR) ? NGX_LOG_INFO : NGX_LOG_ALERT,
+                      log, err,
                       timer ? "sigtimedwait() failed" : "sigwaitinfo() failed");
         return NGX_ERROR;
     }
@@ -245,46 +233,46 @@ int ngx_sigio_process_events(ngx_log_t *
         delta = ngx_elapsed_msec - delta;
 
         ngx_log_debug2(NGX_LOG_DEBUG_EVENT, log, 0,
-                       "sigio timer: %d, delta: %d", timer, (int) delta);
+                       "rtsig timer: %d, delta: %d", timer, (int) delta);
     }
 
-    sgcf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_sigio_module);
+    ngx_log_debug3(NGX_LOG_DEBUG_EVENT, log, 0,
+                   "signo:%d fd:%d band:%X", signo, si.si_fd, si.si_band);
 
-    if (signo == sgcf->signo) {
+    rtscf = ngx_event_get_conf(ngx_cycle->conf_ctx, ngx_rtsig_module);
 
-        /* STUB: old_cycles */
+    if (signo == rtscf->signo) {
+
+        /* TODO: old_cycles */
         c = &ngx_cycle->connections[si.si_fd];
 
-        if (si.si_band & POLL_IN) {
-            if (!c->read->active) {
-                continue;
+        /* TODO: stale signals */
+
+        if (si.si_band & (POLLIN|POLLHUP|POLLERR)) {
+            if (c->read->active) {
+                c->read->ready = 1;
+                c->read->event_handler(c->read);
             }
-
-            c->read->ready = 1;
-            c->read->event_handler(c->read);
         }
 
-        if (si.si_band & POLL_OUT) {
-            if (!c->read->active) {
-                continue;
+        if (si.si_band & (POLLOUT|POLLHUP|POLLERR)) {
+            if (c->write->active) {
+                c->write->ready = 1;
+                c->write->event_handler(c->write);
             }
-
-            c->read->ready = 1;
-            c->read->event_handler(c->read);
         }
 
     } else if (signo == SIGIO) {
         ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
                       "signal queue overflowed: "
-                      "SIGIO, fd:%d, band:%d", si.si_fd, si.si_band);
+                      "SIGIO, fd:%d, band:%X", si.si_fd, si.si_band);
 
         ngx_memzero(&sa, sizeof(struct sigaction));
-        sa.sa_sigaction = SIG_DFL;
+        sa.sa_handler = SIG_DFL;
         sigemptyset(&sa.sa_mask);
-        if (sigaction(sgcf->signo, &sa, NULL) == -1) {
+        if (sigaction(rtscf->signo, &sa, NULL) == -1) {
             ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
-                          "sigaction queue overflowed: "
-                          "SIGIO, fd:%d, band:%d", si.si_fd, si.si_band);
+                          "sigaction(%d, SIG_DFL) failed", rtscf->signo);
         }
 
     } else {
@@ -292,59 +280,7 @@ int ngx_sigio_process_events(ngx_log_t *
                       timer ?  "sigtimedwait() returned unexpected signal: %d":
                                "sigwaitinfo() returned unexpected signal: %d",
                       signo);
-            return NGX_ERROR;
-        }
-    }
-
-
-
-
-
-
-    for (i = 0; i < events; i++) {
-        c = event_list[i].data.ptr;
-
-        instance = (uintptr_t) c & 1;
-        c = (ngx_connection_t *) ((uintptr_t) c & (uintptr_t) ~1);
-
-        ngx_log_debug3(NGX_LOG_DEBUG_EVENT, log, 0,
-                       "sigio: fd:%d ev:%04X d:" PTR_FMT,
-                       c->fd, event_list[i].events, event_list[i].data);
-
-        if (c->read->instance != instance) {
-
-            /*
-             * it's a stale event from a file descriptor
-             * that was just closed in this iteration
-             */
-
-            ngx_log_debug1(NGX_LOG_DEBUG_EVENT, log, 0,
-                           "sigio: stale event " PTR_FMT, c);
-            continue;
-        }
-
-        if (event_list[i].events & EPOLLOUT) {
-            if (!c->write->active) {
-                continue;
-            }
-
-            c->write->ready = 1;
-            c->write->event_handler(c->write);
-        }
-
-        if (event_list[i].events & (EPOLLERR|EPOLLHUP)) {
-            ngx_log_error(NGX_LOG_ALERT, log, 0,
-                          "sigio_wait() error on fd:%d ev:%d",
-                          c->fd, event_list[i].events);
-            continue;
-        }
-
-        if (event_list[i].events & ~(EPOLLIN|EPOLLOUT)) {
-            ngx_log_error(NGX_LOG_ALERT, log, 0,
-                          "sigio_wait() returned strange events on fd:%d ev:%d",
-                          c->fd, event_list[i].events);
-        }
-
+        return NGX_ERROR;
     }
 
     if (timer != (ngx_msec_t) -1 && delta) {
@@ -355,25 +291,25 @@ int ngx_sigio_process_events(ngx_log_t *
 }
 
 
-static void *ngx_sigio_create_conf(ngx_cycle_t *cycle)
+static void *ngx_rtsig_create_conf(ngx_cycle_t *cycle)
 {
-    ngx_sigio_conf_t  *sgcf;
+    ngx_rtsig_conf_t  *rtscf;
 
-    ngx_test_null(sgcf, ngx_palloc(cycle->pool, sizeof(ngx_sigio_conf_t)),
+    ngx_test_null(rtscf, ngx_palloc(cycle->pool, sizeof(ngx_rtsig_conf_t)),
                   NGX_CONF_ERROR);
 
-    sgcf->events = NGX_CONF_UNSET;
+    rtscf->signo = NGX_CONF_UNSET;
 
-    return epcf;
+    return rtscf;
 }
 
 
-static char *ngx_sigio_init_conf(ngx_cycle_t *cycle, void *conf)
+static char *ngx_rtsig_init_conf(ngx_cycle_t *cycle, void *conf)
 {
-    ngx_sigio_conf_t  *sgcf = conf;
+    ngx_rtsig_conf_t  *rtscf = conf;
 
-    /* LinuxThreads uses the first 3 RT signals */
-    ngx_conf_init_unsigned_value(sgcf->signo, SIGRTMIN + 10);
+    /* LinuxThreads use the first 3 RT signals */
+    ngx_conf_init_value(rtscf->signo, SIGRTMIN + 10);
 
     return NGX_CONF_OK;
 }
--- a/src/event/ngx_event.c
+++ b/src/event/ngx_event.c
@@ -264,7 +264,12 @@ static int ngx_event_init(ngx_cycle_t *c
 #else
 
         rev->event_handler = &ngx_event_accept;
-        ngx_add_event(rev, NGX_READ_EVENT, 0);
+
+        if (ngx_event_flags & NGX_USE_SIGIO_EVENT) {
+            ngx_add_conn(c);
+        } else {
+            ngx_add_event(rev, NGX_READ_EVENT, 0);
+        }
 
 #endif
     }
--- a/src/event/ngx_event_accept.c
+++ b/src/event/ngx_event_accept.c
@@ -94,9 +94,13 @@ void ngx_event_accept(ngx_event_t *ev)
             err = ngx_socket_errno;
 
             if (err == NGX_EAGAIN) {
-                ngx_log_error(NGX_LOG_NOTICE, log, err,
-                              "EAGAIN after %d accepted connection(s)",
-                              accepted);
+                if (!(ngx_event_flags
+                      & (NGX_USE_EDGE_EVENT|NGX_USE_SIGIO_EVENT)))
+                {
+                    ngx_log_error(NGX_LOG_NOTICE, log, err,
+                                  "EAGAIN after %d accepted connection(s)",
+                                  accepted);
+                }
 
                 ngx_destroy_pool(pool);
                 return;