diff --git a/auto/cc/gcc b/auto/cc/gcc index af279fa43..17bb13883 100644 --- a/auto/cc/gcc +++ b/auto/cc/gcc @@ -37,7 +37,7 @@ fi case "$NGX_PLATFORM" in *:sun4u) - # "-mcpu=v9" enables the "casxa" assembler instruction + # "-mcpu=v9" enables the "casa" assembler instruction CFLAGS="$CFLAGS -mcpu=v9" ;; @@ -134,6 +134,8 @@ case "$NGX_GCC_VER" in # we have a lot of the unused function arguments CFLAGS="$CFLAGS -Wno-unused-parameter" CFLAGS="$CFLAGS -Wno-unused-function" + CFLAGS="$CFLAGS -Wunused-variable" + CFLAGS="$CFLAGS -Wunused-value" #CFLAGS="$CFLAGS -Wunreachable-code" ;; diff --git a/auto/cc/icc b/auto/cc/icc index 0aa975ed2..d3a151c6e 100644 --- a/auto/cc/icc +++ b/auto/cc/icc @@ -22,8 +22,18 @@ CFLAGS="$CFLAGS -Ob2" # single-file IP optimizations #IPO="-ip" + # multi-file IP optimizations -IPO="-ipo -ipo_obj" +case "$NGX_ICC_VER" in + 9.*) + IPO="-ipo" + ;; + + *) + IPO="-ipo -ipo_obj" + ;; +esac + CFLAGS="$CFLAGS $IPO" CORE_LINK="$CORE_LINK $IPO" CORE_LINK="$CORE_LINK -opt_report_file=$NGX_OBJS/opt_report_file" @@ -72,7 +82,7 @@ CFLAGS="$CFLAGS -wd171" CFLAGS="$CFLAGS -wd181" # zero used for undefined preprocessing identifier CFLAGS="$CFLAGS -wd193" -#the format string ends before this argument +# the format string ends before this argument CFLAGS="$CFLAGS -wd268" # invalid format string conversion CFLAGS="$CFLAGS -wd269" @@ -92,15 +102,17 @@ CFLAGS="$CFLAGS -wd981" CFLAGS="$CFLAGS -wd1418" # external declaration in primary source file CFLAGS="$CFLAGS -wd1419" -# explicit conversion of a 64-bit integral type to a smaller integral type -CFLAGS="$CFLAGS -wd1683" -# conversion from pointer to same-sized integral type, warning on offsetof() -CFLAGS="$CFLAGS -wd1684" case "$NGX_ICC_VER" in 8.* | 9.*) # "cc" clobber ignored, warnings for Liunx's htons() CFLAGS="$CFLAGS -wd1469" + # explicit conversion of a 64-bit integral type to a smaller + # integral type + CFLAGS="$CFLAGS -wd1683" + # conversion from pointer to same-sized integral type, + # warning on offsetof() + CFLAGS="$CFLAGS -wd1684" # STUB # non-POD class type passed through ellipsis, Linux only ? diff --git a/auto/cc/name b/auto/cc/name index faa329075..7202aaa26 100644 --- a/auto/cc/name +++ b/auto/cc/name @@ -11,47 +11,47 @@ if [ $CC = cl ]; then 2>&1 >/dev/null`; then NGX_CC_NAME=msvc7 - echo " using Microsoft Visual C++ 7 compiler" + echo " Microsoft Visual C++ 7 compiler" else NGX_CC_NAME=msvc - echo " using Microsoft Visual C++ compiler" + echo " Microsoft Visual C++ compiler" fi else if [ $CC = wcl386 ]; then NGX_CC_NAME=owc - echo " using Open Watcom C compiler" + echo " Open Watcom C compiler" else if [ $CC = bcc32 ]; then NGX_CC_NAME=bcc - echo " using Borland C++ compiler" + echo " Borland C++ compiler" else if `$CC -v 2>&1 | grep 'gcc version' 2>&1 >/dev/null`; then NGX_CC_NAME=gcc - echo " using GNU C compiler" + echo " GNU C compiler" else if `$CC -V 2>&1 | grep '^Intel(R) C' 2>&1 >/dev/null`; then NGX_CC_NAME=icc - echo " using Intel C++ compiler" + echo " Intel C++ compiler" else if `$CC -V 2>&1 | grep 'Sun C' 2>&1 >/dev/null`; then NGX_CC_NAME=sunc - echo " using Sun C compiler" + echo " Sun C compiler" else if `$CC -V 2>&1 | grep '^Compaq C' 2>&1 >/dev/null`; then NGX_CC_NAME=ccc - echo " using Compaq C compiler" + echo " Compaq C compiler" else if `$CC -V 2>&1 | grep '^aCC: ' 2>&1 >/dev/null`; then NGX_CC_NAME=acc - echo " using HP aC++ compiler" + echo " HP aC++ compiler" else NGX_CC_NAME=unknown diff --git a/auto/configure b/auto/configure index daff4bd86..89390ea69 100755 --- a/auto/configure +++ b/auto/configure @@ -19,12 +19,28 @@ if [ $NGX_DEBUG = YES ]; then fi +if test -z "$NGX_PLATFORM"; then + echo "checking for OS" + + NGX_SYSTEM=`uname -s 2>/dev/null` + NGX_RELEASE=`uname -r 2>/dev/null` + NGX_MACHINE=`uname -m 2>/dev/null` + + echo " + $NGX_SYSTEM $NGX_RELEASE $NGX_MACHINE" + + NGX_PLATFORM="$NGX_SYSTEM:$NGX_RELEASE:$NGX_MACHINE"; + +else + echo "building for $NGX_PLATFORM" +fi + + if [ "$NGX_PLATFORM" != win32 ]; then . auto/headers fi -. auto/os/conf . auto/cc/conf +. auto/os/conf if [ "$NGX_PLATFORM" != win32 ]; then . auto/os/features diff --git a/auto/os/conf b/auto/os/conf index 69813ce25..56bdd2219 100644 --- a/auto/os/conf +++ b/auto/os/conf @@ -2,20 +2,7 @@ # Copyright (C) Igor Sysoev -if test -z "$NGX_PLATFORM"; then - echo "checking for OS" - - NGX_SYSTEM=`uname -s 2>/dev/null` - NGX_RELEASE=`uname -r 2>/dev/null` - NGX_MACHINE=`uname -m 2>/dev/null` - - echo " + $NGX_SYSTEM $NGX_RELEASE $NGX_MACHINE" - - NGX_PLATFORM="$NGX_SYSTEM:$NGX_RELEASE:$NGX_MACHINE"; - -else - echo "building for $NGX_PLATFORM" -fi +echo "checking for $NGX_SYSTEM specific features" case "$NGX_PLATFORM" in diff --git a/auto/os/features b/auto/os/features index 44c33cd31..3ec911087 100644 --- a/auto/os/features +++ b/auto/os/features @@ -92,6 +92,9 @@ fi if [ "$NGX_SYSTEM" = "NetBSD" ]; then + have=NGX_HAVE_TIMER_EVENT . auto/have + echo " + kqueue's EVFILT_TIMER found" + # NetBSD 2.0 incompatibly defines kevent.udata as "intptr_t" cat << END >> $NGX_AUTO_CONFIG_H diff --git a/auto/os/freebsd b/auto/os/freebsd index e5451224a..870ec9241 100644 --- a/auto/os/freebsd +++ b/auto/os/freebsd @@ -37,7 +37,7 @@ fi # sendfile if [ $osreldate -gt 300007 ]; then - echo " + using sendfile()" + echo " + sendfile() found" have=NGX_HAVE_SENDFILE . auto/have CORE_SRCS="$CORE_SRCS $FREEBSD_SENDFILE_SRCS" @@ -49,7 +49,7 @@ fi if [ \( $osreldate -lt 500000 -a $osreldate -ge 410000 \) \ -o $osreldate -ge 500011 ] then - echo " + using kqueue" + echo " + kqueue found" have=NGX_HAVE_KQUEUE . auto/have have=NGX_HAVE_CLEAR_EVENT . auto/have @@ -67,10 +67,19 @@ NGX_KQUEUE_CHECKED=YES if [ \( $version -lt 500000 -a $version -ge 430000 \) \ -o $version -ge 500018 ] then - echo " + using kqueue's NOTE_LOWAT" + echo " + kqueue's NOTE_LOWAT found" have=NGX_HAVE_LOWAT_EVENT . auto/have fi +# kqueue's EVFILT_TIMER + +if [ \( $version -lt 500000 -a $version -ge 440001 \) \ + -o $version -ge 500023 ] +then + echo " + kqueue's EVFILT_TIMER found" + have=NGX_HAVE_TIMER_EVENT . auto/have +fi + if [ $USE_THREADS = "rfork" ]; then diff --git a/auto/os/linux b/auto/os/linux index 32ef4cb8f..c31f848be 100644 --- a/auto/os/linux +++ b/auto/os/linux @@ -25,7 +25,7 @@ version=${version:-0} # enable the rt signals on Linux 2.2.19 and onward if [ $version -ge 131609 -o $EVENT_RTSIG = YES ]; then - echo " + using rt signals" + echo " + rt signals found" have=NGX_HAVE_RTSIG . auto/have have=NGX_HAVE_POLL . auto/have EVENT_MODULES="$EVENT_MODULES $RTSIG_MODULE" diff --git a/docs/xml/nginx/changes.xml b/docs/xml/nginx/changes.xml index b4b975f8c..fa1342cd5 100644 --- a/docs/xml/nginx/changes.xml +++ b/docs/xml/nginx/changes.xml @@ -9,6 +9,141 @@
../" CRLF, sizeof("../" CRLF) - 1); + tp = ngx_timeofday(); + for (i = 0; i < entries.nelts; i++) { b->last = ngx_cpymem(b->last, "last++ = ' '; - ngx_gmtime(entry[i].mtime + ngx_gmtoff * 60 * alcf->localtime, &tm); + ngx_gmtime(entry[i].mtime + tp->gmtoff * 60 * alcf->localtime, &tm); b->last = ngx_sprintf(b->last, "%02d-%s-%d %02d:%02d ", tm.ngx_tm_mday, diff --git a/src/http/modules/ngx_http_geo_module.c b/src/http/modules/ngx_http_geo_module.c index eedc1f7b2..6d94a069e 100644 --- a/src/http/modules/ngx_http_geo_module.c +++ b/src/http/modules/ngx_http_geo_module.c @@ -123,6 +123,7 @@ ngx_http_geo_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) } tree = ngx_radix_tree_create(cf->pool, -1); + if (tree == NULL) { return NGX_CONF_ERROR; } diff --git a/src/http/modules/ngx_http_index_module.c b/src/http/modules/ngx_http_index_module.c index 01b6d0cab..b7daa6d41 100644 --- a/src/http/modules/ngx_http_index_module.c +++ b/src/http/modules/ngx_http_index_module.c @@ -126,7 +126,8 @@ ngx_http_index_handler(ngx_http_request_t *r) ngx_uint_t i; ngx_http_index_t *index; ngx_http_index_ctx_t *ctx; - ngx_pool_cleanup_file_t *cln; + ngx_pool_cleanup_t *cln; + ngx_pool_cleanup_file_t *clnf; ngx_http_script_code_pt code; ngx_http_script_engine_t e; ngx_http_core_loc_conf_t *clcf; @@ -180,9 +181,9 @@ ngx_http_index_handler(ngx_http_request_t *r) e.ip = index[i].lengths->elts; e.request = r; - /* 1 byte for terminating '\0' and 4 bytes is preallocation */ + /* 1 byte for terminating '\0' */ - len = 1 + 4; + len = 1; while (*(uintptr_t *) e.ip) { lcode = *(ngx_http_script_len_code_pt *) e.ip; @@ -190,6 +191,10 @@ ngx_http_index_handler(ngx_http_request_t *r) } ctx->index.len = len; + + /* 16 bytes are preallocation */ + + len += 16; } if (len > ctx->path.len) { @@ -228,6 +233,11 @@ ngx_http_index_handler(ngx_http_request_t *r) ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, "open index \"%s\"", ctx->path.data); + cln = ngx_pool_cleanup_add(r->pool, sizeof(ngx_pool_cleanup_file_t)); + if (cln == NULL) { + return NGX_HTTP_INTERNAL_SERVER_ERROR; + } + fd = ngx_open_file(ctx->path.data, NGX_FILE_RDONLY, NGX_FILE_OPEN); if (fd == (ngx_fd_t) NGX_AGAIN) { @@ -268,19 +278,12 @@ ngx_http_index_handler(ngx_http_request_t *r) return NGX_HTTP_INTERNAL_SERVER_ERROR; } + cln->handler = ngx_pool_cleanup_file; + clnf = cln->data; - cln = ngx_palloc(r->pool, sizeof(ngx_pool_cleanup_file_t)); - if (cln == NULL) { - return NGX_HTTP_INTERNAL_SERVER_ERROR; - } - - cln->fd = fd; - cln->name = ctx->path.data; - cln->log = r->pool->log; - - if (ngx_pool_cleanup_add(r->pool, ngx_pool_cleanup_file, cln) == NULL) { - return NGX_HTTP_INTERNAL_SERVER_ERROR; - } + clnf->fd = fd; + clnf->name = ctx->path.data; + clnf->log = r->pool->log; clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); diff --git a/src/http/modules/ngx_http_ssi_filter_module.c b/src/http/modules/ngx_http_ssi_filter_module.c index 5f9ee3a42..af82b0e8b 100644 --- a/src/http/modules/ngx_http_ssi_filter_module.c +++ b/src/http/modules/ngx_http_ssi_filter_module.c @@ -1968,6 +1968,7 @@ ngx_http_ssi_date_gmt_local_variable(ngx_http_request_t *r, uintptr_t gmt) { ngx_http_ssi_ctx_t *ctx; ngx_http_variable_value_t *vv; + ngx_time_t *tp; struct tm tm; char buf[NGX_HTTP_SSI_DATE_LEN]; @@ -1976,12 +1977,14 @@ ngx_http_ssi_date_gmt_local_variable(ngx_http_request_t *r, uintptr_t gmt) return NULL; } + tp = ngx_timeofday(); + ctx = ngx_http_get_module_ctx(r, ngx_http_ssi_filter_module); if (ctx->timefmt.len == sizeof("%s") - 1 && ctx->timefmt.data[0] == '%' && ctx->timefmt.data[1] == 's') { - vv->value = ngx_time() + (gmt ? 0 : ngx_gmtoff); + vv->value = tp->sec + (gmt ? 0 : tp->gmtoff); vv->text.data = ngx_palloc(r->pool, NGX_TIME_T_LEN); if (vv->text.data == NULL) { @@ -1994,12 +1997,12 @@ ngx_http_ssi_date_gmt_local_variable(ngx_http_request_t *r, uintptr_t gmt) } if (gmt) { - ngx_libc_gmtime(&tm); + ngx_libc_gmtime(tp->sec, &tm); } else { - ngx_libc_localtime(&tm); + ngx_libc_localtime(tp->sec, &tm); } - vv->value = ngx_time() + (gmt ? 0 : ngx_gmtoff); + vv->value = tp->sec + (gmt ? 0 : tp->gmtoff); vv->text.len = strftime(buf, NGX_HTTP_SSI_DATE_LEN, (char *) ctx->timefmt.data, &tm); diff --git a/src/http/modules/ngx_http_ssl_module.c b/src/http/modules/ngx_http_ssl_module.c index bb9a55f49..09bf63dcf 100644 --- a/src/http/modules/ngx_http_ssl_module.c +++ b/src/http/modules/ngx_http_ssl_module.c @@ -17,6 +17,15 @@ static void *ngx_http_ssl_create_srv_conf(ngx_conf_t *cf); static char *ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child); +#if !defined (SSL_OP_CIPHER_SERVER_PREFERENCE) + +static char *ngx_http_ssl_nosupported(ngx_conf_t *cf, ngx_command_t *cmd, + void *conf); + +static char ngx_http_ssl_openssl097[] = "OpenSSL 0.9.7 and higher"; + +#endif + static ngx_conf_bitmask_t ngx_http_ssl_protocols[] = { { ngx_string("SSLv2"), NGX_SSL_SSLv2 }, @@ -26,6 +35,7 @@ static ngx_conf_bitmask_t ngx_http_ssl_protocols[] = { }; + static ngx_command_t ngx_http_ssl_commands[] = { { ngx_string("ssl"), @@ -50,14 +60,14 @@ static ngx_command_t ngx_http_ssl_commands[] = { NULL }, { ngx_string("ssl_protocols"), - NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_1MORE, ngx_conf_set_bitmask_slot, NGX_HTTP_SRV_CONF_OFFSET, offsetof(ngx_http_ssl_srv_conf_t, protocols), &ngx_http_ssl_protocols }, { ngx_string("ssl_ciphers"), - NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_1MORE, + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, ngx_conf_set_str_slot, NGX_HTTP_SRV_CONF_OFFSET, offsetof(ngx_http_ssl_srv_conf_t, ciphers), @@ -65,10 +75,14 @@ static ngx_command_t ngx_http_ssl_commands[] = { { ngx_string("ssl_prefer_server_ciphers"), NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG, +#ifdef SSL_OP_CIPHER_SERVER_PREFERENCE ngx_conf_set_flag_slot, NGX_HTTP_SRV_CONF_OFFSET, offsetof(ngx_http_ssl_srv_conf_t, prefer_server_ciphers), NULL }, +#else + ngx_http_ssl_nosupported, 0, 0, ngx_http_ssl_openssl097 }, +#endif ngx_null_command }; @@ -144,6 +158,8 @@ ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) ngx_http_ssl_srv_conf_t *prev = parent; ngx_http_ssl_srv_conf_t *conf = child; + ngx_pool_cleanup_t *cln; + ngx_conf_merge_value(conf->enable, prev->enable, 0); if (conf->enable == 0) { @@ -172,29 +188,37 @@ ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) return NGX_CONF_ERROR; } - if (ngx_pool_cleanup_add(cf->pool, ngx_ssl_cleanup_ctx, &conf->ssl) == NULL) - { + cln = ngx_pool_cleanup_add(cf->pool, 0); + if (cln == NULL) { return NGX_CONF_ERROR; } - if (ngx_ssl_certificate(&conf->ssl, conf->certificate.data, - conf->certificate_key.data) != NGX_OK) + cln->handler = ngx_ssl_cleanup_ctx; + cln->data = &conf->ssl; + + if (ngx_ssl_certificate(cf, &conf->ssl, &conf->certificate, + &conf->certificate_key) != NGX_OK) { return NGX_CONF_ERROR; } if (SSL_CTX_set_cipher_list(conf->ssl.ctx, - (const char *) conf->ciphers.data) == 0) + (const char *) conf->ciphers.data) + == 0) { ngx_ssl_error(NGX_LOG_EMERG, cf->log, 0, "SSL_CTX_set_cipher_list(\"%V\") failed", &conf->ciphers); } +#ifdef SSL_OP_CIPHER_SERVER_PREFERENCE + if (conf->prefer_server_ciphers) { SSL_CTX_set_options(conf->ssl.ctx, SSL_OP_CIPHER_SERVER_PREFERENCE); } +#endif + /* a temporary 512-bit RSA key is required for export versions of MSIE */ if (ngx_ssl_generate_rsa512_key(&conf->ssl) != NGX_OK) { return NGX_CONF_ERROR; @@ -207,3 +231,18 @@ ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) return NGX_CONF_OK; } + + +#if !defined (SSL_OP_CIPHER_SERVER_PREFERENCE) + +static char * +ngx_http_ssl_nosupported(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) +{ + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "\"%V\" directive is available only in %s,", + &cmd->name, cmd->post); + + return NGX_CONF_ERROR; +} + +#endif diff --git a/src/http/modules/ngx_http_static_module.c b/src/http/modules/ngx_http_static_module.c index c5d5af855..0e995f526 100644 --- a/src/http/modules/ngx_http_static_module.c +++ b/src/http/modules/ngx_http_static_module.c @@ -82,7 +82,8 @@ ngx_http_static_handler(ngx_http_request_t *r) ngx_buf_t *b; ngx_chain_t out; ngx_file_info_t fi; - ngx_pool_cleanup_file_t *cln; + ngx_pool_cleanup_t *cln; + ngx_pool_cleanup_file_t *clnf; ngx_http_core_loc_conf_t *clcf; if (r->uri.data[r->uri.len - 1] == '/') { @@ -119,6 +120,11 @@ ngx_http_static_handler(ngx_http_request_t *r) ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, "http filename: \"%s\"", path.data); + cln = ngx_pool_cleanup_add(r->pool, sizeof(ngx_pool_cleanup_file_t)); + if (cln == NULL) { + return NGX_HTTP_INTERNAL_SERVER_ERROR; + } + fd = ngx_open_file(path.data, NGX_FILE_RDONLY, NGX_FILE_OPEN); if (fd == NGX_INVALID_FILE) { @@ -223,18 +229,12 @@ ngx_http_static_handler(ngx_http_request_t *r) log->action = "sending response to client"; - cln = ngx_palloc(r->pool, sizeof(ngx_pool_cleanup_file_t)); - if (cln == NULL) { - return NGX_HTTP_INTERNAL_SERVER_ERROR; - } + cln->handler = ngx_pool_cleanup_file; + clnf = cln->data; - cln->fd = fd; - cln->name = path.data; - cln->log = r->pool->log; - - if (ngx_pool_cleanup_add(r->pool, ngx_pool_cleanup_file, cln) == NULL) { - return NGX_HTTP_INTERNAL_SERVER_ERROR; - } + clnf->fd = fd; + clnf->name = path.data; + clnf->log = r->pool->log; r->headers_out.status = NGX_HTTP_OK; r->headers_out.content_length_n = ngx_file_size(&fi); diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c index dcb3956e1..867bf3118 100644 --- a/src/http/ngx_http.c +++ b/src/http/ngx_http.c @@ -659,6 +659,8 @@ ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) #endif ls->backlog = in_addr[a].conf.backlog; + ls->rcvbuf = in_addr[a].conf.rcvbuf; + ls->sndbuf = in_addr[a].conf.sndbuf; #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER) ls->accept_filter = in_addr[a].conf.accept_filter; diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index 4c6cfc073..21224d389 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -152,11 +152,7 @@ static ngx_command_t ngx_http_core_commands[] = { NULL }, { ngx_string("listen"), -#if 0 - NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_1MORE, -#else NGX_HTTP_SRV_CONF|NGX_CONF_1MORE, -#endif ngx_http_core_listen, NGX_HTTP_SRV_CONF_OFFSET, 0, @@ -2010,7 +2006,7 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) ngx_http_core_srv_conf_t *scf = conf; char *err; - ngx_str_t *value; + ngx_str_t *value, size; ngx_uint_t n; struct hostent *h; ngx_http_listen_t *ls; @@ -2050,6 +2046,8 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) ls->file_name = cf->conf_file->file.name; ls->line = cf->conf_file->line; ls->conf.backlog = -1; + ls->conf.rcvbuf = -1; + ls->conf.sndbuf = -1; if (inet_upstream.host.len) { inet_upstream.host.data[inet_upstream.host.len] = '\0'; @@ -2100,8 +2098,8 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) continue; } - if (ngx_strncmp(value[n].data, "bl=", 3) == 0) { - ls->conf.backlog = ngx_atoi(value[n].data + 3, value[n].len - 3); + if (ngx_strncmp(value[n].data, "backlog=", 8) == 0) { + ls->conf.backlog = ngx_atoi(value[n].data + 8, value[n].len - 8); ls->conf.bind = 1; if (ls->conf.backlog == NGX_ERROR || ls->conf.backlog == 0) { @@ -2113,9 +2111,41 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) continue; } - if (ngx_strncmp(value[n].data, "af=", 3) == 0) { + if (ngx_strncmp(value[n].data, "rcvbuf=", 7) == 0) { + size.len = value[n].len - 7; + size.data = value[n].data + 7; + + ls->conf.rcvbuf = ngx_parse_size(&size); + ls->conf.bind = 1; + + if (ls->conf.rcvbuf == NGX_ERROR) { + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "invalid rcvbuf \"%V\"", &value[n]); + return NGX_CONF_ERROR; + } + + continue; + } + + if (ngx_strncmp(value[n].data, "sndbuf=", 7) == 0) { + size.len = value[n].len - 7; + size.data = value[n].data + 7; + + ls->conf.sndbuf = ngx_parse_size(&size); + ls->conf.bind = 1; + + if (ls->conf.sndbuf == NGX_ERROR) { + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "invalid sndbuf \"%V\"", &value[n]); + return NGX_CONF_ERROR; + } + + continue; + } + + if (ngx_strncmp(value[n].data, "accept_filter=", 14) == 0) { #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER) - ls->conf.accept_filter = (char *) &value[n].data[3]; + ls->conf.accept_filter = (char *) &value[n].data[14]; ls->conf.bind = 1; #else ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h index 4de800736..cf415efda 100644 --- a/src/http/ngx_http_core_module.h +++ b/src/http/ngx_http_core_module.h @@ -18,6 +18,8 @@ typedef struct { unsigned bind:1; int backlog; + int rcvbuf; + int sndbuf; #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER) char *accept_filter; diff --git a/src/http/ngx_http_log_module.c b/src/http/ngx_http_log_module.c index 3caa2e91e..617d46a7f 100644 --- a/src/http/ngx_http_log_module.c +++ b/src/http/ngx_http_log_module.c @@ -309,11 +309,11 @@ ngx_http_log_time(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) static u_char * ngx_http_log_msec(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op) { - struct timeval tv; + ngx_time_t *tp; - ngx_gettimeofday(&tv); + tp = ngx_timeofday(); - return ngx_sprintf(buf, "%l.%03l", tv.tv_sec, tv.tv_usec / 1000); + return ngx_sprintf(buf, "%T.%03M", tp->sec, tp->msec); } diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c index 2fb1764c8..9071ae5a4 100644 --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -163,15 +163,8 @@ ngx_http_init_connection(ngx_connection_t *c) /* the deferred accept(), rtsig, aio, iocp */ if (ngx_accept_mutex) { - if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) { - ngx_http_close_connection(c); - return; - } - - ngx_post_event(rev); - - ngx_mutex_unlock(ngx_posted_events_mutex); + ngx_post_event(rev, &ngx_posted_events); #if (NGX_STAT_STUB) ngx_atomic_fetch_add(ngx_stat_reading, 1); diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c index a1c6a2e98..6d1bd497d 100644 --- a/src/http/ngx_http_upstream.c +++ b/src/http/ngx_http_upstream.c @@ -66,6 +66,8 @@ static size_t ngx_http_upstream_log_status_getlen(ngx_http_request_t *r, uintptr_t data); static u_char *ngx_http_upstream_log_status(ngx_http_request_t *r, u_char *buf, ngx_http_log_op_t *op); +static u_char *ngx_http_upstream_log_response_time(ngx_http_request_t *r, + u_char *buf, ngx_http_log_op_t *op); static u_char *ngx_http_upstream_log_error(ngx_http_request_t *r, u_char *buf, size_t len); @@ -204,6 +206,8 @@ static ngx_http_log_op_name_t ngx_http_upstream_log_fmt_ops[] = { { ngx_string("upstream_status"), 0, NULL, ngx_http_upstream_log_status_getlen, ngx_http_upstream_log_status }, + { ngx_string("upstream_response_time"), NGX_TIME_T_LEN + 4, NULL, NULL, + ngx_http_upstream_log_response_time }, { ngx_null_string, 0, NULL, NULL, NULL } }; @@ -217,6 +221,7 @@ char *ngx_http_upstream_header_errors[] = { void ngx_http_upstream_init(ngx_http_request_t *r) { + ngx_time_t *tp; ngx_connection_t *c; ngx_http_upstream_t *u; ngx_http_core_loc_conf_t *clcf; @@ -286,6 +291,10 @@ ngx_http_upstream_init(ngx_http_request_t *r) ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t)); + tp = ngx_timeofday(); + + u->state->response_time = tp->sec * 1000 + tp->msec; + ngx_http_upstream_connect(r, u); } @@ -978,6 +987,8 @@ ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u) ngx_list_part_t *part; ngx_table_elt_t *h; ngx_event_pipe_t *p; + ngx_pool_cleanup_t *cl; + ngx_pool_cleanup_file_t *clf; ngx_http_core_loc_conf_t *clcf; ngx_http_upstream_header_t *hh; ngx_http_upstream_main_conf_t *umcf; @@ -1033,6 +1044,20 @@ ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u) u->header_sent = 1; + if (r->request_body->temp_file) { + for (cl = r->pool->cleanup; cl; cl = cl->next) { + if (cl->handler == ngx_pool_cleanup_file) { + clf = cl->data; + + if (clf->fd == r->request_body->temp_file->file.fd) { + cl->handler(clf); + cl->handler = NULL; + break; + } + } + } + } + /* TODO: preallocate event_pipe bufs, look "Content-Length" */ #if 0 @@ -1404,9 +1429,17 @@ static void ngx_http_upstream_finalize_request(ngx_http_request_t *r, ngx_http_upstream_t *u, ngx_int_t rc) { + ngx_time_t *tp; + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "finalize http upstream request: %i", rc); + if (u->state->response_time) { + tp = ngx_timeofday(); + u->state->response_time = tp->sec * 1000 + tp->msec + - u->state->response_time; + } + u->finalize_request(r, rc); if (u->peer.connection) { @@ -1419,8 +1452,7 @@ ngx_http_upstream_finalize_request(ngx_http_request_t *r, u->peer.connection = NULL; - if (u->header_sent - && (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE)) + if (u->header_sent && (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE)) { rc = 0; } @@ -1782,6 +1814,44 @@ ngx_http_upstream_log_status(ngx_http_request_t *r, u_char *buf, } +static u_char * +ngx_http_upstream_log_response_time(ngx_http_request_t *r, u_char *buf, + ngx_http_log_op_t *op) +{ + ngx_uint_t i; + ngx_http_upstream_t *u; + ngx_http_upstream_state_t *state; + + u = r->upstream; + + if (u == NULL) { + *buf = '-'; + return buf + 1; + } + + i = 0; + state = u->states.elts; + + for ( ;; ) { + if (state[i].status == 0) { + *buf++ = '-'; + + } else { + buf = ngx_sprintf(buf, "%d.%03d", + state[i].response_time / 1000, + state[i].response_time % 1000); + } + + if (++i == u->states.nelts) { + return buf; + } + + *buf++ = ','; + *buf++ = ' '; + } +} + + static u_char * ngx_http_upstream_log_error(ngx_http_request_t *r, u_char *buf, size_t len) { diff --git a/src/http/ngx_http_upstream.h b/src/http/ngx_http_upstream.h index dd7b3c177..637a38d51 100644 --- a/src/http/ngx_http_upstream.h +++ b/src/http/ngx_http_upstream.h @@ -29,12 +29,12 @@ typedef struct { - time_t bl_time; + ngx_msec_t bl_time; ngx_uint_t bl_state; ngx_uint_t status; - time_t time; - + ngx_msec_t response_time; + ngx_str_t *peer; } ngx_http_upstream_state_t; diff --git a/src/imap/ngx_imap_core_module.c b/src/imap/ngx_imap_core_module.c index 9d6629859..d037ad83b 100644 --- a/src/imap/ngx_imap_core_module.c +++ b/src/imap/ngx_imap_core_module.c @@ -411,6 +411,9 @@ ngx_imap_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) } ls->backlog = -1; + ls->rcvbuf = -1; + ls->sndbuf = -1; + ls->addr_ntop = 1; ls->handler = ngx_imap_init_connection; ls->pool_size = 256; diff --git a/src/imap/ngx_imap_ssl_module.c b/src/imap/ngx_imap_ssl_module.c index be6fca93b..d663e8850 100644 --- a/src/imap/ngx_imap_ssl_module.c +++ b/src/imap/ngx_imap_ssl_module.c @@ -17,6 +17,15 @@ static void *ngx_imap_ssl_create_conf(ngx_conf_t *cf); static char *ngx_imap_ssl_merge_conf(ngx_conf_t *cf, void *parent, void *child); +#if !defined (SSL_OP_CIPHER_SERVER_PREFERENCE) + +static char *ngx_imap_ssl_nosupported(ngx_conf_t *cf, ngx_command_t *cmd, + void *conf); + +static char ngx_imap_ssl_openssl097[] = "OpenSSL 0.9.7 and higher"; + +#endif + static ngx_conf_bitmask_t ngx_imap_ssl_protocols[] = { { ngx_string("SSLv2"), NGX_SSL_SSLv2 }, @@ -50,7 +59,7 @@ static ngx_command_t ngx_imap_ssl_commands[] = { NULL }, { ngx_string("ssl_protocols"), - NGX_IMAP_MAIN_CONF|NGX_IMAP_SRV_CONF|NGX_CONF_TAKE1, + NGX_IMAP_MAIN_CONF|NGX_IMAP_SRV_CONF|NGX_CONF_1MORE, ngx_conf_set_bitmask_slot, NGX_IMAP_SRV_CONF_OFFSET, offsetof(ngx_imap_ssl_conf_t, protocols), @@ -65,10 +74,15 @@ static ngx_command_t ngx_imap_ssl_commands[] = { { ngx_string("ssl_prefer_server_ciphers"), NGX_IMAP_MAIN_CONF|NGX_IMAP_SRV_CONF|NGX_CONF_FLAG, +#ifdef SSL_OP_CIPHER_SERVER_PREFERENCE ngx_conf_set_flag_slot, NGX_IMAP_SRV_CONF_OFFSET, offsetof(ngx_imap_ssl_conf_t, prefer_server_ciphers), NULL }, +#else + ngx_imap_ssl_nosupported, 0, 0, ngx_imap_ssl_openssl097 }, +#endif + ngx_null_command }; @@ -138,6 +152,8 @@ ngx_imap_ssl_merge_conf(ngx_conf_t *cf, void *parent, void *child) ngx_imap_ssl_conf_t *prev = parent; ngx_imap_ssl_conf_t *conf = child; + ngx_pool_cleanup_t *cln; + ngx_conf_merge_value(conf->enable, prev->enable, 0); if (conf->enable == 0) { @@ -166,20 +182,25 @@ ngx_imap_ssl_merge_conf(ngx_conf_t *cf, void *parent, void *child) return NGX_CONF_ERROR; } - if (ngx_pool_cleanup_add(cf->pool, ngx_ssl_cleanup_ctx, &conf->ssl) == NULL) - { + cln = ngx_pool_cleanup_add(cf->pool, 0); + if (cln == NULL) { return NGX_CONF_ERROR; } - if (ngx_ssl_certificate(&conf->ssl, conf->certificate.data, - conf->certificate_key.data) != NGX_OK) + cln->handler = ngx_ssl_cleanup_ctx; + cln->data = &conf->ssl; + + if (ngx_ssl_certificate(cf, &conf->ssl, &conf->certificate, + &conf->certificate_key) + != NGX_OK) { return NGX_CONF_ERROR; } if (conf->ciphers.len) { if (SSL_CTX_set_cipher_list(conf->ssl.ctx, - (const char *) conf->ciphers.data) == 0) + (const char *) conf->ciphers.data) + == 0) { ngx_ssl_error(NGX_LOG_EMERG, cf->log, 0, "SSL_CTX_set_cipher_list(\"%V\") failed", @@ -187,6 +208,14 @@ ngx_imap_ssl_merge_conf(ngx_conf_t *cf, void *parent, void *child) } } +#ifdef SSL_OP_CIPHER_SERVER_PREFERENCE + + if (conf->prefer_server_ciphers) { + SSL_CTX_set_options(conf->ssl.ctx, SSL_OP_CIPHER_SERVER_PREFERENCE); + } + +#endif + if (ngx_ssl_generate_rsa512_key(&conf->ssl) != NGX_OK) { return NGX_CONF_ERROR; } @@ -198,3 +227,18 @@ ngx_imap_ssl_merge_conf(ngx_conf_t *cf, void *parent, void *child) return NGX_CONF_OK; } + + +#if !defined (SSL_OP_CIPHER_SERVER_PREFERENCE) + +static char * +ngx_imap_ssl_nosupported(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) +{ + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, + "\"%V\" directive is available only in %s,", + &cmd->name, cmd->post); + + return NGX_CONF_ERROR; +} + +#endif diff --git a/src/os/unix/ngx_atomic.h b/src/os/unix/ngx_atomic.h index 5856103c6..3dfce74c4 100644 --- a/src/os/unix/ngx_atomic.h +++ b/src/os/unix/ngx_atomic.h @@ -33,6 +33,8 @@ ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add); /* the code in src/os/unix/ngx_sunpro_x86.il */ +#define ngx_memory_barrier() __asm (".volatile"); __asm (".nonvolatile") + #else /* ( __GNUC__ || __INTEL_COMPILER ) */ @@ -64,6 +66,8 @@ ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add); /* the code in src/os/unix/ngx_sunpro_amd64.il */ +#define ngx_memory_barrier() __asm (".volatile"); __asm (".nonvolatile") + #else /* ( __GNUC__ || __INTEL_COMPILER ) */ diff --git a/src/os/unix/ngx_channel.c b/src/os/unix/ngx_channel.c index 051f466fd..c7f12937f 100644 --- a/src/os/unix/ngx_channel.c +++ b/src/os/unix/ngx_channel.c @@ -207,6 +207,9 @@ ngx_add_channel_event(ngx_cycle_t *cycle, ngx_fd_t fd, ngx_int_t event, wev->own_lock = &c->lock; #endif + rev->channel = 1; + wev->channel = 1; + ev = (event == NGX_READ_EVENT) ? rev : wev; ev->handler = handler; diff --git a/src/os/unix/ngx_freebsd_rfork_thread.c b/src/os/unix/ngx_freebsd_rfork_thread.c index b7e803b3c..3c550fb8a 100644 --- a/src/os/unix/ngx_freebsd_rfork_thread.c +++ b/src/os/unix/ngx_freebsd_rfork_thread.c @@ -51,7 +51,8 @@ void **ngx_tls; /* the threads tls's array */ static int errno0; /* the main thread's errno */ static int *errnos; /* the threads errno's array */ -int *__error() +int * +__error() { int tid; @@ -72,7 +73,8 @@ int *__error() extern int __isthreaded; -void _spinlock(ngx_atomic_t *lock) +void +_spinlock(ngx_atomic_t *lock) { ngx_int_t tries; @@ -107,7 +109,8 @@ void _spinlock(ngx_atomic_t *lock) #ifndef _spinunlock -void _spinunlock(ngx_atomic_t *lock) +void +_spinunlock(ngx_atomic_t *lock) { *lock = 0; } @@ -115,8 +118,9 @@ void _spinunlock(ngx_atomic_t *lock) #endif -ngx_err_t ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), void *arg, - ngx_log_t *log) +ngx_err_t +ngx_create_thread(ngx_tid_t *tid, ngx_thread_value_t (*func)(void *arg), + void *arg, ngx_log_t *log) { ngx_pid_t id; ngx_err_t err; @@ -174,7 +178,8 @@ ngx_err_t ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), void *arg, } -ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle) +ngx_int_t +ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle) { char *red_zone, *zone; size_t len; @@ -264,7 +269,8 @@ ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle) } -ngx_tid_t ngx_thread_self() +ngx_tid_t +ngx_thread_self() { ngx_int_t tid; @@ -278,7 +284,8 @@ ngx_tid_t ngx_thread_self() } -ngx_err_t ngx_thread_key_create(ngx_tls_key_t *key) +ngx_err_t +ngx_thread_key_create(ngx_tls_key_t *key) { if (nkeys >= NGX_THREAD_KEYS_MAX) { return NGX_ENOMEM; @@ -290,7 +297,8 @@ ngx_err_t ngx_thread_key_create(ngx_tls_key_t *key) } -ngx_err_t ngx_thread_set_tls(ngx_tls_key_t key, void *value) +ngx_err_t +ngx_thread_set_tls(ngx_tls_key_t key, void *value) { if (key >= NGX_THREAD_KEYS_MAX) { return NGX_EINVAL; @@ -301,7 +309,8 @@ ngx_err_t ngx_thread_set_tls(ngx_tls_key_t key, void *value) } -ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags) +ngx_mutex_t * +ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags) { ngx_mutex_t *m; union semun op; @@ -342,7 +351,8 @@ ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags) } -void ngx_mutex_destroy(ngx_mutex_t *m) +void +ngx_mutex_destroy(ngx_mutex_t *m) { if (semctl(m->semid, 0, IPC_RMID) == -1) { ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno, @@ -353,7 +363,8 @@ void ngx_mutex_destroy(ngx_mutex_t *m) } -ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try) +ngx_int_t +ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try) { uint32_t lock, old; ngx_uint_t tries; @@ -414,7 +425,7 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try) "%D threads wait for mutex %p, " "while only %ui threads are available", lock & ~NGX_MUTEX_LOCK_BUSY, m, nthreads); - return NGX_ERROR; + ngx_abort(); } if (ngx_atomic_cmp_set(&m->lock, old, lock)) { @@ -436,7 +447,7 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try) if (semop(m->semid, &op, 1) == -1) { ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno, "semop() failed while waiting on mutex %p", m); - return NGX_ERROR; + ngx_abort(); } ngx_log_debug2(NGX_LOG_DEBUG_MUTEX, m->log, 0, @@ -483,13 +494,14 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try) } -ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m) +void +ngx_mutex_unlock(ngx_mutex_t *m) { uint32_t lock, old; struct sembuf op; if (!ngx_threaded) { - return NGX_OK; + return; } old = m->lock; @@ -497,7 +509,7 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m) if (!(old & NGX_MUTEX_LOCK_BUSY)) { ngx_log_error(NGX_LOG_ALERT, m->log, 0, "trying to unlock the free mutex %p", m); - return NGX_ERROR; + ngx_abort(); } /* free the mutex */ @@ -521,7 +533,7 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m) ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "mutex %p is unlocked", m); - return NGX_OK; + return; } /* check whether we need to wake up a waiting thread */ @@ -558,7 +570,7 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m) if (semop(m->semid, &op, 1) == -1) { ngx_log_error(NGX_LOG_ALERT, m->log, ngx_errno, "semop() failed while waking up on mutex %p", m); - return NGX_ERROR; + ngx_abort(); } break; @@ -570,11 +582,12 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m) ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "mutex %p is unlocked", m); - return NGX_OK; + return; } -ngx_cond_t *ngx_cond_init(ngx_log_t *log) +ngx_cond_t * +ngx_cond_init(ngx_log_t *log) { ngx_cond_t *cv; @@ -592,7 +605,8 @@ ngx_cond_t *ngx_cond_init(ngx_log_t *log) } -void ngx_cond_destroy(ngx_cond_t *cv) +void +ngx_cond_destroy(ngx_cond_t *cv) { if (close(cv->kq) == -1) { ngx_log_error(NGX_LOG_ALERT, cv->log, ngx_errno, @@ -603,7 +617,8 @@ void ngx_cond_destroy(ngx_cond_t *cv) } -ngx_int_t ngx_cond_wait(ngx_cond_t *cv, ngx_mutex_t *m) +ngx_int_t +ngx_cond_wait(ngx_cond_t *cv, ngx_mutex_t *m) { int n; ngx_err_t err; @@ -647,9 +662,7 @@ ngx_int_t ngx_cond_wait(ngx_cond_t *cv, ngx_mutex_t *m) cv->tid = ngx_thread_self(); } - if (ngx_mutex_unlock(m) == NGX_ERROR) { - return NGX_ERROR; - } + ngx_mutex_unlock(m); ngx_log_debug3(NGX_LOG_DEBUG_CORE, cv->log, 0, "cv %p wait, kq:%d, signo:%d", cv, cv->kq, cv->signo); @@ -703,15 +716,14 @@ ngx_int_t ngx_cond_wait(ngx_cond_t *cv, ngx_mutex_t *m) ngx_log_debug1(NGX_LOG_DEBUG_CORE, cv->log, 0, "cv %p is waked up", cv); - if (ngx_mutex_lock(m) == NGX_ERROR) { - return NGX_ERROR; - } + ngx_mutex_lock(m); return NGX_OK; } -ngx_int_t ngx_cond_signal(ngx_cond_t *cv) +ngx_int_t +ngx_cond_signal(ngx_cond_t *cv) { ngx_err_t err; diff --git a/src/os/unix/ngx_freebsd_rfork_thread.h b/src/os/unix/ngx_freebsd_rfork_thread.h index 79e748a00..20957a5ff 100644 --- a/src/os/unix/ngx_freebsd_rfork_thread.h +++ b/src/os/unix/ngx_freebsd_rfork_thread.h @@ -55,7 +55,8 @@ extern char *ngx_freebsd_kern_usrstack; extern size_t ngx_thread_stack_size; -static ngx_inline ngx_int_t ngx_gettid() +static ngx_inline ngx_int_t +ngx_gettid() { char *sp; @@ -97,7 +98,8 @@ ngx_err_t ngx_thread_set_tls(ngx_tls_key_t key, void *value); #define ngx_thread_set_tls_n "the tls key setting" -static void *ngx_thread_get_tls(ngx_tls_key_t key) +static void * +ngx_thread_get_tls(ngx_tls_key_t key) { if (key >= NGX_THREAD_KEYS_MAX) { return NULL; @@ -108,9 +110,9 @@ static void *ngx_thread_get_tls(ngx_tls_key_t key) #define ngx_mutex_trylock(m) ngx_mutex_dolock(m, 1) -#define ngx_mutex_lock(m) ngx_mutex_dolock(m, 0) +#define ngx_mutex_lock(m) (void) ngx_mutex_dolock(m, 0) ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try); -ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m); +void ngx_mutex_unlock(ngx_mutex_t *m); typedef int (*ngx_rfork_thread_func_pt)(void *arg); diff --git a/src/os/unix/ngx_gcc_atomic_amd64.h b/src/os/unix/ngx_gcc_atomic_amd64.h index 07b2d50b5..374e3b8ff 100644 --- a/src/os/unix/ngx_gcc_atomic_amd64.h +++ b/src/os/unix/ngx_gcc_atomic_amd64.h @@ -72,3 +72,6 @@ ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add) return add; } + + +#define ngx_memory_barrier() __asm__ volatile ("" ::: "memory") diff --git a/src/os/unix/ngx_gcc_atomic_ppc.h b/src/os/unix/ngx_gcc_atomic_ppc.h index 8fc3bc041..58b24c31a 100644 --- a/src/os/unix/ngx_gcc_atomic_ppc.h +++ b/src/os/unix/ngx_gcc_atomic_ppc.h @@ -64,3 +64,10 @@ ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add) return res; } + + +#if (NGX_SMP) +#define ngx_memory_barrier() __asm__ volatile ("sync\n" ::: "memory") +#else +#define ngx_memory_barrier() __asm__ volatile ("" ::: "memory") +#endif diff --git a/src/os/unix/ngx_gcc_atomic_sparc64.h b/src/os/unix/ngx_gcc_atomic_sparc64.h index c7022a930..8314318e7 100644 --- a/src/os/unix/ngx_gcc_atomic_sparc64.h +++ b/src/os/unix/ngx_gcc_atomic_sparc64.h @@ -67,3 +67,13 @@ ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add) old = res; } } + + +#if (NGX_SMP) +#define ngx_memory_barrier() \ + __asm__ volatile ( \ + "membar #LoadLoad | #LoadStore | #StoreStore | #StoreLoad" \ + ::: "memory") +#else +#define ngx_memory_barrier() __asm__ volatile ("" ::: "memory") +#endif diff --git a/src/os/unix/ngx_gcc_atomic_x86.h b/src/os/unix/ngx_gcc_atomic_x86.h index e3c0c9379..3053e72ff 100644 --- a/src/os/unix/ngx_gcc_atomic_x86.h +++ b/src/os/unix/ngx_gcc_atomic_x86.h @@ -101,3 +101,11 @@ ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add) } #endif + + +/* + * on x86 the write operations go in a program order, so we need only + * to disable the gcc reorder optimizations + */ + +#define ngx_memory_barrier() __asm__ volatile ("" ::: "memory") diff --git a/src/os/unix/ngx_linux_config.h b/src/os/unix/ngx_linux_config.h index d3ef3258b..ac7d7a8df 100644 --- a/src/os/unix/ngx_linux_config.h +++ b/src/os/unix/ngx_linux_config.h @@ -98,11 +98,6 @@ extern ssize_t sendfile(int s, int fd, int32_t *offset, size_t size); #endif -#ifndef NGX_HAVE_SELECT_CHANGE_TIMEOUT -#define NGX_HAVE_SELECT_CHANGE_TIMEOUT 1 -#endif - - #define NGX_HAVE_OS_SPECIFIC_INIT 1 diff --git a/src/os/unix/ngx_posix_init.c b/src/os/unix/ngx_posix_init.c index f20f44cec..4a2b581be 100644 --- a/src/os/unix/ngx_posix_init.c +++ b/src/os/unix/ngx_posix_init.c @@ -50,7 +50,7 @@ ngx_os_init(ngx_log_t *log) return NGX_ERROR; } - ngx_max_sockets = rlmt.rlim_cur; + ngx_max_sockets = (ngx_int_t) rlmt.rlim_cur; #if (NGX_HAVE_INHERITED_NONBLOCK) ngx_inherited_nonblocking = 1; diff --git a/src/os/unix/ngx_process.c b/src/os/unix/ngx_process.c index 07a7c66f5..5e88ef38f 100644 --- a/src/os/unix/ngx_process.c +++ b/src/os/unix/ngx_process.c @@ -282,7 +282,6 @@ void ngx_signal_handler(int signo) { char *action; - struct timeval tv; ngx_int_t ignore; ngx_err_t err; ngx_signal_t *sig; @@ -297,8 +296,7 @@ ngx_signal_handler(int signo) } } - ngx_gettimeofday(&tv); - ngx_time_update(tv.tv_sec); + ngx_time_update(0, 0); action = ""; @@ -456,6 +454,7 @@ ngx_process_get_status(void) if (err == NGX_ECHILD) { ngx_log_error(NGX_LOG_INFO, ngx_cycle->log, errno, "waitpid() failed"); + return; } #endif @@ -527,6 +526,6 @@ ngx_debug_point(void) break; case NGX_DEBUG_POINTS_ABORT: - abort(); + ngx_abort(); } } diff --git a/src/os/unix/ngx_process_cycle.c b/src/os/unix/ngx_process_cycle.c index 029de436f..f4ec06f9b 100644 --- a/src/os/unix/ngx_process_cycle.c +++ b/src/os/unix/ngx_process_cycle.c @@ -21,7 +21,7 @@ static void ngx_worker_process_init(ngx_cycle_t *cycle, ngx_uint_t priority); static void ngx_channel_handler(ngx_event_t *ev); #if (NGX_THREADS) static void ngx_wakeup_worker_threads(ngx_cycle_t *cycle); -static void *ngx_worker_thread_cycle(void *data); +static ngx_thread_value_t ngx_worker_thread_cycle(void *data); #endif #if 0 static void ngx_garbage_collector_cycle(ngx_cycle_t *cycle, void *data); @@ -69,7 +69,6 @@ ngx_master_process_cycle(ngx_cycle_t *cycle) ngx_int_t i; ngx_uint_t n; sigset_t set; - struct timeval tv; struct itimerval itv; ngx_uint_t live; ngx_msec_t delay; @@ -145,8 +144,7 @@ ngx_master_process_cycle(ngx_cycle_t *cycle) sigsuspend(&set); - ngx_gettimeofday(&tv); - ngx_time_update(tv.tv_sec); + ngx_time_update(0, 0); ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "wake up"); @@ -275,7 +273,7 @@ ngx_single_process_cycle(ngx_cycle_t *cycle) for ( ;; ) { ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle"); - ngx_process_events(cycle); + ngx_process_events_and_timers(cycle); if (ngx_terminate || ngx_quit) { ngx_master_exit(cycle); @@ -645,6 +643,8 @@ ngx_master_exit(ngx_cycle_t *cycle) static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data) { + ngx_uint_t i; + ngx_connection_t *c; #if (NGX_THREADS) ngx_int_t n; ngx_err_t err; @@ -657,11 +657,6 @@ ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data) #if (NGX_THREADS) - if (ngx_time_mutex_init(cycle->log) == NGX_ERROR) { - /* fatal */ - exit(2); - } - ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); if (ngx_threads_n) { @@ -731,7 +726,7 @@ ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data) ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle"); - ngx_process_events(cycle); + ngx_process_events_and_timers(cycle); if (ngx_terminate) { ngx_log_error(NGX_LOG_NOTICE, cycle->log, 0, "exiting"); @@ -740,6 +735,21 @@ ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data) ngx_wakeup_worker_threads(cycle); #endif + c = cycle->connections; + for (i = 0; i < cycle->connection_n; i++) { + if (c[i].fd != -1 + && c[i].read + && !c[i].read->accept + && !c[i].read->channel) + { + ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, + "open socket #%d left in %ui connection, " + "aborting", + c[i].fd, i); + ngx_abort(); + } + } + /* * we do not destroy cycle->pool here because a signal handler * that uses cycle->log can be called at this point @@ -1054,7 +1064,7 @@ ngx_wakeup_worker_threads(ngx_cycle_t *cycle) } -static void * +static ngx_thread_value_t ngx_worker_thread_cycle(void *data) { ngx_thread_t *thr = data; @@ -1075,7 +1085,7 @@ ngx_worker_thread_cycle(void *data) if (err) { ngx_log_error(NGX_LOG_ALERT, cycle->log, err, ngx_thread_sigmask_n " failed"); - return (void *) 1; + return (ngx_thread_value_t) 1; } ngx_log_debug1(NGX_LOG_DEBUG_CORE, cycle->log, 0, @@ -1085,25 +1095,23 @@ ngx_worker_thread_cycle(void *data) tls = ngx_calloc(sizeof(ngx_core_tls_t), cycle->log); if (tls == NULL) { - return (void *) 1; + return (ngx_thread_value_t) 1; } err = ngx_thread_set_tls(ngx_core_tls_key, tls); if (err != 0) { ngx_log_error(NGX_LOG_ALERT, cycle->log, err, ngx_thread_set_tls_n " failed"); - return (void *) 1; + return (ngx_thread_value_t) 1; } - if (ngx_mutex_lock(ngx_posted_events_mutex) == NGX_ERROR) { - return (void *) 1; - } + ngx_mutex_lock(ngx_posted_events_mutex); for ( ;; ) { thr->state = NGX_THREAD_FREE; if (ngx_cond_wait(thr->cv, ngx_posted_events_mutex) == NGX_ERROR) { - return (void *) 1; + return (ngx_thread_value_t) 1; } if (ngx_terminate) { @@ -1115,22 +1123,22 @@ ngx_worker_thread_cycle(void *data) "thread " NGX_TID_T_FMT " is done", ngx_thread_self()); - return (void *) 0; + return (ngx_thread_value_t) 0; } thr->state = NGX_THREAD_BUSY; if (ngx_event_thread_process_posted(cycle) == NGX_ERROR) { - return (void *) 1; + return (ngx_thread_value_t) 1; } if (ngx_event_thread_process_posted(cycle) == NGX_ERROR) { - return (void *) 1; + return (ngx_thread_value_t) 1; } if (ngx_process_changes) { if (ngx_process_changes(cycle, 1) == NGX_ERROR) { - return (void *) 1; + return (ngx_thread_value_t) 1; } } } @@ -1185,7 +1193,7 @@ ngx_garbage_collector_cycle(ngx_cycle_t *cycle, void *data) ngx_add_timer(ev, 60 * 60 * 1000); - ngx_process_events(cycle); + ngx_process_events_and_timers(cycle); } } diff --git a/src/os/unix/ngx_pthread_thread.c b/src/os/unix/ngx_pthread_thread.c index 0b55c7192..c91e65d58 100644 --- a/src/os/unix/ngx_pthread_thread.c +++ b/src/os/unix/ngx_pthread_thread.c @@ -15,8 +15,9 @@ static ngx_uint_t max_threads; static pthread_attr_t thr_attr; -ngx_err_t ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), void *arg, - ngx_log_t *log) +ngx_err_t +ngx_create_thread(ngx_tid_t *tid, ngx_thread_value_t (*func)(void *arg), + void *arg, ngx_log_t *log) { int err; @@ -42,7 +43,8 @@ ngx_err_t ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), void *arg, } -ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle) +ngx_int_t +ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle) { int err; @@ -70,7 +72,8 @@ ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle) } -ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags) +ngx_mutex_t * +ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags) { int err; ngx_mutex_t *m; @@ -94,7 +97,8 @@ ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags) } -void ngx_mutex_destroy(ngx_mutex_t *m) +void +ngx_mutex_destroy(ngx_mutex_t *m) { int err; @@ -109,12 +113,13 @@ void ngx_mutex_destroy(ngx_mutex_t *m) } -ngx_int_t ngx_mutex_lock(ngx_mutex_t *m) +void +ngx_mutex_lock(ngx_mutex_t *m) { int err; if (!ngx_threaded) { - return NGX_OK; + return; } ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "lock mutex %p", m); @@ -124,16 +129,17 @@ ngx_int_t ngx_mutex_lock(ngx_mutex_t *m) if (err != 0) { ngx_log_error(NGX_LOG_ALERT, m->log, err, "pthread_mutex_lock(%p) failed", m); - return NGX_ERROR; + ngx_abort(); } ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "mutex %p is locked", m); - return NGX_OK; + return; } -ngx_int_t ngx_mutex_trylock(ngx_mutex_t *m) +ngx_int_t +ngx_mutex_trylock(ngx_mutex_t *m) { int err; @@ -152,7 +158,7 @@ ngx_int_t ngx_mutex_trylock(ngx_mutex_t *m) if (err != 0) { ngx_log_error(NGX_LOG_ALERT, m->log, err, "pthread_mutex_trylock(%p) failed", m); - return NGX_ERROR; + ngx_abort(); } ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "mutex %p is locked", m); @@ -161,12 +167,13 @@ ngx_int_t ngx_mutex_trylock(ngx_mutex_t *m) } -ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m) +void +ngx_mutex_unlock(ngx_mutex_t *m) { int err; if (!ngx_threaded) { - return NGX_OK; + return; } ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "unlock mutex %p", m); @@ -176,16 +183,17 @@ ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m) if (err != 0) { ngx_log_error(NGX_LOG_ALERT, m->log, err, "pthread_mutex_unlock(%p) failed", m); - return NGX_ERROR; + ngx_abort(); } ngx_log_debug1(NGX_LOG_DEBUG_MUTEX, m->log, 0, "mutex %p is unlocked", m); - return NGX_OK; + return; } -ngx_cond_t *ngx_cond_init(ngx_log_t *log) +ngx_cond_t * +ngx_cond_init(ngx_log_t *log) { int err; ngx_cond_t *cv; @@ -209,7 +217,8 @@ ngx_cond_t *ngx_cond_init(ngx_log_t *log) } -void ngx_cond_destroy(ngx_cond_t *cv) +void +ngx_cond_destroy(ngx_cond_t *cv) { int err; @@ -224,7 +233,8 @@ void ngx_cond_destroy(ngx_cond_t *cv) } -ngx_int_t ngx_cond_wait(ngx_cond_t *cv, ngx_mutex_t *m) +ngx_int_t +ngx_cond_wait(ngx_cond_t *cv, ngx_mutex_t *m) { int err; @@ -246,7 +256,8 @@ ngx_int_t ngx_cond_wait(ngx_cond_t *cv, ngx_mutex_t *m) } -ngx_int_t ngx_cond_signal(ngx_cond_t *cv) +ngx_int_t +ngx_cond_signal(ngx_cond_t *cv) { int err; diff --git a/src/os/unix/ngx_socket.c b/src/os/unix/ngx_socket.c index 121958977..60885ddd5 100644 --- a/src/os/unix/ngx_socket.c +++ b/src/os/unix/ngx_socket.c @@ -13,7 +13,7 @@ * while fcntl(F_SETFL, ~O_NONBLOCK) needs to learn before * the previous state using fcntl(F_GETFL). * - * ioctl() and fcntl() are syscalls on at least FreeBSD 2.x, Linux 2.2 + * ioctl() and fcntl() are syscalls at least in FreeBSD 2.x, Linux 2.2 * and Solaris 7. * * ioctl() in Linux 2.4 and 2.6 uses BKL, however, fcntl(F_SETFL) uses it too. @@ -73,6 +73,7 @@ ngx_tcp_push(ngx_socket_t s) #elif (NGX_LINUX) + int ngx_tcp_nopush(ngx_socket_t s) { @@ -84,6 +85,7 @@ ngx_tcp_nopush(ngx_socket_t s) (const void *) &cork, sizeof(int)); } + int ngx_tcp_push(ngx_socket_t s) { @@ -103,6 +105,7 @@ ngx_tcp_nopush(ngx_socket_t s) return 0; } + int ngx_tcp_push(ngx_socket_t s) { diff --git a/src/os/unix/ngx_sunpro_atomic_sparc64.h b/src/os/unix/ngx_sunpro_atomic_sparc64.h index e634416ab..6b4ce84b9 100644 --- a/src/os/unix/ngx_sunpro_atomic_sparc64.h +++ b/src/os/unix/ngx_sunpro_atomic_sparc64.h @@ -50,3 +50,9 @@ ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add) old = res; } } + + +#define ngx_memory_barrier() \ + __asm (".volatile"); \ + __asm ("membar #LoadLoad | #LoadStore | #StoreStore | #StoreLoad"); \ + __asm (".nonvolatile") diff --git a/src/os/unix/ngx_thread.h b/src/os/unix/ngx_thread.h index e630b356e..5171be6e8 100644 --- a/src/os/unix/ngx_thread.h +++ b/src/os/unix/ngx_thread.h @@ -66,8 +66,8 @@ typedef struct { ngx_int_t ngx_mutex_trylock(ngx_mutex_t *m); -ngx_int_t ngx_mutex_lock(ngx_mutex_t *m); -ngx_int_t ngx_mutex_unlock(ngx_mutex_t *m); +void ngx_mutex_lock(ngx_mutex_t *m); +void ngx_mutex_unlock(ngx_mutex_t *m); #endif @@ -90,10 +90,11 @@ extern ngx_int_t ngx_threads_n; extern volatile ngx_thread_t ngx_threads[NGX_MAX_THREADS]; -ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle); -ngx_err_t ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), void *arg, - ngx_log_t *log); +typedef void * ngx_thread_value_t; +ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle); +ngx_err_t ngx_create_thread(ngx_tid_t *tid, + ngx_thread_value_t (*func)(void *arg), void *arg, ngx_log_t *log); ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags); void ngx_mutex_destroy(ngx_mutex_t *m); @@ -113,7 +114,7 @@ ngx_int_t ngx_cond_signal(ngx_cond_t *cv); #define NGX_TID_T_FMT "%d" #define ngx_mutex_trylock(m) NGX_OK -#define ngx_mutex_lock(m) NGX_OK +#define ngx_mutex_lock(m) #define ngx_mutex_unlock(m) #define ngx_cond_signal(cv) diff --git a/src/os/unix/ngx_time.c b/src/os/unix/ngx_time.c index 1b1a56697..927132da6 100644 --- a/src/os/unix/ngx_time.c +++ b/src/os/unix/ngx_time.c @@ -8,20 +8,16 @@ #include-void ngx_localtime(ngx_tm_t *tm) +void +ngx_localtime(time_t s, ngx_tm_t *tm) { #if (NGX_HAVE_LOCALTIME_R) - time_t now; - - now = ngx_time(); - (void) localtime_r(&now, tm); + (void) localtime_r(&s, tm); #else - time_t now; ngx_tm_t *t; - now = ngx_time(); - t = localtime(&now); + t = localtime(&s); *tm = *t; #endif @@ -31,40 +27,32 @@ void ngx_localtime(ngx_tm_t *tm) } -void ngx_libc_localtime(struct tm *tm) +void +ngx_libc_localtime(time_t s, struct tm *tm) { #if (NGX_HAVE_LOCALTIME_R) - time_t now; - - now = ngx_time(); - (void) localtime_r(&now, tm); + (void) localtime_r(&s, tm); #else - time_t now; struct tm *t; - now = ngx_time(); - t = localtime(&now); + t = localtime(&s); *tm = *t; #endif } -void ngx_libc_gmtime(struct tm *tm) +void +ngx_libc_gmtime(time_t s, struct tm *tm) { #if (NGX_HAVE_LOCALTIME_R) - time_t now; - - now = ngx_time(); - (void) gmtime_r(&now, tm); + (void) gmtime_r(&s, tm); #else - time_t now; struct tm *t; - now = ngx_time(); - t = gmtime(&now); + t = gmtime(&s); *tm = *t; #endif diff --git a/src/os/unix/ngx_time.h b/src/os/unix/ngx_time.h index f9fe3c52f..b31bd4753 100644 --- a/src/os/unix/ngx_time.h +++ b/src/os/unix/ngx_time.h @@ -52,9 +52,9 @@ typedef struct tm ngx_tm_t; #endif -void ngx_localtime(ngx_tm_t *tm); -void ngx_libc_localtime(struct tm *tm); -void ngx_libc_gmtime(struct tm *tm); +void ngx_localtime(time_t s, ngx_tm_t *tm); +void ngx_libc_localtime(time_t s, struct tm *tm); +void ngx_libc_gmtime(time_t s, struct tm *tm); #define ngx_gettimeofday(tp) (void) gettimeofday(tp, NULL); #define ngx_msleep(ms) (void) usleep(ms * 1000) diff --git a/src/os/win32/ngx_atomic.h b/src/os/win32/ngx_atomic.h index 87de57dd1..1e3334548 100644 --- a/src/os/win32/ngx_atomic.h +++ b/src/os/win32/ngx_atomic.h @@ -41,6 +41,9 @@ typedef volatile ngx_atomic_uint_t ngx_atomic_t; #define ngx_atomic_fetch_add(p, add) InterlockedExchangeAdd((long *) p, add) +#define ngx_memory_barrier() + + void ngx_spinlock(ngx_atomic_t *lock, ngx_uint_t spin); #define ngx_trylock(lock) (*(lock) == 0 && ngx_atomic_cmp_set(lock, 0, 1)) diff --git a/src/os/win32/ngx_process_cycle.c b/src/os/win32/ngx_process_cycle.c index 7eabefe5c..be363e258 100644 --- a/src/os/win32/ngx_process_cycle.c +++ b/src/os/win32/ngx_process_cycle.c @@ -10,7 +10,7 @@ #include -static void *ngx_worker_thread_cycle(void *data); +static ngx_thread_value_t __stdcall ngx_worker_thread_cycle(void *data); static long __stdcall ngx_window_procedure(HWND window, u_int message, u_int wparam, long lparam); @@ -202,7 +202,7 @@ ngx_single_process_cycle(ngx_cycle_t *cycle) } -static void * +static ngx_thread_value_t __stdcall ngx_worker_thread_cycle(void *data) { ngx_cycle_t *cycle; @@ -212,10 +212,10 @@ ngx_worker_thread_cycle(void *data) while (!ngx_quit) { ngx_log_debug0(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "worker cycle"); - ngx_process_events(cycle); + ngx_process_events_and_timers(cycle); } - return NULL; + return 0; } diff --git a/src/os/win32/ngx_thread.c b/src/os/win32/ngx_thread.c index 0703ac7d4..f8cedd2a5 100644 --- a/src/os/win32/ngx_thread.c +++ b/src/os/win32/ngx_thread.c @@ -14,13 +14,13 @@ ngx_int_t ngx_threads_n; static size_t stack_size; -ngx_err_t ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), void *arg, - ngx_log_t *log) +ngx_err_t +ngx_create_thread(ngx_tid_t *tid, + ngx_thread_value_t (__stdcall *func)(void *arg), void *arg, ngx_log_t *log) { ngx_err_t err; - *tid = CreateThread(NULL, stack_size, - (LPTHREAD_START_ROUTINE) func, arg, 0, NULL); + *tid = CreateThread(NULL, stack_size, func, arg, 0, NULL); if (*tid != NULL) { return 0; @@ -32,7 +32,8 @@ ngx_err_t ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), void *arg, } -ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle) +ngx_int_t +ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle) { stack_size = size; @@ -40,7 +41,8 @@ ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle) } -ngx_err_t ngx_thread_key_create(ngx_tls_key_t *key) +ngx_err_t +ngx_thread_key_create(ngx_tls_key_t *key) { *key = TlsAlloc(); @@ -52,7 +54,8 @@ ngx_err_t ngx_thread_key_create(ngx_tls_key_t *key) } -ngx_err_t ngx_thread_set_tls(ngx_tls_key_t *key, void *data) +ngx_err_t +ngx_thread_set_tls(ngx_tls_key_t *key, void *data) { if (TlsSetValue(*key, data) == 0) { return ngx_errno; @@ -62,7 +65,8 @@ ngx_err_t ngx_thread_set_tls(ngx_tls_key_t *key, void *data) } -ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags) +ngx_mutex_t * +ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags) { return (ngx_mutex_t *) 1; } @@ -70,15 +74,22 @@ ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags) /* STUB */ -ngx_int_t +void ngx_mutex_lock(ngx_mutex_t *m) { - return NGX_OK; + return; } + ngx_int_t ngx_mutex_trylock(ngx_mutex_t *m) { return NGX_OK; } + +void +ngx_mutex_unlock(ngx_mutex_t *m) { + return; +} + /**/ diff --git a/src/os/win32/ngx_thread.h b/src/os/win32/ngx_thread.h index b55dcca4d..3da1dc25c 100644 --- a/src/os/win32/ngx_thread.h +++ b/src/os/win32/ngx_thread.h @@ -14,6 +14,7 @@ typedef HANDLE ngx_tid_t; typedef DWORD ngx_tls_key_t; +typedef DWORD ngx_thread_value_t; typedef struct { @@ -22,8 +23,8 @@ typedef struct { } ngx_mutex_t; -ngx_err_t ngx_create_thread(ngx_tid_t *tid, void* (*func)(void *arg), - void *arg, ngx_log_t *log); +ngx_err_t ngx_create_thread(ngx_tid_t *tid, + ngx_thread_value_t (__stdcall *func)(void *arg), void *arg, ngx_log_t *log); ngx_int_t ngx_init_threads(int n, size_t size, ngx_cycle_t *cycle); ngx_err_t ngx_thread_key_create(ngx_tls_key_t *key); @@ -41,14 +42,13 @@ ngx_err_t ngx_thread_set_tls(ngx_tls_key_t *key, void *data); ngx_mutex_t *ngx_mutex_init(ngx_log_t *log, ngx_uint_t flags); -ngx_int_t ngx_mutex_lock(ngx_mutex_t *m); +void ngx_mutex_lock(ngx_mutex_t *m); ngx_int_t ngx_mutex_trylock(ngx_mutex_t *m); +void ngx_mutex_unlock(ngx_mutex_t *m); /* STUB */ #define NGX_MUTEX_LIGHT 0 - -#define ngx_mutex_unlock(m) /**/ diff --git a/src/os/win32/ngx_time.c b/src/os/win32/ngx_time.c index 04a1af6a3..39ce63336 100644 --- a/src/os/win32/ngx_time.c +++ b/src/os/win32/ngx_time.c @@ -8,7 +8,8 @@ #include -void ngx_gettimeofday(struct timeval *tp) +void +ngx_gettimeofday(struct timeval *tp) { uint64_t intervals; FILETIME ft; @@ -36,29 +37,28 @@ void ngx_gettimeofday(struct timeval *tp) } -void ngx_libc_localtime(struct tm *tm) +void +ngx_libc_localtime(time_t s, struct tm *tm) { - time_t now; struct tm *t; - now = ngx_time(); - t = localtime(&now); + t = localtime(&s); *tm = *t; } -void ngx_libc_gmtime(struct tm *tm) +void +ngx_libc_gmtime(time_t s, struct tm *tm) { - time_t now; struct tm *t; - now = ngx_time(); - t = gmtime(&now); + t = gmtime(&s); *tm = *t; } -ngx_int_t ngx_gettimezone(void) +ngx_int_t +ngx_gettimezone(void) { TIME_ZONE_INFORMATION tz; diff --git a/src/os/win32/ngx_time.h b/src/os/win32/ngx_time.h index 4c1498407..225c38cf0 100644 --- a/src/os/win32/ngx_time.h +++ b/src/os/win32/ngx_time.h @@ -40,8 +40,8 @@ typedef FILETIME ngx_mtime_t; #define NGX_HAVE_GETTIMEZONE 1 ngx_int_t ngx_gettimezone(void); -void ngx_libc_localtime(struct tm *tm); -void ngx_libc_gmtime(struct tm *tm); +void ngx_libc_localtime(time_t s, struct tm *tm); +void ngx_libc_gmtime(time_t s, struct tm *tm); void ngx_gettimeofday(struct timeval *tp); diff --git a/src/os/win32/ngx_win32_config.h b/src/os/win32/ngx_win32_config.h index a814acbdc..9658c1225 100644 --- a/src/os/win32/ngx_win32_config.h +++ b/src/os/win32/ngx_win32_config.h @@ -8,6 +8,10 @@ #define _NGX_WIN32_CONFIG_H_INCLUDED_ +#define WIN32 0x0400 +#define _WIN32_WINNT 0x0400 + + #define STRICT #define WIN32_LEAN_AND_MEAN