nginx-0.0.1-2002-08-15-21:20:26 import
diff --git a/src/core/nginx.c b/src/core/nginx.c
index f1671b3..ab287f2 100644
--- a/src/core/nginx.c
+++ b/src/core/nginx.c
@@ -25,7 +25,7 @@
int ngx_max_conn = 512;
struct sockaddr_in ngx_addr = {0, AF_INET, 0, 0, 0};
-
+int ngx_backlog = 0;
ngx_pool_t ngx_pool;
ngx_log_t ngx_log;
@@ -35,10 +35,12 @@
int main(int argc, char *const *argv)
{
char addr_text[22];
- ngx_socket_t fd;
+ ngx_socket_t s;
ngx_listen_t ls;
+ int reuseaddr = 1;
#if (WIN32)
WSADATA wsd;
+ unsigned long nb = 1;
#endif
@@ -61,16 +63,45 @@
"WSAStartup failed");
#endif
+ /* for each listening socket */
+ s = socket(AF_INET, SOCK_STREAM, 0);
+ if (s == -1)
+ ngx_log_error(NGX_LOG_EMERG, &(ngx_log), ngx_socket_errno,
+ "socket failed");
+
+ if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
+ (const void *) &reuseaddr, sizeof(int)) == -1)
+ ngx_log_error(NGX_LOG_EMERG, &(ngx_log), ngx_socket_errno,
+ "setsockopt (SO_REUSEADDR) failed");
+
+#if (WIN32)
+ if (ioctlsocket(s, FIONBIO, &nb) == -1)
+ ngx_log_error(NGX_LOG_EMERG, &(ngx_log), ngx_socket_errno,
+ "ioctlsocket (FIONBIO) failed");
+#else
+ if (fcntl(s, F_SETFL, O_NONBLOCK) == -1)
+ ngx_log_error(NGX_LOG_EMERG, &(ngx_log), ngx_socket_errno,
+ "fcntl (O_NONBLOCK) failed");
+#endif
+
ngx_snprintf(ngx_cpystrn(addr_text, inet_ntoa(ngx_addr.sin_addr), 16),
7, ":%d", ntohs(ngx_addr.sin_port));
- fd = ngx_listen((struct sockaddr *) &ngx_addr, -1, &ngx_log, addr_text);
+
+ if (bind(s, (struct sockaddr *) &ngx_addr,
+ sizeof(struct sockaddr_in)) == -1)
+ ngx_log_error(NGX_LOG_EMERG, &(ngx_log), ngx_socket_errno,
+ "bind to %s failed", addr_text);
+
+ if (listen(s, ngx_backlog) == -1)
+ ngx_log_error(NGX_LOG_EMERG, &(ngx_log), ngx_socket_errno,
+ "listen to %s failed", addr_text);
ngx_server.buff_size = 1024;
ngx_server.handler = ngx_http_init_connection;
/* daemon */
- ls.fd = fd;
+ ls.fd = s;
ls.server = &ngx_server;
ls.log = &ngx_log;
diff --git a/src/core/ngx_config.h b/src/core/ngx_config.h
index 1412da8..2350dee 100644
--- a/src/core/ngx_config.h
+++ b/src/core/ngx_config.h
@@ -48,8 +48,10 @@
#include <stdio.h>
#include <stdarg.h>
#include <fcntl.h>
+#include <signal.h>
#include <string.h>
#include <sys/types.h>
+#include <sys/wait.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/uio.h>
diff --git a/src/core/ngx_hunk.c b/src/core/ngx_hunk.c
index 3defc6d..2bf1a53 100644
--- a/src/core/ngx_hunk.c
+++ b/src/core/ngx_hunk.c
@@ -8,12 +8,12 @@
ngx_hunk_t *h = ngx_palloc(pool, sizeof(ngx_hunk_t));
#ifndef OFF_EQUAL_PTR
- h->pos.f = h->last.f = 0;
+ h->pos.file = h->last.file = 0;
#endif
h->pre_start = ngx_palloc(pool, size + before + after);
- h->start = h->pos.p = h->last.p = h->pre_start + before;
- h->end = h->last.p + size;
+ h->start = h->pos.mem = h->last.mem = h->pre_start + before;
+ h->end = h->last.mem + size;
h->post_end = h->end + after;
h->type = NGX_HUNK_TEMP;
@@ -28,21 +28,22 @@
ngx_hunk_t *h = ngx_palloc(pool, sizeof(ngx_hunk_t));
#ifndef OFF_EQUAL_PTR
- h->pos.f = h->last.f = 0;
+ h->pos.file = h->last.file = 0;
#endif
- if (hunk->type & NGX_HUNK_TEMP && hunk->pos.p - hunk->pre_start >= size) {
+ if (hunk->type & NGX_HUNK_TEMP && hunk->pos.mem - hunk->pre_start >= size) {
/* keep hunk->start unchanged - used in restore */
h->pre_start = hunk->pre_start;
- h->end = h->post_end = hunk->pre_start = hunk->pos.p;
- h->start = h->pos.p = h->last.p = h->end - size;
+ h->end = h->post_end = hunk->pre_start = hunk->pos.mem;
+ h->start = h->pos.mem = h->last.mem = h->end - size;
h->type = NGX_HUNK_TEMP;
h->tag = 0;
h->fd = (ngx_file_t) -1;
} else {
- h->pre_start = h->start = h->pos.p = h->last.p = ngx_palloc(pool, size);
+ h->pre_start = h->start = h->pos.mem = h->last.mem
+ = ngx_palloc(pool, size);
h->end = h->post_end = h->start + size;
h->type = NGX_HUNK_TEMP;
@@ -58,22 +59,23 @@
ngx_hunk_t *h = ngx_palloc(pool, sizeof(ngx_hunk_t));
#ifndef OFF_EQUAL_PTR
- h->pos.f = h->last.f = 0;
+ h->pos.file = h->last.file = 0;
#endif
if (hunk->type & NGX_HUNK_TEMP
- && hunk->last.p == hunk->end
+ && hunk->last.mem == hunk->end
&& hunk->post_end - hunk->end >= size)
{
h->post_end = hunk->post_end;
- h->pre_start = h->start = h->pos.p = h->last.p = hunk->post_end =
- hunk->last.p;
+ h->pre_start = h->start = h->pos.mem = h->last.mem = hunk->post_end =
+ hunk->last.mem;
h->type = NGX_HUNK_TEMP;
h->tag = 0;
h->fd = (ngx_file_t) -1;
} else {
- h->pre_start = h->start = h->pos.p = h->last.p = ngx_palloc(pool, size);
+ h->pre_start = h->start = h->pos.mem = h->last.mem =
+ ngx_palloc(pool, size);
h->end = h->post_end = h->start + size;
h->type = NGX_HUNK_TEMP;
diff --git a/src/core/ngx_hunk.h b/src/core/ngx_hunk.h
index e4238b4..8fbcf80 100644
--- a/src/core/ngx_hunk.h
+++ b/src/core/ngx_hunk.h
@@ -7,33 +7,39 @@
#include <ngx_alloc.h>
-/* type */
+/* hunk type */
+
+/* temp means that hunk's content can be changed */
+/* other type means that hunk's content can not be changed */
#define NGX_HUNK_TEMP 0x0001
#define NGX_HUNK_MEMORY 0x0002
#define NGX_HUNK_MMAP 0x0004
#define NGX_HUNK_FILE 0x0008
-#define NGX_HUNK_FLUSH 0x0010
-/* in thread state flush means to write the hunk completely before return
- in event-driven state flush means to start to write the hunk */
-#define NGX_HUNK_LAST 0x0020
-#define NGX_HUNK_IN_MEMORY (NGX_HUNK_TEMP | NGX_HUNK_MEMORY | NGX_HUNK_MMAP )
-#define NGX_HUNK_TYPE 0x0ffff
+/* hunk flags */
-/* flags */
-#define NGX_HUNK_SHUTDOWN 0x10000
+/* in thread state flush means to write the hunk completely before return */
+/* in event state flush means to start to write the hunk */
+#define NGX_HUNK_FLUSH 0x0100
+/* last hunk */
+#define NGX_HUNK_LAST 0x0200
/* can be used with NGX_HUNK_LAST only */
+#define NGX_HUNK_SHUTDOWN 0x0400
+
+
+#define NGX_HUNK_IN_MEMORY (NGX_HUNK_TEMP|NGX_HUNK_MEMORY|NGX_HUNK_MMAP)
+
typedef struct ngx_hunk_s ngx_hunk_t;
struct ngx_hunk_s {
union {
- char *p; /* start of current data */
- off_t f;
+ char *mem; /* start of current data */
+ off_t file;
} pos;
union {
- char *p; /* end of current data */
- off_t f;
+ char *mem; /* end of current data */
+ off_t file;
} last;
int type;
char *start; /* start of hunk */
diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c
index 6fb02db..8429d90 100644
--- a/src/core/ngx_log.c
+++ b/src/core/ngx_log.c
@@ -45,6 +45,7 @@
len += ngx_snprintf(errstr + len, sizeof(errstr) - len - 1,
" [%s] (%d)",
err_levels[level], err);
+ else
len += ngx_snprintf(errstr + len, sizeof(errstr) - len - 1,
" [%s] (%X)",
err_levels[level], err);