summaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2002-08-26 15:18:19 +0000
committerIgor Sysoev <igor@sysoev.ru>2002-08-26 15:18:19 +0000
commit0ad17c09032bdfbc67cd1239b43107edc9d55a52 (patch)
tree3c2b56845d9c982135e12d505e1e443cbe0cd8ff /src/core
parent83661a922b26d84230ae0cc39f161323797cbb6c (diff)
downloadnginx-0ad17c09032bdfbc67cd1239b43107edc9d55a52.tar.gz
nginx-0ad17c09032bdfbc67cd1239b43107edc9d55a52.tar.bz2
nginx-0.0.1-2002-08-26-19:18:19 import
Diffstat (limited to 'src/core')
-rw-r--r--src/core/nginx.c57
-rw-r--r--src/core/ngx_alloc.c4
-rw-r--r--src/core/ngx_config.h1
-rw-r--r--src/core/ngx_connection.h9
-rw-r--r--src/core/ngx_hunk.c10
-rw-r--r--src/core/ngx_hunk.h2
-rw-r--r--src/core/ngx_listen.h12
-rw-r--r--src/core/ngx_log.c42
-rw-r--r--src/core/ngx_log.h16
9 files changed, 94 insertions, 59 deletions
diff --git a/src/core/nginx.c b/src/core/nginx.c
index bf737827f..748b44314 100644
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -85,43 +85,57 @@ static void ngx_open_listening_sockets(ngx_log_t *log)
/* for each listening socket */
ls = (ngx_listen_t *) ngx_listening_sockets->elts;
for (i = 0; i < ngx_listening_sockets->nelts; i++) {
+
if (ls[i].done)
continue;
-#if (WIN32)
- s = WSASocket(ls[i].family, ls[i].type, ls[i].protocol, NULL, 0, 0);
-#else
- s = socket(ls[i].family, ls[i].type, ls[i].protocol);
-#endif
- if (s == -1)
+ if (ls[i].inherited) {
+
+ /* TODO: close on exit */
+ /* TODO: nonblocking */
+ /* TODO: deferred accept */
+
+ ls[i].done = 1;
+ continue;
+ }
+
+ s = ngx_socket(ls[i].family, ls[i].type, ls[i].protocol,
+ ls[i].flags);
+ if (s == -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
- "nginx: socket %s falied", ls[i].addr_text);
+ ngx_socket_n " %s falied", ls[i].addr_text);
+ exit(1);
+ }
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
- (const void *) &reuseaddr, sizeof(int)) == -1)
+ (const void *) &reuseaddr, sizeof(int)) == -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
- "nginx: setsockopt (SO_REUSEADDR) %s failed",
+ "setsockopt(SO_REUSEADDR) %s failed",
ls[i].addr_text);
+ exit(1);
+ }
/* TODO: close on exit */
if (ls[i].nonblocking) {
- if (ngx_nonblocking(s) == -1)
+ if (ngx_nonblocking(s) == -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
ngx_nonblocking_n " %s failed",
ls[i].addr_text);
+ exit(1);
+ }
}
- if (bind(s, (struct sockaddr *) ls[i].addr, ls[i].addr_len) == -1) {
+ if (bind(s, ls[i].sockaddr, ls[i].socklen) == -1) {
err = ngx_socket_errno;
- ngx_log_error(NGX_LOG_ALERT, log, err,
- "bind to %s failed", ls[i].addr_text);
+ ngx_log_error(NGX_LOG_EMERG, log, err,
+ "bind() to %s failed", ls[i].addr_text);
if (err != NGX_EADDRINUSE)
exit(1);
if (ngx_close_socket(s) == -1)
- ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno,
+ ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
ngx_close_socket_n " %s failed",
ls[i].addr_text);
@@ -129,9 +143,11 @@ static void ngx_open_listening_sockets(ngx_log_t *log)
continue;
}
- if (listen(s, ls[i].backlog) == -1)
+ if (listen(s, ls[i].backlog) == -1) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
- "listen to %s failed", ls[i].addr_text);
+ "listen() to %s failed", ls[i].addr_text);
+ exit(1);
+ }
/* TODO: deferred accept */
@@ -142,10 +158,13 @@ static void ngx_open_listening_sockets(ngx_log_t *log)
if (!failed)
break;
- ngx_log_error(NGX_LOG_NOTICE, log, 0, "try to bind again after 500ms");
+ ngx_log_error(NGX_LOG_NOTICE, log, 0,
+ "try again to bind() after 500ms");
ngx_msleep(500);
}
- if (failed)
- ngx_log_error(NGX_LOG_EMERG, log, 0, "can't bind");
+ if (failed) {
+ ngx_log_error(NGX_LOG_EMERG, log, 0, "can not bind(), exiting");
+ exit(1);
+ }
}
diff --git a/src/core/ngx_alloc.c b/src/core/ngx_alloc.c
index e059e94f6..1fd058b9f 100644
--- a/src/core/ngx_alloc.c
+++ b/src/core/ngx_alloc.c
@@ -12,8 +12,8 @@ void *ngx_alloc(size_t size, ngx_log_t *log)
p = malloc(size);
if (p == NULL)
- ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
- "ngx_alloc: malloc() %d bytes failed", size);
+ ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
+ "malloc() %d bytes failed", size);
return p;
}
diff --git a/src/core/ngx_config.h b/src/core/ngx_config.h
index 16ea3a68b..88f374ac3 100644
--- a/src/core/ngx_config.h
+++ b/src/core/ngx_config.h
@@ -48,6 +48,7 @@
#else /* POSIX */
#include <unistd.h>
+#include <stddef.h> /* offsetof */
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
diff --git a/src/core/ngx_connection.h b/src/core/ngx_connection.h
index 84cbd24f7..2f6d12826 100644
--- a/src/core/ngx_connection.h
+++ b/src/core/ngx_connection.h
@@ -26,6 +26,15 @@ struct ngx_connection_s {
ngx_server_t *server;
ngx_server_t *servers;
ngx_pool_t *pool;
+
+ int family;
+ struct sockaddr *sockaddr;
+ socklen_t socklen;
+ size_t addr;
+ char *addr_text;
+ size_t addr_textlen;
+
+ time_t post_accept_timeout;
};
diff --git a/src/core/ngx_hunk.c b/src/core/ngx_hunk.c
index 29edfbc18..f829b7e48 100644
--- a/src/core/ngx_hunk.c
+++ b/src/core/ngx_hunk.c
@@ -18,7 +18,7 @@ ngx_hunk_t *ngx_get_hunk(ngx_pool_t *pool, int size, int before, int after)
h->type = NGX_HUNK_TEMP;
h->tag = 0;
- h->fd = (ngx_file_t) -1;
+ h->fd = (ngx_fd_t) -1;
return h;
}
@@ -39,7 +39,7 @@ ngx_hunk_t *ngx_get_hunk_before(ngx_pool_t *pool, ngx_hunk_t *hunk, int size)
h->type = NGX_HUNK_TEMP;
h->tag = 0;
- h->fd = (ngx_file_t) -1;
+ h->fd = (ngx_fd_t) -1;
} else {
h->pre_start = h->start = h->pos.mem = h->last.mem
@@ -48,7 +48,7 @@ ngx_hunk_t *ngx_get_hunk_before(ngx_pool_t *pool, ngx_hunk_t *hunk, int size)
h->type = NGX_HUNK_TEMP;
h->tag = 0;
- h->fd = (ngx_file_t) -1;
+ h->fd = (ngx_fd_t) -1;
}
return h;
@@ -71,7 +71,7 @@ ngx_hunk_t *ngx_get_hunk_after(ngx_pool_t *pool, ngx_hunk_t *hunk, int size)
hunk->last.mem;
h->type = NGX_HUNK_TEMP;
h->tag = 0;
- h->fd = (ngx_file_t) -1;
+ h->fd = (ngx_fd_t) -1;
} else {
h->pre_start = h->start = h->pos.mem = h->last.mem =
@@ -80,7 +80,7 @@ ngx_hunk_t *ngx_get_hunk_after(ngx_pool_t *pool, ngx_hunk_t *hunk, int size)
h->type = NGX_HUNK_TEMP;
h->tag = 0;
- h->fd = (ngx_file_t) -1;
+ h->fd = (ngx_fd_t) -1;
}
return h;
diff --git a/src/core/ngx_hunk.h b/src/core/ngx_hunk.h
index 36c36e8c9..5e2a1d47e 100644
--- a/src/core/ngx_hunk.h
+++ b/src/core/ngx_hunk.h
@@ -48,7 +48,7 @@ struct ngx_hunk_s {
char *pre_start; /* start of pre-allocated hunk */
char *post_end; /* end of post-allocated hunk */
int tag;
- ngx_file_t fd;
+ ngx_fd_t fd;
};
typedef struct ngx_chain_s ngx_chain_t;
diff --git a/src/core/ngx_listen.h b/src/core/ngx_listen.h
index 26980d431..8108d837d 100644
--- a/src/core/ngx_listen.h
+++ b/src/core/ngx_listen.h
@@ -11,22 +11,26 @@
typedef struct {
ngx_socket_t fd;
- void *addr;
- size_t addr_len;
- char *addr_text;
+ struct sockaddr *sockaddr;
+ socklen_t socklen;
+ size_t addr;
+ char *addr_text;
+ size_t addr_textlen;
int family;
int type;
int protocol;
+ int flags;
ngx_log_t *log;
void *server;
int (*handler)(ngx_connection_t *c);
int backlog;
+ time_t post_accept_timeout;
unsigned done:1;
- unsigned close:1;
+ unsigned inherited:1;
unsigned nonblocking:1;
#if 0
unsigned overlapped:1;
diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c
index 8429d90b1..bed628aed 100644
--- a/src/core/ngx_log.c
+++ b/src/core/ngx_log.c
@@ -37,39 +37,42 @@ void ngx_log_error_core(int level, ngx_log_t *log, ngx_err_t err,
#endif
ngx_localtime(&tm);
- len = ngx_snprintf(errstr, sizeof(errstr), "%02d:%02d:%02d",
+ len = ngx_snprintf(errstr, sizeof(errstr), "%4d/%02d/%02d %02d:%02d:%02d",
+ tm.ngx_tm_year + 1900, tm.ngx_tm_mon, tm.ngx_tm_mday,
tm.ngx_tm_hour, tm.ngx_tm_min, tm.ngx_tm_sec);
+ len += ngx_snprintf(errstr + len, sizeof(errstr) - len - 1,
+ " [%s] ", err_levels[level]);
+
+ len += ngx_snprintf(errstr + len, sizeof(errstr) - len - 1,
+ "%d#%d: ", getpid(), 0);
+
+#if (HAVE_VARIADIC_MACROS)
+ va_start(args, fmt);
+ len += ngx_vsnprintf(errstr + len, sizeof(errstr) - len - 1, fmt, args);
+ va_end(args);
+#else
+ len += ngx_vsnprintf(errstr + len, sizeof(errstr) - len - 1, fmt, args);
+#endif
+
if (err) {
if ((unsigned) err < 0x80000000)
len += ngx_snprintf(errstr + len, sizeof(errstr) - len - 1,
- " [%s] (%d)",
- err_levels[level], err);
+ " (%d: ", err);
else
len += ngx_snprintf(errstr + len, sizeof(errstr) - len - 1,
- " [%s] (%X)",
- err_levels[level], err);
+ " (%X: ", err);
len += ngx_strerror_r(err, errstr + len, sizeof(errstr) - len - 1);
if (len < sizeof(errstr) - 2) {
- errstr[len++] = ':';
- errstr[len++] = ' ';
+ errstr[len++] = ')';
} else {
len = sizeof(errstr) - 2;
}
-
- } else {
- len += ngx_snprintf(errstr + len, sizeof(errstr) - len - 1,
- " [%s] ", err_levels[level]);
}
-#if (HAVE_VARIADIC_MACROS)
- va_start(args, fmt);
- len += ngx_vsnprintf(errstr + len, sizeof(errstr) - len - 1, fmt, args);
- va_end(args);
-#else
- len += ngx_vsnprintf(errstr + len, sizeof(errstr) - len - 1, fmt, args);
-#endif
+ if (level != NGX_LOG_DEBUG && log->handler)
+ len += log->handler(log->data, errstr + len, sizeof(errstr) - len - 1);
if (len > sizeof(errstr) - 2)
len = sizeof(errstr) - 2;
@@ -77,9 +80,6 @@ void ngx_log_error_core(int level, ngx_log_t *log, ngx_err_t err,
errstr[len + 1] = '\0';
fputs(errstr, stderr);
-
- if (level == NGX_LOG_EMERG)
- exit(1);
}
#if !(HAVE_VARIADIC_MACROS)
diff --git a/src/core/ngx_log.h b/src/core/ngx_log.h
index 7afabcbae..f1e49ebd4 100644
--- a/src/core/ngx_log.h
+++ b/src/core/ngx_log.h
@@ -3,6 +3,7 @@
#include <ngx_errno.h>
+#include <ngx_file.h>
typedef enum {
NGX_LOG_EMERG = 0,
@@ -59,13 +60,14 @@ typedef enum {
*/
typedef struct {
- int log_level;
- char *action;
- char *context;
-#if 0
- void *data; /* i.e. ngx_http_proxy_error_context_t */
- char *func(ngx_log_t *log);
-#endif
+ int log_level;
+ ngx_fd_t fd;
+ void *data;
+ size_t (*handler)(void *ctx, char *buf, size_t len);
+/* STUB */
+ char *action;
+ char *context;
+/* */
} ngx_log_t;
#define MAX_ERROR_STR 2048