changeset 256:8e39cab6abd5

nginx-0.0.2-2004-02-10-19:23:38 import
author Igor Sysoev <igor@sysoev.ru>
date Tue, 10 Feb 2004 16:23:38 +0000
parents e6938ca7331a
children 70e1c7d2b83d
files auto/configure auto/unix src/core/nginx.c src/core/nginx.h src/core/ngx_connection.c src/core/ngx_connection.h src/event/modules/ngx_epoll_module.c src/event/ngx_event.h src/http/ngx_http_request.c src/os/unix/ngx_errno.c src/os/unix/ngx_errno.h src/os/unix/ngx_freebsd_config.h src/os/unix/ngx_linux_config.h src/os/unix/ngx_recv.c src/os/unix/ngx_solaris_config.h
diffstat 15 files changed, 87 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/auto/configure
+++ b/auto/configure
@@ -3,7 +3,7 @@
 . auto/init
 . auto/sources
 
-test -d $OBJ || mkdir $OBJ
+test -d $OBJS || mkdir $OBJS
 echo > $NGX_AUTO_CONFIG_H
 
 if [ "$PLATFORM" != win32 ]; then
--- a/auto/unix
+++ b/auto/unix
@@ -98,6 +98,12 @@ ngx_func_test="char buf[20]; int n; n = 
 . auto/func
 
 
+ngx_func="gnu_strerror_r()"
+ngx_func_inc="#include <string.h>"
+ngx_func_test="char buf[20], *str; str = strerror_r(1, buf, 20)"
+. auto/func
+
+
 ngx_func="localtime_r()"
 ngx_func_inc="#include <time.h>"
 ngx_func_test="struct tm t; time_t c=0; localtime_r(&c, &t)"
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -203,6 +203,15 @@ int main(int argc, char *const *argv, ch
         ccf->pid.data = NGINX_PID;
         ccf->newpid.len = sizeof(NGINX_NEW_PID) - 1;
         ccf->newpid.data = NGINX_NEW_PID;
+
+    } else {
+        ccf->newpid.len = ccf->pid.len + sizeof(NGINX_NEW_PID_EXT);
+        if (!(ccf->newpid.data = ngx_alloc(ccf->newpid.len, cycle->log))) {
+            return 1;
+        }
+
+        ngx_memcpy(ngx_cpymem(ccf->newpid.data, ccf->pid.data, ccf->pid.len),
+                   NGINX_NEW_PID_EXT, sizeof(NGINX_NEW_PID_EXT));
     }
 
     len = ngx_snprintf(pid, /* STUB */ 10, PID_T_FMT, ngx_getpid());
@@ -785,7 +794,7 @@ static ngx_int_t ngx_getopt(ngx_master_c
         }
     }
 
-    if (cycle->conf_file.len == NULL) {
+    if (cycle->conf_file.data == NULL) {
         cycle->conf_file.len = sizeof(NGINX_CONF) - 1;
         cycle->conf_file.data = NGINX_CONF;
     }
@@ -814,6 +823,7 @@ static ngx_int_t ngx_core_module_init(ng
     /* set by pcalloc()
      *
      * ccf->pid = NULL;
+     * ccf->newpid = NULL;
      */
     ccf->daemon = NGX_CONF_UNSET;
     ccf->master = NGX_CONF_UNSET;
--- a/src/core/nginx.h
+++ b/src/core/nginx.h
@@ -2,19 +2,20 @@
 #define _NGINX_H_INCLUDED_
 
 
-#define NGINX_VER      "nginx/0.0.2"
-#define NGINX_CONF     "nginx.conf"
-#define NGINX_PID      "nginx.pid"
-#define NGINX_NEW_PID  NGINX_PID ".newbin"
+#define NGINX_VER          "nginx/0.0.2"
+#define NGINX_CONF         "nginx.conf"
+#define NGINX_PID          "nginx.pid"
+#define NGINX_NEW_PID_EXT  ".newbin"
+#define NGINX_NEW_PID      NGINX_PID NGINX_NEW_PID_EXT
 
-#define NGINX_VAR      "NGINX="
-#define NGINX_VAR_LEN  (sizeof(NGINX_VAR) - 1)
+#define NGINX_VAR          "NGINX="
+#define NGINX_VAR_LEN      (sizeof(NGINX_VAR) - 1)
 
-extern ngx_module_t    ngx_core_module;
+extern ngx_module_t        ngx_core_module;
 
-extern ngx_uint_t      ngx_connection_counter;
+extern ngx_uint_t          ngx_connection_counter;
 
-extern ngx_int_t       ngx_process;
+extern ngx_int_t           ngx_process;
 
 
 #endif /* _NGINX_H_INCLUDED_ */
--- a/src/core/ngx_connection.c
+++ b/src/core/ngx_connection.c
@@ -243,14 +243,14 @@ ngx_int_t ngx_connection_error(ngx_conne
     ngx_int_t  level;
 
     if (err == NGX_ECONNRESET
-        && c->read->log_error == NGX_ERROR_IGNORE_ECONNRESET)
+        && c->log_error == NGX_ERROR_IGNORE_ECONNRESET)
     {
         return 0;
     }
 
     if (err == NGX_ECONNRESET || err == NGX_EPIPE || err == NGX_ENOTCONN) {
 
-        switch (c->read->log_error) {
+        switch (c->log_error) {
 
         case NGX_ERROR_INFO:
             level = NGX_LOG_INFO;
--- a/src/core/ngx_connection.h
+++ b/src/core/ngx_connection.h
@@ -52,6 +52,14 @@ typedef struct {
 } ngx_listening_t;
 
 
+typedef enum {
+     NGX_ERROR_CRIT = 0,
+     NGX_ERROR_ERR,
+     NGX_ERROR_INFO,
+     NGX_ERROR_IGNORE_ECONNRESET
+} ngx_connection_log_error_e;
+
+
 struct ngx_connection_s {
     void             *data;
     ngx_event_t      *read;
@@ -84,6 +92,8 @@ struct ngx_connection_s {
 
     ngx_int_t         number;
 
+    unsigned          log_error:2;  /* ngx_connection_log_error_e */
+
     unsigned          pipeline:1;
     unsigned          unexpected_eof:1;
     signed            tcp_nopush:2;
--- a/src/event/modules/ngx_epoll_module.c
+++ b/src/event/modules/ngx_epoll_module.c
@@ -132,12 +132,15 @@ ngx_module_t  ngx_epoll_module = {
 static int ngx_epoll_init(ngx_cycle_t *cycle)
 {
     size_t             n;
+    ngx_event_conf_t  *ecf;
     ngx_epoll_conf_t  *epcf;
 
+    ecf = ngx_event_get_conf(cycle->conf_ctx, ngx_event_core_module);
+
     epcf = ngx_event_get_conf(cycle->conf_ctx, ngx_epoll_module);
 
     if (ep == -1) {
-        ep = epoll_create(/* STUB: open_files / 2 */ 512);
+        ep = epoll_create(ecf->connections / 2);
 
         if (ep == -1) {
             ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
--- a/src/event/ngx_event.h
+++ b/src/event/ngx_event.h
@@ -20,14 +20,6 @@ typedef struct {
 #endif
 
 
-typedef enum {
-     NGX_ERROR_CRIT = 0,
-     NGX_ERROR_ERR,
-     NGX_ERROR_INFO,
-     NGX_ERROR_IGNORE_ECONNRESET
-} ngx_event_log_error_e;
-
-
 struct ngx_event_s {
     void            *data;
     /* TODO rename to handler */
@@ -88,7 +80,6 @@ struct ngx_event_s {
 
     unsigned short   read_discarded:1;
 
-    unsigned short   log_error:2;  /* ngx_event_log_error_e */
     unsigned short   unexpected_eof:1;
 
     unsigned short   deferred_accept:1;
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -79,10 +79,10 @@ void ngx_http_init_connection(ngx_connec
     ctx->action = "reading client request line";
     c->log->data = ctx;
     c->log->handler = ngx_http_log_error;
+    c->log_error = NGX_ERROR_INFO;
 
     rev = c->read;
     rev->event_handler = ngx_http_init_request;
-    rev->log_error = NGX_ERROR_INFO;
 
     /* STUB: epoll */ c->write->event_handler = ngx_http_empty_handler;
 
@@ -1272,10 +1272,10 @@ static void ngx_http_keepalive_handler(n
      * so we ignore ECONNRESET here.
      */
 
-    rev->log_error = NGX_ERROR_IGNORE_ECONNRESET;
+    c->log_error = NGX_ERROR_IGNORE_ECONNRESET;
     ngx_set_socket_errno(0);
     n = ngx_recv(c, c->buffer->last, c->buffer->end - c->buffer->last);
-    rev->log_error = NGX_ERROR_INFO;
+    c->log_error = NGX_ERROR_INFO;
 
     if (n == NGX_AGAIN) {
         return;
--- a/src/os/unix/ngx_errno.c
+++ b/src/os/unix/ngx_errno.c
@@ -25,4 +25,34 @@ ngx_int_t ngx_strerror_r(int err, char *
     return len;
 }
 
+#elif (HAVE_GNU_STRERROR_R)
+
+/* Linux strerror_r() */
+
+ngx_int_t ngx_strerror_r(int err, char *errstr, size_t size)
+{
+    char    *str;
+    size_t   len;
+
+    if (size == 0) {
+        return 0;
+    }
+
+    errstr[0] = '\0';
+
+    str = strerror_r(err, errstr, size);
+
+    if (str != errstr) {
+        return ngx_cpystrn(errstr, str, size) - errstr;
+    }
+
+    for (len = 0; len < size; len++) {
+        if (errstr[len] == '\0') {
+            break;
+        }
+    }
+
+    return len;
+}
+
 #endif
--- a/src/os/unix/ngx_errno.h
+++ b/src/os/unix/ngx_errno.h
@@ -2,8 +2,8 @@
 #define _NGX_ERRNO_H_INCLUDED_
 
 
-#include <errno.h>
-#include <string.h>
+#include <ngx_config.h>
+#include <ngx_core.h>
 
 
 typedef int               ngx_err_t;
@@ -34,7 +34,7 @@ typedef int               ngx_err_t;
 #define ngx_set_socket_errno(err)  errno = err
 
 
-#if (HAVE_STRERROR_R)
+#if (HAVE_STRERROR_R || HAVE_GNU_STRERROR_R)
 
 ngx_int_t ngx_strerror_r(int err, char *errstr, size_t size);
 
--- a/src/os/unix/ngx_freebsd_config.h
+++ b/src/os/unix/ngx_freebsd_config.h
@@ -7,7 +7,9 @@
 #include <stdlib.h>
 #include <stdarg.h>
 #include <stdio.h>
+#include <errno.h>
 #include <fcntl.h>
+#include <string.h>
 #include <signal.h>
 #include <sys/types.h>
 #include <sys/stat.h>
--- a/src/os/unix/ngx_linux_config.h
+++ b/src/os/unix/ngx_linux_config.h
@@ -13,10 +13,11 @@
 #include <stdlib.h>
 #include <stdarg.h>
 #include <stdio.h>
+#include <errno.h>
 #include <fcntl.h>
+#include <string.h>
 #include <signal.h>
 #include <time.h>
-#include <string.h>
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/select.h>
--- a/src/os/unix/ngx_recv.c
+++ b/src/os/unix/ngx_recv.c
@@ -32,7 +32,7 @@ ssize_t ngx_unix_recv(ngx_connection_t *
                     ngx_set_socket_errno(rev->kq_errno);
 
                     if (rev->kq_errno == NGX_ECONNRESET
-                        && rev->log_error == NGX_ERROR_IGNORE_ECONNRESET)
+                        && c->log_error == NGX_ERROR_IGNORE_ECONNRESET)
                     {
                         return 0;
                     }
--- a/src/os/unix/ngx_solaris_config.h
+++ b/src/os/unix/ngx_solaris_config.h
@@ -14,9 +14,10 @@
 #include <stdlib.h>
 #include <stdarg.h>
 #include <stdio.h>
+#include <errno.h>
 #include <fcntl.h>
+#include <string.h>
 #include <signal.h>
-#include <strings.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/wait.h>