diff src/event/ngx_event.c @ 467:bbd6b0b4a2b1 release-0.1.8

nginx-0.1.8-RELEASE import *) Bugfix: in the ngx_http_autoindex_module if the long file names were in the listing. *) Feature: the "^~" modifier in the location directive. *) Feature: the proxy_max_temp_file_size directive.
author Igor Sysoev <igor@sysoev.ru>
date Sat, 20 Nov 2004 19:52:20 +0000
parents a88a3e4e158f
children 2ff194b74f1e
line wrap: on
line diff
--- a/src/event/ngx_event.c
+++ b/src/event/ngx_event.c
@@ -12,31 +12,12 @@
 #define DEFAULT_CONNECTIONS  512
 
 
+extern ngx_module_t ngx_kqueue_module;
+extern ngx_module_t ngx_devpoll_module;
+extern ngx_module_t ngx_epoll_module;
+extern ngx_module_t ngx_rtsig_module;
 extern ngx_module_t ngx_select_module;
-extern ngx_event_module_t ngx_select_module_ctx;
-
-#if (HAVE_KQUEUE)
-#include <ngx_kqueue_module.h>
-#endif
-
-#if (HAVE_DEVPOLL)
-extern ngx_module_t ngx_devpoll_module;
-extern ngx_event_module_t ngx_devpoll_module_ctx;
-#endif
 
-#if (HAVE_EPOLL)
-extern ngx_module_t ngx_epoll_module;
-extern ngx_event_module_t ngx_epoll_module_ctx;
-#endif
-
-#if (HAVE_RTSIG)
-extern ngx_module_t ngx_rtsig_module;
-extern ngx_event_module_t ngx_rtsig_module_ctx;
-#endif
-
-#if (HAVE_AIO)
-#include <ngx_aio_module.h>
-#endif
 
 static ngx_int_t ngx_event_module_init(ngx_cycle_t *cycle);
 static ngx_int_t ngx_event_process_init(ngx_cycle_t *cycle);
@@ -631,13 +612,13 @@ static char *ngx_event_use(ngx_conf_t *c
                     && old_ecf->use != ecf->use)
                 {
                     ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
-                        "when the server runs without a master process "
-                        "the \"%V\" event type must be the same as "
-                        "in previous configuration - \"%s\" "
-                        "and it can not be changed on the fly, "
-                        "to change it you need to stop server "
-                        "and start it again",
-                        &value[1], old_ecf->name);
+                               "when the server runs without a master process "
+                               "the \"%V\" event type must be the same as "
+                               "in previous configuration - \"%s\" "
+                               "and it can not be changed on the fly, "
+                               "to change it you need to stop server "
+                               "and start it again",
+                               &value[1], old_ecf->name);
 
                     return NGX_CONF_ERROR;
                 }
@@ -726,99 +707,122 @@ static void *ngx_event_create_conf(ngx_c
 static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf)
 {
     ngx_event_conf_t  *ecf = conf;
+
+    int                  fd, rtsig;
+    ngx_int_t            i, connections;
+    ngx_module_t        *module;
+    ngx_core_conf_t     *ccf;
+    ngx_event_module_t  *event_module;
+
+    connections = NGX_CONF_UNSET_UINT;
+    module = NULL;
+    rtsig = 0;
+    fd = 0;
+
+#if (HAVE_EPOLL) && !(TEST_BUILD_EPOLL)
+
+    fd = epoll_create(100);
+
+    if (fd != -1) {
+        close(fd);
+        connections = DEFAULT_CONNECTIONS;
+        module = &ngx_epoll_module;
+
+    } else if (ngx_errno != NGX_ENOSYS) {
+        connections = DEFAULT_CONNECTIONS;
+        module = &ngx_epoll_module;
+    }
+
+#endif
+
 #if (HAVE_RTSIG)
-    ngx_core_conf_t  *ccf;
+
+    if (module == NULL) {
+        connections = DEFAULT_CONNECTIONS;
+        module = &ngx_rtsig_module;
+        rtsig = 1;
+    }
+
+#endif
+
+#if (HAVE_DEVPOLL)
+
+    connections = DEFAULT_CONNECTIONS;
+    module = &ngx_devpoll_module;
+
 #endif
 
 #if (HAVE_KQUEUE)
 
-    ngx_conf_init_unsigned_value(ecf->connections, DEFAULT_CONNECTIONS);
-    ngx_conf_init_unsigned_value(ecf->use, ngx_kqueue_module.ctx_index);
-    ngx_conf_init_ptr_value(ecf->name, ngx_kqueue_module_ctx.name->data);
-
-#elif (HAVE_DEVPOLL)
-
-    ngx_conf_init_unsigned_value(ecf->connections, DEFAULT_CONNECTIONS);
-    ngx_conf_init_unsigned_value(ecf->use, ngx_devpoll_module.ctx_index);
-    ngx_conf_init_ptr_value(ecf->name, ngx_devpoll_module_ctx.name->data);
-
-#elif (HAVE_EPOLL)
+    connections = DEFAULT_CONNECTIONS;
+    module = &ngx_kqueue_module;
 
-    ngx_conf_init_unsigned_value(ecf->connections, DEFAULT_CONNECTIONS);
-    ngx_conf_init_unsigned_value(ecf->use, ngx_epoll_module.ctx_index);
-    ngx_conf_init_ptr_value(ecf->name, ngx_epoll_module_ctx.name->data);
-
-#elif (HAVE_RTSIG)
+#endif
 
-    ngx_conf_init_unsigned_value(ecf->connections, DEFAULT_CONNECTIONS);
-    ngx_conf_init_unsigned_value(ecf->use, ngx_rtsig_module.ctx_index);
-    ngx_conf_init_ptr_value(ecf->name, ngx_rtsig_module_ctx.name->data);
+#if (HAVE_SELECT)
 
-#elif (HAVE_SELECT)
+    if (module == NULL) {
 
 #if (NGX_WIN32)
-    ngx_conf_init_unsigned_value(ecf->connections, DEFAULT_CONNECTIONS);
+        connections = DEFAULT_CONNECTIONS;
 #else
-    ngx_conf_init_unsigned_value(ecf->connections,
-          FD_SETSIZE < DEFAULT_CONNECTIONS ? FD_SETSIZE : DEFAULT_CONNECTIONS);
+        connections = FD_SETSIZE < DEFAULT_CONNECTIONS ? FD_SETSIZE:
+                                                         DEFAULT_CONNECTIONS;
+#endif
+        module = &ngx_select_module;
+    }
+
 #endif
 
-    ngx_conf_init_unsigned_value(ecf->use, ngx_select_module.ctx_index);
-    ngx_conf_init_ptr_value(ecf->name, ngx_select_module_ctx.name->data);
-
-#else
-
-    ngx_int_t            i, m;
-    ngx_event_module_t  *module;
-
-    m = -1;
-    module = NULL;
+    if (module == NULL) {
+        for (i = 0; ngx_modules[i]; i++) {
+            if (ngx_modules[i]->type == NGX_EVENT_MODULE) {
+                event_module = ngx_modules[i]->ctx;
 
-    for (i = 0; ngx_modules[i]; i++) {
-        if (ngx_modules[i]->type == NGX_EVENT_MODULE) {
-            module = ngx_modules[i]->ctx;
+                if (ngx_strcmp(event_module->name->data, event_core_name.data)
+                                                                          == 0)
+                {
+                    continue;
+                }
 
-            if (ngx_strcmp(module->name->data, event_core_name.data) == 0) {
-                continue;
+                module = ngx_modules[i];
+                break;
             }
-
-            m = ngx_modules[i]->ctx_index;
-            break;
         }
     }
 
-    if (m == -1) {
+    if (module == NULL) {
         ngx_log_error(NGX_LOG_EMERG, cycle->log, 0, "no events module found");
         return NGX_CONF_ERROR;
     }
 
-    ngx_conf_init_unsigned_value(ecf->connections, DEFAULT_CONNECTIONS);
+    ngx_conf_init_unsigned_value(ecf->connections, connections);
+    cycle->connection_n = ecf->connections;
 
-    ngx_conf_init_unsigned_value(ecf->use, m);
-    ngx_conf_init_ptr_value(ecf->name, module->name->data);
+    ngx_conf_init_unsigned_value(ecf->use, module->ctx_index);
 
-#endif
-
-    cycle->connection_n = ecf->connections;
+    event_module = module->ctx;
+    ngx_conf_init_ptr_value(ecf->name, event_module->name->data);
 
     ngx_conf_init_value(ecf->multi_accept, 0);
     ngx_conf_init_value(ecf->accept_mutex, 1);
     ngx_conf_init_msec_value(ecf->accept_mutex_delay, 500);
 
-#if (HAVE_RTSIG)
-    if (ecf->use == ngx_rtsig_module.ctx_index && ecf->accept_mutex == 0) {
-        ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx,
-                                               ngx_core_module);
-        if (ccf->worker_processes) {
-            ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
-                          "the \"rtsig\" method requires "
-                          "\"accept_mutex\" to be on");
-            return NGX_CONF_ERROR;
-        }
+
+    if (!rtsig || ecf->accept_mutex) {
+        return NGX_CONF_OK;
     }
-#endif
+
+    ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module);
 
-    return NGX_CONF_OK;
+    if (ccf->worker_processes == 0) {
+        return NGX_CONF_OK;
+    }
+
+    ngx_log_error(NGX_LOG_EMERG, cycle->log, 0,
+                  "the \"rtsig\" method requires \"accept_mutex\" to be on");
+
+    return NGX_CONF_ERROR;
 }