# HG changeset patch # User Igor Sysoev # Date 1054654978 0 # Node ID 7ebc8b7fb816e252bc4661079d26775a5bcaf959 # Parent a059e1aa65d4a3fe326d4dcfabfbff397115a80e nginx-0.0.1-2003-06-03-19:42:58 import diff --git a/src/core/nginx.c b/src/core/nginx.c --- a/src/core/nginx.c +++ b/src/core/nginx.c @@ -31,21 +31,25 @@ ngx_array_t ngx_listening_sockets; int main(int argc, char *const *argv) { int i; - ngx_str_t conf_file; - ngx_conf_t conf; + ngx_str_t conf_file; + ngx_log_t *log; + ngx_conf_t conf; ngx_max_sockets = -1; +#if 0 ngx_log.fd = STDERR_FILENO; ngx_log.log_level = NGX_LOG_INFO; /* STUB */ ngx_log.log_level = NGX_LOG_DEBUG; +#endif + log = ngx_log_init_errlog(); - if (ngx_os_init(&ngx_log) == NGX_ERROR) { + if (ngx_os_init(log) == NGX_ERROR) { return 1; } - ngx_pool = ngx_create_pool(16 * 1024, &ngx_log); + ngx_pool = ngx_create_pool(16 * 1024, log); /* */ ngx_max_module = 0; @@ -72,7 +76,7 @@ int main(int argc, char *const *argv) conf.ctx = ngx_conf_ctx; conf.pool = ngx_pool; - conf.log = &ngx_log; + conf.log = log; conf.module_type = NGX_CORE_MODULE; conf.cmd_type = NGX_MAIN_CONF; @@ -83,6 +87,11 @@ int main(int argc, char *const *argv) return 1; } +#if 0 + log = (ngx_log_t *) ngx_get_conf(ngx_errlog_module); + /* STUB */ log->log_level = NGX_LOG_DEBUG; +#endif + ngx_init_temp_number(); ngx_io = ngx_os_io; @@ -95,7 +104,7 @@ int main(int argc, char *const *argv) } } - if (ngx_open_listening_sockets(&ngx_log) == NGX_ERROR) { + if (ngx_open_listening_sockets(log) == NGX_ERROR) { return 1; } @@ -103,12 +112,12 @@ int main(int argc, char *const *argv) /* TODO: fork */ - ngx_pre_thread(&ngx_listening_sockets, ngx_pool, &ngx_log); + ngx_pre_thread(&ngx_listening_sockets, ngx_pool, log); /* TODO: threads */ /* STUB */ - ngx_worker(&ngx_log); + ngx_worker(log); } return 0; diff --git a/src/core/ngx_alloc.c b/src/core/ngx_alloc.c --- a/src/core/ngx_alloc.c +++ b/src/core/ngx_alloc.c @@ -1,10 +1,6 @@ #include - -#include -#include -#include -#include +#include void *ngx_alloc(size_t size, ngx_log_t *log) diff --git a/src/core/ngx_alloc.h b/src/core/ngx_alloc.h --- a/src/core/ngx_alloc.h +++ b/src/core/ngx_alloc.h @@ -3,8 +3,8 @@ #include +#include -#include /* NGX_MAX_ALLOC_FROM_POOL should be (PAGE_SIZE - 1), i.e. 4095 on x86. On FreeBSD 5.x it allows to use zero copy send. @@ -18,12 +18,15 @@ typedef struct ngx_pool_large_s ngx_pool_large_t; + struct ngx_pool_large_s { ngx_pool_large_t *next; void *alloc; }; -typedef struct ngx_pool_s ngx_pool_t; + +typedef struct ngx_pool_s ngx_pool_t; + struct ngx_pool_s { char *last; char *end; diff --git a/src/core/ngx_array.c b/src/core/ngx_array.c --- a/src/core/ngx_array.c +++ b/src/core/ngx_array.c @@ -1,9 +1,6 @@ #include - -#include -#include -#include +#include ngx_array_t *ngx_create_array(ngx_pool_t *p, int n, size_t size) diff --git a/src/core/ngx_array.h b/src/core/ngx_array.h --- a/src/core/ngx_array.h +++ b/src/core/ngx_array.h @@ -3,8 +3,8 @@ #include +#include -#include typedef struct { void *elts; diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c --- a/src/core/ngx_conf_file.c +++ b/src/core/ngx_conf_file.c @@ -1,9 +1,6 @@ #include - #include -#include -#include char ngx_conf_errstr[MAX_CONF_ERRSTR]; diff --git a/src/core/ngx_conf_file.h b/src/core/ngx_conf_file.h --- a/src/core/ngx_conf_file.h +++ b/src/core/ngx_conf_file.h @@ -3,14 +3,7 @@ #include -#include -#include -#include -#include -#include -#include -#include -#include +#include /* @@ -51,10 +44,6 @@ extern char ngx_conf_errstr[MAX_CONF_ERRSTR]; -typedef struct ngx_conf_s ngx_conf_t; - - -typedef struct ngx_command_s ngx_command_t; struct ngx_command_s { ngx_str_t name; int type; @@ -66,14 +55,15 @@ struct ngx_command_s { #define ngx_null_command {ngx_null_string, 0, NULL, 0, 0, NULL} -typedef struct { + +struct ngx_module_s { int ctx_index; int index; void *ctx; ngx_command_t *commands; int type; int (*init_module)(ngx_pool_t *p); -} ngx_module_t; +}; typedef struct { diff --git a/src/core/ngx_connection.h b/src/core/ngx_connection.h --- a/src/core/ngx_connection.h +++ b/src/core/ngx_connection.h @@ -1,26 +1,10 @@ #ifndef _NGX_CONNECTION_H_INCLUDED_ #define _NGX_CONNECTION_H_INCLUDED_ +#include #include - -#if 0 -#include -#include -#include -#include -#include -#include +#include -#include -#endif - -#if 0 -typedef struct ngx_connection_s ngx_connection_t; -#endif - -#ifdef NGX_EVENT -#include -#endif struct ngx_connection_s { ngx_socket_t fd; diff --git a/src/core/ngx_core.h b/src/core/ngx_core.h --- a/src/core/ngx_core.h +++ b/src/core/ngx_core.h @@ -5,19 +5,25 @@ #include #include #include -#include #include #include +typedef struct ngx_module_s ngx_module_t; +typedef struct ngx_conf_s ngx_conf_t; +typedef struct ngx_command_s ngx_command_t; + +typedef struct ngx_file_s ngx_file_t; +typedef struct ngx_event_s ngx_event_t; typedef struct ngx_connection_s ngx_connection_t; -typedef struct ngx_event_s ngx_event_t; #include #include +#include #include #include -#include +#include #include +#include #include #include #include diff --git a/src/core/ngx_file.c b/src/core/ngx_file.c --- a/src/core/ngx_file.c +++ b/src/core/ngx_file.c @@ -1,10 +1,6 @@ #include #include -#include -#include -#include -#include static int ngx_temp_number; diff --git a/src/core/ngx_file.h b/src/core/ngx_file.h --- a/src/core/ngx_file.h +++ b/src/core/ngx_file.h @@ -2,11 +2,9 @@ #define _NGX_FILE_H_INCLUDED_ -#include -#include -#include +#include +#include -typedef struct ngx_file_s ngx_file_t; struct ngx_file_s { ngx_fd_t fd; diff --git a/src/core/ngx_hunk.c b/src/core/ngx_hunk.c --- a/src/core/ngx_hunk.c +++ b/src/core/ngx_hunk.c @@ -1,6 +1,6 @@ #include -#include +#include ngx_hunk_t *ngx_create_temp_hunk(ngx_pool_t *pool, int size, diff --git a/src/core/ngx_hunk.h b/src/core/ngx_hunk.h --- a/src/core/ngx_hunk.h +++ b/src/core/ngx_hunk.h @@ -1,11 +1,9 @@ -#ifndef _NGX_CHUNK_H_INCLUDED_ -#define _NGX_CHUNK_H_INCLUDED_ +#ifndef _NGX_HUNK_H_INCLUDED_ +#define _NGX_HUNK_H_INCLUDED_ #include -#include -#include -#include +#include /* hunk type */ @@ -35,7 +33,8 @@ -typedef struct ngx_hunk_s ngx_hunk_t; +typedef struct ngx_hunk_s ngx_hunk_t; + struct ngx_hunk_s { char *pos; char *last; @@ -53,7 +52,8 @@ struct ngx_hunk_s { }; -typedef struct ngx_chain_s ngx_chain_t; +typedef struct ngx_chain_s ngx_chain_t; + struct ngx_chain_s { ngx_hunk_t *hunk; ngx_chain_t *next; @@ -83,4 +83,4 @@ ngx_hunk_t *ngx_create_temp_hunk(ngx_poo } while (0); -#endif /* _NGX_CHUNK_H_INCLUDED_ */ +#endif /* _NGX_HUNK_H_INCLUDED_ */ diff --git a/src/core/ngx_inet.c b/src/core/ngx_inet.c --- a/src/core/ngx_inet.c +++ b/src/core/ngx_inet.c @@ -1,7 +1,6 @@ #include -#include -#include +#include /* AF_INET only */ diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c --- a/src/core/ngx_log.c +++ b/src/core/ngx_log.c @@ -14,6 +14,36 @@ #include +static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); + + +static ngx_str_t errlog_name = ngx_string("errlog"); + +static ngx_command_t ngx_errlog_commands[] = { + + {ngx_string("error_log"), + NGX_MAIN_CONF|NGX_CONF_TAKE1, + ngx_set_error_log, + 0, + 0, + NULL}, + + ngx_null_command +}; + + +ngx_module_t ngx_errlog_module = { + NGX_MODULE, + &errlog_name, /* module context */ + ngx_errlog_commands, /* module directives */ + NGX_CORE_MODULE, /* module type */ + NULL /* init module */ +}; + + +static ngx_log_t ngx_log; + + static const char *err_levels[] = { "stderr", "emerg", "alert", "crit", "error", "warn", "notice", "info", "debug" @@ -33,6 +63,9 @@ void ngx_log_error_core(int level, ngx_l #if (HAVE_VARIADIC_MACROS) va_list args; #endif +#if (WIN32) + int written; +#endif ngx_localtime(&tm); len = ngx_snprintf(errstr, sizeof(errstr), "%4d/%02d/%02d %02d:%02d:%02d", @@ -87,10 +120,15 @@ void ngx_log_error_core(int level, ngx_l #if (WIN32) errstr[len++] = '\r'; -#endif errstr[len++] = '\n'; + if (log->fd) { + WriteFile(log->fd, errstr, len, &written, NULL); + } +#else + errstr[len++] = '\n'; + write(log->fd, errstr, len); +#endif - write(log->fd, errstr, len); #if 0 errstr[len] = '\0'; @@ -137,6 +175,8 @@ void ngx_assert_core(ngx_log_t *log, con #endif +#if 0 + void ngx_log_stderr(ngx_event_t *ev) { char errstr[MAX_ERROR_STR]; @@ -165,3 +205,79 @@ void ngx_log_stderr(ngx_event_t *ev) ngx_log_error(NGX_LOG_STDERR, &ngx_log, 0, "%s", errstr); } } + +#endif + + +static char *ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) +{ + return ngx_log_set_errlog(cf, cmd, &ngx_log); +} + + + +ngx_log_t *ngx_log_init_errlog() +{ +#if (WIN32) + ngx_log.fd = GetStdHandle(STD_ERROR_HANDLE); + + if (ngx_log.fd == NGX_INVALID_FILE) { + /* TODO: where we can log error ? */ + return NULL; + + } else if (ngx_log.fd == NULL) { + /* there are no associated standard handles */ + /* TODO: where we can log possible errors ? */ + } + +#else + ngx_log.fd = STDERR_FILENO; +#endif + + ngx_log.log_level = NGX_LOG_INFO; + /* STUB */ ngx_log.log_level = NGX_LOG_DEBUG; + + return &ngx_log; +} + + +char *ngx_log_set_errlog(ngx_conf_t *cf, ngx_command_t *cmd, ngx_log_t *log) +{ + int len; + ngx_err_t err; + ngx_str_t *value; + + value = cf->args->elts; + + log->fd = ngx_open_file(value[1].data, + NGX_FILE_RDWR, + NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND); + + if (log->fd == NGX_INVALID_FILE) { + err = ngx_errno; + len = ngx_snprintf(ngx_conf_errstr, sizeof(ngx_conf_errstr) - 1, + ngx_open_file_n " \"%s\" failed (%d: ", + value[1].data, err); + len += ngx_strerror_r(err, ngx_conf_errstr + len, + sizeof(ngx_conf_errstr) - len - 1); + ngx_conf_errstr[len++] = ')'; + ngx_conf_errstr[len++] = '\0'; + return ngx_conf_errstr; + } + +#if (WIN32) + if (ngx_file_append_mode(log->fd) == NGX_ERROR) { + err = ngx_errno; + len = ngx_snprintf(ngx_conf_errstr, sizeof(ngx_conf_errstr) - 1, + ngx_file_append_mode_n " \"%s\" failed (%d: ", + value[1].data, err); + len += ngx_strerror_r(err, ngx_conf_errstr + len, + sizeof(ngx_conf_errstr) - len - 1); + ngx_conf_errstr[len++] = ')'; + ngx_conf_errstr[len++] = '\0'; + return ngx_conf_errstr; + } +#endif + + return NGX_CONF_OK; +} diff --git a/src/core/ngx_log.h b/src/core/ngx_log.h --- a/src/core/ngx_log.h +++ b/src/core/ngx_log.h @@ -2,8 +2,9 @@ #define _NGX_LOG_H_INCLUDED_ -#include -#include +#include +#include + typedef enum { NGX_LOG_STDERR = 0, @@ -160,4 +161,11 @@ void ngx_assert_core(ngx_log_t *log, con #endif /* VARIADIC MACROS */ +ngx_log_t *ngx_log_init_errlog(); +char *ngx_log_set_errlog(ngx_conf_t *cf, ngx_command_t *cmd, ngx_log_t *log); + + +extern ngx_module_t ngx_errlog_module; + + #endif /* _NGX_LOG_H_INCLUDED_ */ diff --git a/src/core/ngx_modules.c b/src/core/ngx_modules.c --- a/src/core/ngx_modules.c +++ b/src/core/ngx_modules.c @@ -1,9 +1,9 @@ #include - -#include +#include +extern ngx_module_t ngx_errlog_module; extern ngx_module_t ngx_events_module; extern ngx_module_t ngx_event_module; @@ -42,6 +42,10 @@ extern ngx_module_t ngx_http_log_module ngx_module_t *ngx_modules[] = { + /* core */ + + &ngx_errlog_module, + /* events */ &ngx_events_module, diff --git a/src/core/ngx_sendfile.c b/src/core/ngx_sendfile.c deleted file mode 100644 --- a/src/core/ngx_sendfile.c +++ /dev/null @@ -1,25 +0,0 @@ - -#include - -#if !(HAVE_SENDFILE) - -#include -#include -#include -#include - -int ngx_sendfile(ngx_socket_t s, - ngx_iovec_t *headers, int hdr_cnt, - ngx_fd_t fd, off_t offset, size_t nbytes, - ngx_iovec_t *trailers, int trl_cnt, - off_t *sent, - ngx_log_t *log) -{ - ngx_log_error(NGX_LOG_INFO, log, 0, - "ngx_sendfile: sendfile is not implemented"); - - - return NGX_ERROR; -} - -#endif diff --git a/src/core/ngx_sendfile.h b/src/core/ngx_sendfile.h deleted file mode 100644 --- a/src/core/ngx_sendfile.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef _NGX_SENDFILE_H_INCLUDED_ -#define _NGX_SENDFILE_H_INCLUDED_ - - -#include -#include -#include -#include -#include -#include -#include - -int ngx_sendfile(ngx_connection_t *c, - ngx_iovec_t *headers, int hdr_cnt, - ngx_fd_t fd, off_t offset, size_t nbytes, - ngx_iovec_t *trailers, int trl_cnt, - off_t *sent, u_int flags); - - -extern u_int ngx_sendfile_flags; - - -#endif /* _NGX_SENDFILE_H_INCLUDED_ */ diff --git a/src/core/ngx_server.h b/src/core/ngx_server.h deleted file mode 100644 --- a/src/core/ngx_server.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef _NGX_SERVER_H_INCLUDED_ -#define _NGX_SERVER_H_INCLUDED_ - - -#include -#include -#include - -typedef struct { - int log_level; - ngx_pool_t *pool; - int (*handler)(void *data); - int buff_size; -} ngx_server_t; - - -#endif /* _NGX_SERVER_H_INCLUDED_ */ diff --git a/src/core/ngx_string.c b/src/core/ngx_string.c --- a/src/core/ngx_string.c +++ b/src/core/ngx_string.c @@ -1,7 +1,6 @@ #include #include -#include char *ngx_cpystrn(char *dst, char *src, size_t n) diff --git a/src/core/ngx_string.h b/src/core/ngx_string.h --- a/src/core/ngx_string.h +++ b/src/core/ngx_string.h @@ -3,6 +3,7 @@ #include +#include typedef struct { diff --git a/src/core/ngx_table.h b/src/core/ngx_table.h --- a/src/core/ngx_table.h +++ b/src/core/ngx_table.h @@ -3,9 +3,8 @@ #include -#include -#include -#include +#include + typedef ngx_array_t ngx_table_t; @@ -14,6 +13,7 @@ typedef struct { ngx_str_t value; } ngx_table_elt_t; + #define ngx_create_table(p, n) ngx_create_array(p, n, 2 * sizeof(ngx_str_t)) #define ngx_push_table(t) ngx_push_array(t) diff --git a/src/event/ngx_event_accept.c b/src/event/ngx_event_accept.c --- a/src/event/ngx_event_accept.c +++ b/src/event/ngx_event_accept.c @@ -78,7 +78,7 @@ void ngx_event_accept(ngx_event_t *ev) ls->addr_text.data); } - sleep(1); + ngx_msleep(1000); ngx_destroy_pool(pool); return; diff --git a/src/event/ngx_event_acceptex.c b/src/event/ngx_event_acceptex.c --- a/src/event/ngx_event_acceptex.c +++ b/src/event/ngx_event_acceptex.c @@ -1,11 +1,9 @@ #include +#include -#include -#include -#include #include -#include + #include #include #include @@ -14,10 +12,7 @@ -/* This function should always return NGX_OK even there are some failures - because if we return NGX_ERROR then listening socket would be closed */ - -int ngx_event_acceptex(ngx_event_t *ev) +void ngx_event_acceptex(ngx_event_t *ev) { ngx_connection_t *c; @@ -25,25 +20,23 @@ int ngx_event_acceptex(ngx_event_t *ev) if (ev->ovlp.error) { ngx_log_error(NGX_LOG_CRIT, ev->log, ev->ovlp.error, - "AcceptEx(%s) falied", c->addr_text.data); - return NGX_OK; + "AcceptEx() falied for %s", c->addr_text.data); + return; } -#if 0 - - /* can we do SO_UPDATE_ACCEPT_CONTEXT just before shutdown() ??? + /* TODO: can we do SO_UPDATE_ACCEPT_CONTEXT just before shutdown() ??? or AcceptEx's context will be lost ??? */ /* SO_UPDATE_ACCEPT_CONTEXT is required for shutdown() to work */ - if (setsockopt(context->accept_socket, SOL_SOCKET, - SO_UPDATE_ACCEPT_CONTEXT, (char *)&nsd, - sizeof(nsd))) { - ap_log_error(APLOG_MARK, APLOG_ERR, WSAGetLastError(), server_conf, - "setsockopt(SO_UPDATE_ACCEPT_CONTEXT) failed."); + if (setsockopt(c->fd, SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT, + (char *)&c->listening->fd, sizeof(ngx_socket_t)) == -1) + { + ngx_log_error(NGX_LOG_CRIT, ev->log, ngx_socket_errno, + "setsockopt(SO_UPDATE_ACCEPT_CONTEXT) failed for %s", + c->addr_text.data); - /* non fatal - we can not only do lingering close */ - -#endif + /* non fatal - we can not only do lingering close */ + } getacceptexsockaddrs(c->data, 0, c->socklen + 16, c->socklen + 16, @@ -57,7 +50,7 @@ int ngx_event_acceptex(ngx_event_t *ev) c->handler(c); - return NGX_OK; + return; } diff --git a/src/http/modules/ngx_http_log_handler.c b/src/http/modules/ngx_http_log_handler.c --- a/src/http/modules/ngx_http_log_handler.c +++ b/src/http/modules/ngx_http_log_handler.c @@ -198,5 +198,19 @@ static char *ngx_http_log_set_log(ngx_co return ngx_conf_errstr; } +#if (WIN32) + if (ngx_file_append_mode(lcf->file.fd) == NGX_ERROR) { + err = ngx_errno; + len = ngx_snprintf(ngx_conf_errstr, sizeof(ngx_conf_errstr) - 1, + ngx_file_appned_mode_n " \"%s\" failed (%d: ", + lcf->file.name.data, err); + len += ngx_strerror_r(err, ngx_conf_errstr + len, + sizeof(ngx_conf_errstr) - len - 1); + ngx_conf_errstr[len++] = ')'; + ngx_conf_errstr[len++] = '\0'; + return ngx_conf_errstr; + } +#endif + return NGX_CONF_OK; } diff --git a/src/http/modules/ngx_http_range_filter.c b/src/http/modules/ngx_http_range_filter.c --- a/src/http/modules/ngx_http_range_filter.c +++ b/src/http/modules/ngx_http_range_filter.c @@ -252,7 +252,7 @@ static int ngx_http_range_header_filter( r->headers_out.content_length); len += ctx->boundary_header.len + range[i].content_range.len - + range[i].end - range[i].start; + + (size_t) (range[i].end - range[i].start); } r->headers_out.content_length = len; diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c --- a/src/http/ngx_http.c +++ b/src/http/ngx_http.c @@ -1,13 +1,10 @@ #include +#include -#include -#include #include -#include + #include -#include -#include static void ngx_http_init_filters(ngx_pool_t *pool, ngx_module_t **modules); diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h --- a/src/http/ngx_http.h +++ b/src/http/ngx_http.h @@ -3,15 +3,7 @@ #include - -#include -#include -#include -#include -#include -#include -#include - +#include #include #include #include diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -798,8 +798,12 @@ static char *ngx_http_core_merge_srv_con if (conf->listen.nelts == 0) { ngx_test_null(l, ngx_push_array(&conf->listen), NGX_CONF_ERROR); l->addr = INADDR_ANY; +#if (WIN32) + l->port = 80; +#else /* STUB: getuid() should be cached */ l->port = (getuid() == 0) ? 80 : 8000; +#endif l->family = AF_INET; } diff --git a/src/http/ngx_http_event.c b/src/http/ngx_http_event.c --- a/src/http/ngx_http_event.c +++ b/src/http/ngx_http_event.c @@ -279,6 +279,10 @@ static void ngx_http_process_request_lin /* STUB: we need to handle such URIs */ if (r->complex_uri || r->unusual_uri) { + r->request_line.len = r->request_end - r->request_start; + r->request_line.data = r->request_start; + r->request_line.data[r->request_line.len] = '\0'; + ngx_http_header_parse_error(r, NGX_HTTP_PARSE_INVALID_REQUEST); ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST); return; diff --git a/src/http/ngx_http_header_filter.c b/src/http/ngx_http_header_filter.c --- a/src/http/ngx_http_header_filter.c +++ b/src/http/ngx_http_header_filter.c @@ -93,7 +93,6 @@ static int ngx_http_header_filter(ngx_ht ngx_hunk_t *h; ngx_chain_t *ch; ngx_table_elt_t *header; - ngx_http_range_t *range; if (r->http_version < NGX_HTTP_VERSION_10) { return NGX_OK; diff --git a/src/os/unix/ngx_errno.h b/src/os/unix/ngx_errno.h --- a/src/os/unix/ngx_errno.h +++ b/src/os/unix/ngx_errno.h @@ -5,6 +5,7 @@ #include #include + typedef int ngx_err_t; #define NGX_ENOENT ENOENT diff --git a/src/os/unix/ngx_time.h b/src/os/unix/ngx_time.h --- a/src/os/unix/ngx_time.h +++ b/src/os/unix/ngx_time.h @@ -24,7 +24,7 @@ void ngx_localtime(ngx_tm_t *tm); ngx_msec_t ngx_msec(void); /* STUB */ -#define ngx_time() time(NULL) +#define ngx_time() time(NULL) #endif /* _NGX_TIME_H_INCLUDED_ */ diff --git a/src/os/win32/ngx_errno.h b/src/os/win32/ngx_errno.h --- a/src/os/win32/ngx_errno.h +++ b/src/os/win32/ngx_errno.h @@ -3,22 +3,24 @@ #include +#include -typedef DWORD ngx_err_t; + +typedef DWORD ngx_err_t; #define ngx_errno GetLastError() #define ngx_socket_errno WSAGetLastError() #define ngx_set_socket_errno(err) WSASetLastError(err) -#define NGX_ENOENT ERROR_FILE_NOT_FOUND -#define NGX_EACCES ERROR_ACCESS_DENIED -#define NGX_EEXIST ERROR_FILE_EXISTS -#define NGX_ENOTDIR ERROR_PATH_NOT_FOUND -#define NGX_EAGAIN WSAEWOULDBLOCK -#define NGX_EINPROGRESS WSAEINPROGRESS -#define NGX_EADDRINUSE WSAEADDRINUSE -#define NGX_ECONNRESET ECONNRESET -#define NGX_ETIMEDOUT WSAETIMEDOUT +#define NGX_ENOENT ERROR_FILE_NOT_FOUND +#define NGX_EACCES ERROR_ACCESS_DENIED +#define NGX_EEXIST ERROR_FILE_EXISTS +#define NGX_ENOTDIR ERROR_PATH_NOT_FOUND +#define NGX_EAGAIN WSAEWOULDBLOCK +#define NGX_EINPROGRESS WSAEINPROGRESS +#define NGX_EADDRINUSE WSAEADDRINUSE +#define NGX_ECONNRESET ECONNRESET +#define NGX_ETIMEDOUT WSAETIMEDOUT int ngx_strerror_r(ngx_err_t err, char *errstr, size_t size); diff --git a/src/os/win32/ngx_files.c b/src/os/win32/ngx_files.c --- a/src/os/win32/ngx_files.c +++ b/src/os/win32/ngx_files.c @@ -1,9 +1,7 @@ #include +#include -#include -#include -#include ssize_t ngx_read_file(ngx_file_t *file, char *buf, size_t size, off_t offset) { @@ -18,3 +16,15 @@ ssize_t ngx_read_file(ngx_file_t *file, return n; } + + +int ngx_file_append_mode(ngx_fd_t *fd) +{ + if (SetFilePointer(fd, 0, NULL, FILE_END) == 0xFFFFFFFF) { + if (GetLastError() != NO_ERROR) { + return NGX_ERROR; + } + } + + return NGX_OK; +} diff --git a/src/os/win32/ngx_files.h b/src/os/win32/ngx_files.h --- a/src/os/win32/ngx_files.h +++ b/src/os/win32/ngx_files.h @@ -3,14 +3,12 @@ #include - -#include -#include +#include /* INVALID_FILE_ATTRIBUTES specified but never defined at least in VC6SP2 */ #ifndef INVALID_FILE_ATTRIBUTES -#define INVALID_FILE_ATTRIBUTES 0xFFFFFFFF +#define INVALID_FILE_ATTRIBUTES 0xFFFFFFFF #endif #define NGX_INVALID_FILE INVALID_HANDLE_VALUE @@ -19,7 +17,7 @@ #define ngx_open_file(name, access, create) \ - CreateFile(name, flags, \ + CreateFile(name, access, \ FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, \ NULL, create, FILE_FLAG_BACKUP_SEMANTICS, NULL) /* @@ -31,6 +29,11 @@ #define NGX_FILE_RDWR GENERIC_READ|GENERIC_WRITE #define NGX_FILE_CREATE_OR_OPEN OPEN_ALWAYS #define NGX_FILE_OPEN OPEN_EXISTING +#define NGX_FILE_APPEND 0 + + +int ngx_file_append_mode(ngx_fd_t fd); +#define ngx_file_append_mode_n "SetFilePointer()" #define ngx_open_tempfile(name, persistent) \ @@ -46,7 +49,6 @@ #define ngx_open_tempfile_n "CreateFile()" - #define ngx_close_file CloseHandle #define ngx_close_file_n "CloseHandle()" diff --git a/src/os/win32/ngx_init.c b/src/os/win32/ngx_init.c --- a/src/os/win32/ngx_init.c +++ b/src/os/win32/ngx_init.c @@ -14,11 +14,73 @@ ngx_os_io_t ngx_os_io = { }; +/* Should these pointers be per protocol ? */ +LPFN_ACCEPTEX acceptex; +LPFN_GETACCEPTEXSOCKADDRS getacceptexsockaddrs; +LPFN_TRANSMITFILE transmitfile; + +static GUID ae_guid = WSAID_ACCEPTEX; +static GUID as_guid = WSAID_GETACCEPTEXSOCKADDRS; +static GUID tf_guid = WSAID_TRANSMITFILE; + + int ngx_os_init(ngx_log_t *log) { - if (ngx_init_sockets(log) == NGX_ERROR) { + DWORD bytes; + SOCKET s; + WSADATA wsd; + + /* init Winsock */ + + if (WSAStartup(MAKEWORD(2,2), &wsd) != 0) { + ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, + "WSAStartup failed"); + return NGX_ERROR; + } + + ngx_log_error(NGX_LOG_INFO, log, 0, "max sockets: %d", wsd.iMaxSockets); + + /* get AcceptEx(), GetAcceptExSockAddrs() and TransmitFile() addresses */ + + s = ngx_socket(AF_INET, SOCK_STREAM, IPPROTO_IP, 0); + if (s == -1) { + ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, + ngx_socket_n " %s falied"); return NGX_ERROR; } + if (WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, &ae_guid, sizeof(GUID), + &acceptex, sizeof(LPFN_ACCEPTEX), &bytes, NULL, NULL) == -1) { + + ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, + "WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER, " + "WSAID_ACCEPTEX) failed"); + return NGX_ERROR; + } + + if (WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, &as_guid, sizeof(GUID), + &getacceptexsockaddrs, sizeof(LPFN_GETACCEPTEXSOCKADDRS), + &bytes, NULL, NULL) == -1) { + + ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, + "WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER, " + "WSAID_ACCEPTEX) failed"); + return NGX_ERROR; + } + + if (WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, &tf_guid, sizeof(GUID), + &transmitfile, sizeof(LPFN_TRANSMITFILE), &bytes, + NULL, NULL) == -1) { + ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, + "WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER, " + "WSAID_TRANSMITFILE) failed"); + return NGX_ERROR; + } + + if (ngx_close_socket(s) == -1) { + ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno, + ngx_close_socket_n " failed"); + } + return NGX_OK; } diff --git a/src/os/win32/ngx_os_init.h b/src/os/win32/ngx_os_init.h --- a/src/os/win32/ngx_os_init.h +++ b/src/os/win32/ngx_os_init.h @@ -3,7 +3,7 @@ #include -#include +#include int ngx_os_init(ngx_log_t *log); diff --git a/src/os/win32/ngx_socket.c b/src/os/win32/ngx_socket.c --- a/src/os/win32/ngx_socket.c +++ b/src/os/win32/ngx_socket.c @@ -1,76 +1,7 @@ #include - #include -#include -#include -#include - - -/* These pointers should be per protocol ? */ -LPFN_ACCEPTEX acceptex; -LPFN_GETACCEPTEXSOCKADDRS getacceptexsockaddrs; -LPFN_TRANSMITFILE transmitfile; - -static GUID ae_guid = WSAID_ACCEPTEX; -static GUID as_guid = WSAID_GETACCEPTEXSOCKADDRS; -static GUID tf_guid = WSAID_TRANSMITFILE; - - -int ngx_init_sockets(ngx_log_t *log) -{ - DWORD bytes; - SOCKET s; - WSADATA wsd; - - if (WSAStartup(MAKEWORD(2,2), &wsd) != 0) { - ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, - "WSAStartup failed"); - return NGX_ERROR; - } - - s = ngx_socket(AF_INET, SOCK_STREAM, IPPROTO_IP, 0); - if (s == -1) { - ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, - ngx_socket_n " %s falied"); - return NGX_ERROR; - } - if (WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, &ae_guid, sizeof(GUID), - &acceptex, sizeof(LPFN_ACCEPTEX), &bytes, NULL, NULL) == -1) { - - ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, - "WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER, " - "WSAID_ACCEPTEX) failed"); - return NGX_ERROR; - } - - if (WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, &as_guid, sizeof(GUID), - &getacceptexsockaddrs, sizeof(LPFN_GETACCEPTEXSOCKADDRS), - &bytes, NULL, NULL) == -1) { - - ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, - "WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER, " - "WSAID_ACCEPTEX) failed"); - return NGX_ERROR; - } - - if (WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, &tf_guid, sizeof(GUID), - &transmitfile, sizeof(LPFN_TRANSMITFILE), &bytes, - NULL, NULL) == -1) { - ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno, - "WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER, " - "WSAID_TRANSMITFILE) failed"); - return NGX_ERROR; - } - - if (ngx_close_socket(s) == -1) { - ngx_log_error(NGX_LOG_ALERT, log, ngx_socket_errno, - ngx_close_socket_n " failed"); - } - - return NGX_OK; -} int ngx_nonblocking(ngx_socket_t s) { @@ -79,6 +10,7 @@ int ngx_nonblocking(ngx_socket_t s) return ioctlsocket(s, FIONBIO, &nb); } + int ngx_blocking(ngx_socket_t s) { unsigned long nb = 0; diff --git a/src/os/win32/ngx_socket.h b/src/os/win32/ngx_socket.h --- a/src/os/win32/ngx_socket.h +++ b/src/os/win32/ngx_socket.h @@ -3,7 +3,8 @@ #include -#include +#include + #define NGX_WRITE_SHUTDOWN SD_SEND @@ -12,7 +13,6 @@ typedef SOCKET ngx_socket_t; typedef int socklen_t; -int ngx_init_sockets(ngx_log_t *log); #define ngx_socket(af, type, proto, flags) \ WSASocket(af, type, proto, NULL, 0, flags) diff --git a/src/os/win32/ngx_time.h b/src/os/win32/ngx_time.h --- a/src/os/win32/ngx_time.h +++ b/src/os/win32/ngx_time.h @@ -2,7 +2,9 @@ #define _NGX_TIME_H_INCLUDED_ -#include +#include +#include + typedef unsigned int ngx_msec_t; #define NGX_MAX_MSEC ~0 @@ -24,7 +26,7 @@ typedef FILETIME ngx_mtime_t; #define ngx_msec GetTickCount /* STUB */ -#define ngx_time() time(NULL) +#define ngx_time() time(NULL) #endif /* _NGX_TIME_H_INCLUDED_ */ diff --git a/src/os/win32/ngx_types.h b/src/os/win32/ngx_types.h --- a/src/os/win32/ngx_types.h +++ b/src/os/win32/ngx_types.h @@ -3,6 +3,7 @@ #include +#include typedef unsigned __int32 u_int32_t;