diff options
| author | Igor Sysoev <igor@sysoev.ru> | 2002-08-15 17:20:26 +0000 |
|---|---|---|
| committer | Igor Sysoev <igor@sysoev.ru> | 2002-08-15 17:20:26 +0000 |
| commit | 0c331d9f666b4f9be91009b7caea457e58a80779 (patch) | |
| tree | d48221581b361ee5b0ccad46e4df49caa41b1bba /src/core | |
| parent | 6de5c2cb63f8aee4bcbec3c363a72fd8e4a4e64d (diff) | |
| download | nginx-0c331d9f666b4f9be91009b7caea457e58a80779.tar.gz nginx-0c331d9f666b4f9be91009b7caea457e58a80779.tar.bz2 | |
nginx-0.0.1-2002-08-15-21:20:26 import
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/nginx.c | 39 | ||||
| -rw-r--r-- | src/core/ngx_config.h | 2 | ||||
| -rw-r--r-- | src/core/ngx_hunk.c | 28 | ||||
| -rw-r--r-- | src/core/ngx_hunk.h | 32 | ||||
| -rw-r--r-- | src/core/ngx_log.c | 1 |
5 files changed, 72 insertions, 30 deletions
diff --git a/src/core/nginx.c b/src/core/nginx.c index f1671b38d..ab287f283 100644 --- a/src/core/nginx.c +++ b/src/core/nginx.c @@ -25,7 +25,7 @@ int ngx_http_init_connection(void *data); 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 @@ ngx_server_t ngx_server; 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 @@ int main(int argc, char *const *argv) "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 1412da85a..2350dee96 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 3defc6d0b..2bf1a5397 100644 --- a/src/core/ngx_hunk.c +++ b/src/core/ngx_hunk.c @@ -8,12 +8,12 @@ ngx_hunk_t *ngx_get_hunk(ngx_pool_t *pool, int size, int before, int after) 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 *ngx_get_hunk_before(ngx_pool_t *pool, ngx_hunk_t *hunk, int size) 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 *ngx_get_hunk_after(ngx_pool_t *pool, ngx_hunk_t *hunk, int size) 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 e4238b4f5..8fbcf806c 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 6fb02db2f..8429d90b1 100644 --- a/src/core/ngx_log.c +++ b/src/core/ngx_log.c @@ -45,6 +45,7 @@ void ngx_log_error_core(int level, ngx_log_t *log, ngx_err_t err, 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); |
