diff options
Diffstat (limited to 'src')
66 files changed, 325 insertions, 223 deletions
diff --git a/src/core/nginx.c b/src/core/nginx.c index 53ac666cd..887fc7997 100644 --- a/src/core/nginx.c +++ b/src/core/nginx.c @@ -112,7 +112,7 @@ ngx_uint_t ngx_max_module; -int main(int argc, char *const *argv, char *const *envp) +int main(int argc, char *const *argv) { ngx_int_t i; ngx_log_t *log; diff --git a/src/core/nginx.h b/src/core/nginx.h index 5f2339b6f..d737d6b63 100644 --- a/src/core/nginx.h +++ b/src/core/nginx.h @@ -8,7 +8,7 @@ #define _NGINX_H_INCLUDED_ -#define NGINX_VER "nginx/0.1.8" +#define NGINX_VER "nginx/0.1.9" #define NGINX_VAR "NGINX" #define NGX_NEWPID_EXT ".newbin" diff --git a/src/core/ngx_buf.c b/src/core/ngx_buf.c index 7d379890f..dedf4444e 100644 --- a/src/core/ngx_buf.c +++ b/src/core/ngx_buf.c @@ -140,7 +140,7 @@ void ngx_chain_update_chains(ngx_chain_t **free, ngx_chain_t **busy, break; } -#if (HAVE_WRITE_ZEROCOPY) +#if (NGX_HAVE_WRITE_ZEROCOPY) if ((*busy)->buf->zerocopy_busy) { break; } diff --git a/src/core/ngx_config.h b/src/core/ngx_config.h index 43fd985a2..916b1b514 100644 --- a/src/core/ngx_config.h +++ b/src/core/ngx_config.h @@ -11,6 +11,13 @@ #include <ngx_auto_headers.h> +#if ((__GNU__ == 2) && (__GNUC_MINOR__ < 8)) +#define NGX_MAX_UINT32_VALUE 0xffffffffLL +#else +#define NGX_MAX_UINT32_VALUE 0xffffffff +#endif + + #if defined __DragonFly__ && !defined __FreeBSD__ #define __FreeBSD__ 4 #define __FreeBSD_version 480101 @@ -127,12 +134,5 @@ typedef long ngx_flag_t; #define NGX_MAXHOSTNAMELEN MAXHOSTNAMELEN */ -#if ((__GNU__ == 2) && (__GNUC_MINOR__ < 8)) -#define NGX_MAX_UINT32_VALUE 0xffffffffLL -#else -#define NGX_MAX_UINT32_VALUE 0xffffffff -#endif - - #endif /* _NGX_CONFIG_H_INCLUDED_ */ diff --git a/src/core/ngx_connection.h b/src/core/ngx_connection.h index e2257ac6c..40f19a8d8 100644 --- a/src/core/ngx_connection.h +++ b/src/core/ngx_connection.h @@ -48,7 +48,7 @@ typedef struct { unsigned nonblocking_accept:1; unsigned nonblocking:1; unsigned shared:1; /* shared between threads or processes */ -#if (HAVE_DEFERRED_ACCEPT) +#if (NGX_HAVE_DEFERRED_ACCEPT) unsigned deferred_accept:1; #endif @@ -101,7 +101,7 @@ struct ngx_connection_s { ngx_ssl_t *ssl; #endif -#if (HAVE_IOCP) +#if (NGX_HAVE_IOCP) struct sockaddr *local_sockaddr; socklen_t local_socklen; #endif @@ -122,7 +122,7 @@ struct ngx_connection_s { unsigned tcp_nodelay:1; signed tcp_nopush:2; -#if (HAVE_IOCP) +#if (NGX_HAVE_IOCP) unsigned accept_context_updated:1; #endif diff --git a/src/core/ngx_output_chain.c b/src/core/ngx_output_chain.c index d2fbf12fb..1c367ccad 100644 --- a/src/core/ngx_output_chain.c +++ b/src/core/ngx_output_chain.c @@ -9,11 +9,18 @@ #include <ngx_event.h> -#define NGX_NONE 1 +#if 0 +#define NGX_SENDFILE_LIMIT 4096 +#endif + + +#define NGX_NONE 1 static ngx_inline ngx_int_t ngx_output_chain_need_to_copy(ngx_output_chain_ctx_t *ctx, ngx_buf_t *buf); +static ngx_int_t ngx_output_chain_add_copy(ngx_pool_t *pool, + ngx_chain_t **chain, ngx_chain_t *in); static ngx_int_t ngx_output_chain_copy_buf(ngx_buf_t *dst, ngx_buf_t *src, ngx_uint_t sendfile); @@ -26,17 +33,20 @@ ngx_int_t ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in) if (ctx->in == NULL && ctx->busy == NULL) { - /* - * the short path for the case when the ctx->in and ctx->busy chains - * are empty, the incoming chain is empty too or has the single buf - * that does not require the copy - */ + /* + * the short path for the case when the ctx->in and ctx->busy chains + * are empty, the incoming chain is empty too or has the single buf + * that does not require the copy + */ if (in == NULL) { return ctx->output_filter(ctx->filter_ctx, in); } if (in->next == NULL +#if (NGX_SENDFILE_LIMIT) + && !(in->buf->in_file && in->buf->file_last > NGX_SENDFILE_LIMIT) +#endif && (!ngx_output_chain_need_to_copy(ctx, in->buf))) { return ctx->output_filter(ctx->filter_ctx, in); @@ -46,7 +56,7 @@ ngx_int_t ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in) /* add the incoming buf to the chain ctx->in */ if (in) { - if (ngx_chain_add_copy(ctx->pool, &ctx->in, in) == NGX_ERROR) { + if (ngx_output_chain_add_copy(ctx->pool, &ctx->in, in) == NGX_ERROR) { return NGX_ERROR; } } @@ -191,11 +201,23 @@ ngx_int_t ngx_output_chain(ngx_output_chain_ctx_t *ctx, ngx_chain_t *in) static ngx_inline ngx_int_t ngx_output_chain_need_to_copy(ngx_output_chain_ctx_t *ctx, ngx_buf_t *buf) { + ngx_uint_t sendfile; + if (ngx_buf_special(buf)) { return 0; } - if (!ctx->sendfile) { + sendfile = ctx->sendfile; + +#if (NGX_SENDFILE_LIMIT) + + if (buf->in_file && buf->file_pos >= NGX_SENDFILE_LIMIT) { + sendfile = 0; + } + +#endif + + if (!sendfile) { if (!ngx_buf_in_memory(buf)) { return 1; @@ -216,6 +238,71 @@ static ngx_inline ngx_int_t } +static ngx_int_t ngx_output_chain_add_copy(ngx_pool_t *pool, + ngx_chain_t **chain, ngx_chain_t *in) +{ + ngx_chain_t *cl, **ll; +#if (NGX_SENDFILE_LIMIT) + ngx_buf_t *b, *buf; +#endif + + ll = chain; + + for (cl = *chain; cl; cl = cl->next) { + ll = &cl->next; + } + + while (in) { + + if (!(cl = ngx_alloc_chain_link(pool))) { + return NGX_ERROR; + } + +#if (NGX_SENDFILE_LIMIT) + + buf = in->buf; + + if (buf->in_file + && buf->file_pos < NGX_SENDFILE_LIMIT + && buf->file_last > NGX_SENDFILE_LIMIT) + { + if (!(b = ngx_calloc_buf(pool))) { + return NGX_ERROR; + } + + ngx_memcpy(b, buf, sizeof(ngx_buf_t)); + + if (ngx_buf_in_memory(buf)) { + buf->pos += (ssize_t) (NGX_SENDFILE_LIMIT - buf->file_pos); + b->last = buf->pos; + } + + buf->file_pos = NGX_SENDFILE_LIMIT; + b->file_last = NGX_SENDFILE_LIMIT; + + cl->buf = b; + + } else { + cl->buf = buf; + in = in->next; + } + +#else + cl->buf = in->buf; + in = in->next; + +#endif + + *ll = cl; + ll = &cl->next; + } + + *ll = NULL; + + return NGX_OK; +} + + static ngx_int_t ngx_output_chain_copy_buf(ngx_buf_t *dst, ngx_buf_t *src, ngx_uint_t sendfile) { @@ -228,6 +315,14 @@ static ngx_int_t ngx_output_chain_copy_buf(ngx_buf_t *dst, ngx_buf_t *src, size = dst->end - dst->pos; } +#if (NGX_SENDFILE_LIMIT) + + if (src->in_file && src->file_pos >= NGX_SENDFILE_LIMIT) { + sendfile = 0; + } + +#endif + if (ngx_buf_in_memory(src)) { ngx_memcpy(dst->pos, src->pos, size); src->pos += size; diff --git a/src/core/ngx_times.c b/src/core/ngx_times.c index f06d64476..5ca235ccf 100644 --- a/src/core/ngx_times.c +++ b/src/core/ngx_times.c @@ -162,12 +162,12 @@ void ngx_time_update(time_t s) ngx_cached_http_time.data = p; -#if (HAVE_GETTIMEZONE) +#if (NGX_HAVE_GETTIMEZONE) ngx_gmtoff = ngx_gettimezone(); ngx_gmtime(s + ngx_gmtoff * 60, &tm); -#elif (HAVE_GMTOFF) +#elif (NGX_HAVE_GMTOFF) ngx_localtime(&tm); ngx_gmtoff = tm.ngx_tm_gmtoff / 60; diff --git a/src/event/modules/ngx_aio_module.c b/src/event/modules/ngx_aio_module.c index 398c57102..bdd31cf9c 100644 --- a/src/event/modules/ngx_aio_module.c +++ b/src/event/modules/ngx_aio_module.c @@ -9,7 +9,7 @@ #include <ngx_event.h> #include <ngx_aio.h> -#if (HAVE_KQUEUE) +#if (NGX_HAVE_KQUEUE) #include <ngx_kqueue_module.h> #endif @@ -27,7 +27,7 @@ ngx_os_io_t ngx_os_aio = { ngx_aio_read_chain, ngx_aio_write, ngx_aio_write_chain, - NGX_HAVE_ZEROCOPY + 0 }; @@ -64,7 +64,7 @@ ngx_module_t ngx_aio_module = { -#if (HAVE_KQUEUE) +#if (NGX_HAVE_KQUEUE) static int ngx_aio_init(ngx_cycle_t *cycle) { @@ -152,7 +152,7 @@ static int ngx_aio_process_events(ngx_cycle_t *cycle) return ngx_kqueue_module_ctx.actions.process_events(cycle); } -#endif /* HAVE_KQUEUE */ +#endif /* NGX_HAVE_KQUEUE */ #if 0 diff --git a/src/event/modules/ngx_devpoll_module.c b/src/event/modules/ngx_devpoll_module.c index 663e2bfef..1a48ceccf 100644 --- a/src/event/modules/ngx_devpoll_module.c +++ b/src/event/modules/ngx_devpoll_module.c @@ -9,7 +9,7 @@ #include <ngx_event.h> -#if (TEST_BUILD_DEVPOLL) +#if (NGX_TEST_BUILD_DEVPOLL) /* Solaris declarations */ diff --git a/src/event/modules/ngx_epoll_module.c b/src/event/modules/ngx_epoll_module.c index 8096932ec..a2eeab08d 100644 --- a/src/event/modules/ngx_epoll_module.c +++ b/src/event/modules/ngx_epoll_module.c @@ -9,7 +9,7 @@ #include <ngx_event.h> -#if (TEST_BUILD_EPOLL) +#if (NGX_TEST_BUILD_EPOLL) /* epoll declarations */ @@ -168,7 +168,7 @@ static int ngx_epoll_init(ngx_cycle_t *cycle) ngx_event_actions = ngx_epoll_module_ctx.actions; -#if (HAVE_CLEAR_EVENT) +#if (NGX_HAVE_CLEAR_EVENT) ngx_event_flags = NGX_USE_CLEAR_EVENT #else ngx_event_flags = NGX_USE_LEVEL_EVENT diff --git a/src/event/modules/ngx_kqueue_module.c b/src/event/modules/ngx_kqueue_module.c index e0fae6f93..49c22a982 100644 --- a/src/event/modules/ngx_kqueue_module.c +++ b/src/event/modules/ngx_kqueue_module.c @@ -189,7 +189,7 @@ static ngx_int_t ngx_kqueue_init(ngx_cycle_t *cycle) ngx_event_actions = ngx_kqueue_module_ctx.actions; ngx_event_flags = NGX_USE_ONESHOT_EVENT -#if (HAVE_CLEAR_EVENT) +#if (NGX_HAVE_CLEAR_EVENT) |NGX_USE_CLEAR_EVENT #else |NGX_USE_LEVEL_EVENT diff --git a/src/event/modules/ngx_rtsig_module.c b/src/event/modules/ngx_rtsig_module.c index 3c0ea9511..d017f05bd 100644 --- a/src/event/modules/ngx_rtsig_module.c +++ b/src/event/modules/ngx_rtsig_module.c @@ -9,7 +9,7 @@ #include <ngx_event.h> -#if (TEST_BUILD_RTSIG) +#if (NGX_TEST_BUILD_RTSIG) #define F_SETSIG 10 #define SIGRTMIN 33 @@ -217,7 +217,7 @@ static ngx_int_t ngx_rtsig_add_connection(ngx_connection_t *c) return NGX_ERROR; } -#if (HAVE_ONESIGFD) +#if (NGX_HAVE_ONESIGFD) if (fcntl(c->fd, F_SETAUXFL, O_ONESIGFD) == -1) { ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno, "fcntl(F_SETAUXFL) failed"); diff --git a/src/event/modules/ngx_select_module.c b/src/event/modules/ngx_select_module.c index 14e6f81a3..0554ee95f 100644 --- a/src/event/modules/ngx_select_module.c +++ b/src/event/modules/ngx_select_module.c @@ -258,7 +258,7 @@ static ngx_int_t ngx_select_process_events(ngx_cycle_t *cycle) ngx_connection_t *c; ngx_epoch_msec_t delta; struct timeval tv, *tp; -#if (HAVE_SELECT_CHANGE_TIMEOUT) +#if (NGX_HAVE_SELECT_CHANGE_TIMEOUT) static ngx_epoch_msec_t deltas = 0; #endif @@ -362,7 +362,7 @@ static ngx_int_t ngx_select_process_events(ngx_cycle_t *cycle) err = 0; } -#if (HAVE_SELECT_CHANGE_TIMEOUT) +#if (NGX_HAVE_SELECT_CHANGE_TIMEOUT) if (timer != NGX_TIMER_INFINITE) { delta = timer - (tv.tv_sec * 1000 + tv.tv_usec / 1000); @@ -403,7 +403,7 @@ static ngx_int_t ngx_select_process_events(ngx_cycle_t *cycle) } } -#else /* !(HAVE_SELECT_CHANGE_TIMEOUT) */ +#else /* !(NGX_HAVE_SELECT_CHANGE_TIMEOUT) */ ngx_gettimeofday(&tv); ngx_time_update(tv.tv_sec); @@ -427,7 +427,7 @@ static ngx_int_t ngx_select_process_events(ngx_cycle_t *cycle) } } -#endif /* HAVE_SELECT_CHANGE_TIMEOUT */ +#endif /* NGX_HAVE_SELECT_CHANGE_TIMEOUT */ ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, "select ready %d", ready); diff --git a/src/event/ngx_event.c b/src/event/ngx_event.c index b3bf530a3..bd451bc65 100644 --- a/src/event/ngx_event.c +++ b/src/event/ngx_event.c @@ -371,7 +371,7 @@ static ngx_int_t ngx_event_process_init(ngx_cycle_t *cycle) rev->accept = 1; -#if (HAVE_DEFERRED_ACCEPT) +#if (NGX_HAVE_DEFERRED_ACCEPT) rev->deferred_accept = s[i].deferred_accept; #endif @@ -719,7 +719,7 @@ static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf) rtsig = 0; fd = 0; -#if (HAVE_EPOLL) && !(TEST_BUILD_EPOLL) +#if (NGX_HAVE_EPOLL) && !(NGX_TEST_BUILD_EPOLL) fd = epoll_create(100); @@ -735,7 +735,7 @@ static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf) #endif -#if (HAVE_RTSIG) +#if (NGX_HAVE_RTSIG) if (module == NULL) { connections = DEFAULT_CONNECTIONS; @@ -745,21 +745,21 @@ static char *ngx_event_init_conf(ngx_cycle_t *cycle, void *conf) #endif -#if (HAVE_DEVPOLL) +#if (NGX_HAVE_DEVPOLL) connections = DEFAULT_CONNECTIONS; module = &ngx_devpoll_module; #endif -#if (HAVE_KQUEUE) +#if (NGX_HAVE_KQUEUE) connections = DEFAULT_CONNECTIONS; module = &ngx_kqueue_module; #endif -#if (HAVE_SELECT) +#if (NGX_HAVE_SELECT) if (module == NULL) { diff --git a/src/event/ngx_event.h b/src/event/ngx_event.h index 44728e381..d156a6393 100644 --- a/src/event/ngx_event.h +++ b/src/event/ngx_event.h @@ -15,7 +15,7 @@ #define NGX_INVALID_INDEX 0xd0d0d0d0 -#if (HAVE_IOCP) +#if (NGX_HAVE_IOCP) typedef struct { WSAOVERLAPPED ovlp; @@ -86,7 +86,7 @@ struct ngx_event_s { unsigned accept_context_updated:1; #endif -#if (HAVE_KQUEUE) +#if (NGX_HAVE_KQUEUE) unsigned kq_vnode:1; /* the pending errno reported by kqueue */ @@ -107,7 +107,7 @@ struct ngx_event_s { * accept: 1 if accept many, 0 otherwise */ -#if (HAVE_KQUEUE) || (HAVE_IOCP) +#if (NGX_HAVE_KQUEUE) || (NGX_HAVE_IOCP) int available; #else unsigned available:1; @@ -117,9 +117,9 @@ struct ngx_event_s { ngx_event_handler_pt event_handler; -#if (HAVE_AIO) +#if (NGX_HAVE_AIO) -#if (HAVE_IOCP) +#if (NGX_HAVE_IOCP) ngx_event_ovlp_t ovlp; #else struct aiocb aiocb; @@ -154,12 +154,12 @@ struct ngx_event_s { unsigned posted_timedout:1; unsigned posted_eof:1; -#if (HAVE_KQUEUE) +#if (NGX_HAVE_KQUEUE) /* the pending errno reported by kqueue */ int posted_errno; #endif -#if (HAVE_KQUEUE) || (HAVE_IOCP) +#if (NGX_HAVE_KQUEUE) || (NGX_HAVE_IOCP) int posted_available; #else unsigned posted_available:1; @@ -272,7 +272,7 @@ extern ngx_event_actions_t ngx_event_actions; /* * Need to add socket or handle only once - i/o completion port. - * It also requires HAVE_AIO and NGX_USE_AIO_EVENT to be set. + * It also requires NGX_HAVE_AIO and NGX_USE_AIO_EVENT to be set. */ #define NGX_USE_IOCP_EVENT 0x00000200 @@ -296,7 +296,7 @@ extern ngx_event_actions_t ngx_event_actions; #define NGX_VNODE_EVENT 0 -#if (HAVE_KQUEUE) +#if (NGX_HAVE_KQUEUE) #define NGX_READ_EVENT EVFILT_READ #define NGX_WRITE_EVENT EVFILT_WRITE @@ -325,7 +325,7 @@ extern ngx_event_actions_t ngx_event_actions; #define NGX_DISABLE_EVENT EV_DISABLE -#elif (HAVE_DEVPOLL) +#elif (NGX_HAVE_DEVPOLL) #define NGX_READ_EVENT POLLIN #define NGX_WRITE_EVENT POLLOUT @@ -334,7 +334,7 @@ extern ngx_event_actions_t ngx_event_actions; #define NGX_ONESHOT_EVENT 1 -#elif (HAVE_EPOLL) +#elif (NGX_HAVE_EPOLL) #define NGX_READ_EVENT EPOLLIN #define NGX_WRITE_EVENT EPOLLOUT @@ -347,7 +347,7 @@ extern ngx_event_actions_t ngx_event_actions; #endif -#elif (HAVE_POLL) +#elif (NGX_HAVE_POLL) #define NGX_READ_EVENT POLLIN #define NGX_WRITE_EVENT POLLOUT @@ -364,10 +364,10 @@ extern ngx_event_actions_t ngx_event_actions; #define NGX_LEVEL_EVENT 0 #define NGX_ONESHOT_EVENT 1 -#endif /* HAVE_KQUEUE */ +#endif /* NGX_HAVE_KQUEUE */ -#if (HAVE_IOCP) +#if (NGX_HAVE_IOCP) #define NGX_IOCP_ACCEPT 0 #define NGX_IOCP_IO 1 #define NGX_IOCP_CONNECT 2 diff --git a/src/event/ngx_event_openssl.c b/src/event/ngx_event_openssl.c index b5c5b7256..294f3b4ce 100644 --- a/src/event/ngx_event_openssl.c +++ b/src/event/ngx_event_openssl.c @@ -9,7 +9,7 @@ #include <ngx_event.h> -static ngx_int_t ngx_ssl_write(ngx_connection_t *c, u_char *data, size_t size); +static ssize_t ngx_ssl_write(ngx_connection_t *c, u_char *data, size_t size); ngx_int_t ngx_ssl_init(ngx_log_t *log) @@ -58,7 +58,7 @@ ngx_int_t ngx_ssl_create_session(ngx_ssl_ctx_t *ssl_ctx, ngx_connection_t *c, } -ngx_int_t ngx_ssl_recv(ngx_connection_t *c, u_char *buf, size_t size) +ssize_t ngx_ssl_recv(ngx_connection_t *c, u_char *buf, size_t size) { int n, sslerr; ngx_err_t err; @@ -239,7 +239,7 @@ ngx_chain_t *ngx_ssl_send_chain(ngx_connection_t *c, ngx_chain_t *in, } -static ngx_int_t ngx_ssl_write(ngx_connection_t *c, u_char *data, size_t size) +static ssize_t ngx_ssl_write(ngx_connection_t *c, u_char *data, size_t size) { int n, sslerr; ngx_err_t err; diff --git a/src/event/ngx_event_openssl.h b/src/event/ngx_event_openssl.h index 69d8d1288..dbdb5f7b3 100644 --- a/src/event/ngx_event_openssl.h +++ b/src/event/ngx_event_openssl.h @@ -41,7 +41,7 @@ ngx_int_t ngx_ssl_create_session(ngx_ssl_ctx_t *ctx, ngx_connection_t *c, #define ngx_ssl_handshake(c) NGX_OK -ngx_int_t ngx_ssl_recv(ngx_connection_t *c, u_char *buf, size_t size); +ssize_t ngx_ssl_recv(ngx_connection_t *c, u_char *buf, size_t size); ngx_chain_t *ngx_ssl_send_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit); ngx_int_t ngx_ssl_shutdown(ngx_connection_t *c); diff --git a/src/event/ngx_event_pipe.c b/src/event/ngx_event_pipe.c index a2edc7129..3ca8a0cf3 100644 --- a/src/event/ngx_event_pipe.c +++ b/src/event/ngx_event_pipe.c @@ -132,7 +132,7 @@ ngx_int_t ngx_event_pipe_read_upstream(ngx_event_pipe_t *p) p->upstream_eof = 1; p->read = 1; -#if (HAVE_KQUEUE) +#if (NGX_HAVE_KQUEUE) if (p->upstream->read->kq_errno) { p->upstream->read->error = 1; p->upstream_error = 1; diff --git a/src/event/ngx_event_posted.c b/src/event/ngx_event_posted.c index aed07faa3..a99a434cb 100644 --- a/src/event/ngx_event_posted.c +++ b/src/event/ngx_event_posted.c @@ -120,7 +120,7 @@ ngx_int_t ngx_event_thread_process_posted(ngx_cycle_t *cycle) ev->ready |= ev->posted_ready; ev->timedout |= ev->posted_timedout; ev->pending_eof |= ev->posted_eof; -#if (HAVE_KQUEUE) +#if (NGX_HAVE_KQUEUE) ev->kq_errno |= ev->posted_errno; #endif if (ev->posted_available) { @@ -130,7 +130,7 @@ ngx_int_t ngx_event_thread_process_posted(ngx_cycle_t *cycle) ev->posted_ready = 0; ev->posted_timedout = 0; ev->posted_eof = 0; -#if (HAVE_KQUEUE) +#if (NGX_HAVE_KQUEUE) ev->posted_errno = 0; #endif ev->posted_available = 0; diff --git a/src/http/modules/ngx_http_gzip_filter.c b/src/http/modules/ngx_http_gzip_filter.c index f8980af52..b093d582f 100644 --- a/src/http/modules/ngx_http_gzip_filter.c +++ b/src/http/modules/ngx_http_gzip_filter.c @@ -237,14 +237,14 @@ static ngx_http_log_op_name_t ngx_http_gzip_log_fmt_ops[] = { static u_char gzheader[10] = { 0x1f, 0x8b, Z_DEFLATED, 0, 0, 0, 0, 0, 0, 3 }; -#if (HAVE_LITTLE_ENDIAN) +#if (NGX_HAVE_LITTLE_ENDIAN) struct gztrailer { uint32_t crc32; uint32_t zlen; }; -#else /* HAVE_BIG_ENDIAN */ +#else /* NGX_HAVE_BIG_ENDIAN */ struct gztrailer { u_char crc32[4]; @@ -437,7 +437,8 @@ static ngx_int_t ngx_http_gzip_proxied(ngx_http_request_t *r, static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in) { - int rc, wbits, memlevel, last; + int rc, wbits, memlevel; + ngx_int_t last; struct gztrailer *trailer; ngx_buf_t *b; ngx_chain_t *cl; @@ -469,7 +470,7 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r, /* * We preallocate a memory for zlib in one buffer (200K-400K), this * dicreases a number of malloc() and free() calls and also probably - * dicreases a number of syscalls (sbrk() or so). + * dicreases a number of syscalls (sbrk() and so on). * Besides we free this memory as soon as the gzipping will complete * and do not wait while a whole response will be sent to a client. * @@ -512,8 +513,19 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r, } cl->buf = b; cl->next = NULL; - ctx->out = cl; - ctx->last_out = &cl->next; + + /* + * We pass the gzheader to the next filter now to avoid its linking + * to the ctx->busy chain. zlib does not usually output the compressed + * data in the initial iterations, so the gzheader that was linked + * to the ctx->busy chain would be flushed by ngx_http_write_filter(). + */ + + if (ngx_http_next_body_filter(r, cl) == NGX_ERROR) { + return ngx_http_gzip_error(ctx); + } + + ctx->last_out = &ctx->out; ctx->crc32 = crc32(0L, Z_NULL, 0); ctx->flush = Z_NO_FLUSH; @@ -727,7 +739,7 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r, b->last += 8; } -#if (HAVE_LITTLE_ENDIAN) +#if (NGX_HAVE_LITTLE_ENDIAN) trailer->crc32 = ctx->crc32; trailer->zlen = ctx->zin; #else @@ -763,7 +775,7 @@ static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r, } } - if (last == NGX_AGAIN) { + if (last == NGX_AGAIN && !ctx->done) { return NGX_AGAIN; } @@ -881,7 +893,9 @@ static int ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx) { deflateEnd(&ctx->zstream); - ngx_pfree(ctx->request->pool, ctx->preallocated); + if (ctx->preallocated) { + ngx_pfree(ctx->request->pool, ctx->preallocated); + } ctx->zstream.avail_in = 0; ctx->zstream.avail_out = 0; diff --git a/src/http/modules/ngx_http_index_handler.c b/src/http/modules/ngx_http_index_handler.c index 013f62b46..3386953bd 100644 --- a/src/http/modules/ngx_http_index_handler.c +++ b/src/http/modules/ngx_http_index_handler.c @@ -10,19 +10,19 @@ typedef struct { - ngx_array_t indices; - size_t max_index_len; - ngx_http_cache_hash_t *index_cache; + ngx_array_t indices; + size_t max_index_len; + ngx_http_cache_hash_t *index_cache; } ngx_http_index_loc_conf_t; typedef struct { - ngx_uint_t index; - u_char *last; - ngx_str_t path; - ngx_str_t redirect; - ngx_http_cache_t *cache; - unsigned tested:1; + ngx_uint_t index; + u_char *last; + ngx_str_t path; + ngx_str_t redirect; + ngx_http_cache_entry_t *cache; + ngx_uint_t tested; /* unsigned tested:1 */ } ngx_http_index_ctx_t; diff --git a/src/http/modules/proxy/ngx_http_proxy_cache.c b/src/http/modules/proxy/ngx_http_proxy_cache.c index f0b56f548..86b8424c6 100644 --- a/src/http/modules/proxy/ngx_http_proxy_cache.c +++ b/src/http/modules/proxy/ngx_http_proxy_cache.c @@ -297,7 +297,7 @@ void ngx_http_proxy_cache_busy_lock(ngx_http_proxy_ctx_t *p) if (rc == NGX_AGAIN) { - if ((ngx_event_flags & (NGX_USE_CLEAR_EVENT|NGX_HAVE_KQUEUE_EVENT)) + if ((ngx_event_flags & (NGX_USE_CLEAR_EVENT|NGX_USE_KQUEUE_EVENT)) && !p->request->connection->write->active) { /* diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c index c0a8cf3d9..425a1a6af 100644 --- a/src/http/modules/proxy/ngx_http_proxy_handler.c +++ b/src/http/modules/proxy/ngx_http_proxy_handler.c @@ -414,7 +414,7 @@ void ngx_http_proxy_check_broken_connection(ngx_event_t *ev) ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ev->log, 0, "http proxy check client, write event:%d", ev->write); -#if (HAVE_KQUEUE) +#if (NGX_HAVE_KQUEUE) if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { @@ -563,9 +563,9 @@ void ngx_http_proxy_busy_lock_handler(ngx_event_t *rev) */ #if 0 -#if (HAVE_KQUEUE) +#if (NGX_HAVE_KQUEUE) - if ((ngx_event_flags & NGX_HAVE_KQUEUE_EVENT) && rev->kq_eof) { + if ((ngx_event_flags & NGX_USE_KQUEUE_EVENT) && rev->kq_eof) { ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock); ngx_del_timer(rev); @@ -1400,7 +1400,7 @@ static char *ngx_http_proxy_lowat_check(ngx_conf_t *cf, void *post, void *data) return NGX_CONF_ERROR; } -#elif !(HAVE_SO_SNDLOWAT) +#elif !(NGX_HAVE_SO_SNDLOWAT) ngx_conf_log_error(NGX_LOG_WARN, cf, 0, "\"proxy_send_lowat\" is not supported, ignored"); diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.h b/src/http/modules/proxy/ngx_http_proxy_handler.h index 094ee3bd1..8ab88ad54 100644 --- a/src/http/modules/proxy/ngx_http_proxy_handler.h +++ b/src/http/modules/proxy/ngx_http_proxy_handler.h @@ -142,7 +142,7 @@ typedef struct { typedef struct { - ngx_http_cache_ctx_t ctx; + ngx_http_cache_t ctx; ngx_uint_t status; ngx_str_t status_line; diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c index 0852a426f..23d40c493 100644 --- a/src/http/modules/proxy/ngx_http_proxy_upstream.c +++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c @@ -782,7 +782,7 @@ static void ngx_http_proxy_send_request(ngx_http_proxy_ctx_t *p) ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http proxy send request"); -#if (HAVE_KQUEUE) +#if (NGX_HAVE_KQUEUE) if ((ngx_event_flags & NGX_USE_KQUEUE_EVENT) && !p->request_sent @@ -1287,8 +1287,8 @@ static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p) header->length = r->headers_out.content_length_n; p->cache->ctx.length = r->headers_out.content_length_n; - header->key_len = p->cache->ctx.key.len; - ngx_memcpy(&header->key, p->cache->ctx.key.data, header->key_len); + header->key_len = p->cache->ctx.key0.len; + ngx_memcpy(&header->key, p->cache->ctx.key0.data, header->key_len); header->key[header->key_len] = LF; } diff --git a/src/http/ngx_http_cache.c b/src/http/ngx_http_cache.c index 22572a58b..abdeae989 100644 --- a/src/http/ngx_http_cache.c +++ b/src/http/ngx_http_cache.c @@ -63,7 +63,7 @@ ngx_http_cache_t *ngx_http_cache_get(ngx_http_cache_hash_t *hash, c[i].refs++; - if ((!(c[i].notify && (ngx_event_flags & NGX_HAVE_KQUEUE_EVENT))) + if ((!(c[i].notify && (ngx_event_flags & NGX_USE_KQUEUE_EVENT))) && (ngx_cached_time - c[i].updated >= hash->update)) { c[i].expired = 1; diff --git a/src/http/ngx_http_cache.h b/src/http/ngx_http_cache.h index 40f4852dd..aa6690265 100644 --- a/src/http/ngx_http_cache.h +++ b/src/http/ngx_http_cache.h @@ -14,11 +14,12 @@ /* - * The 7 uses before an allocation. + * The 3 bits allows the 7 uses before the cache entry allocation. * We can use maximum 7 bits, i.e up to the 127 uses. */ #define NGX_HTTP_CACHE_LAZY_ALLOCATION_BITS 3 + typedef struct { uint32_t crc; ngx_str_t key; @@ -45,7 +46,7 @@ typedef struct { off_t size; ngx_str_t value; } data; -} ngx_http_cache_t; +} ngx_http_cache_entry_t; typedef struct { @@ -62,7 +63,7 @@ typedef struct { #define NGX_HTTP_CACHE_NELTS 4 typedef struct { - ngx_http_cache_t *elts; + ngx_http_cache_entry_t *elts; size_t hash; size_t nelts; time_t life; @@ -76,9 +77,9 @@ typedef struct { typedef struct { ngx_http_cache_hash_t *hash; - ngx_http_cache_t *cache; + ngx_http_cache_entry_t *cache; ngx_file_t file; - ngx_str_t key; + ngx_array_t key; uint32_t crc; u_char md5[16]; ngx_path_t *path; @@ -90,7 +91,10 @@ typedef struct { ssize_t header_size; size_t file_start; ngx_log_t *log; -} ngx_http_cache_ctx_t; + + /* STUB */ + ngx_str_t key0; +} ngx_http_cache_t; @@ -99,6 +103,8 @@ typedef struct { #define NGX_HTTP_CACHE_THE_SAME 3 +#if 0 + ngx_http_cache_t *ngx_http_cache_get(ngx_http_cache_hash_t *cache, ngx_http_cleanup_t *cleanup, ngx_str_t *key, uint32_t *crc); @@ -127,5 +133,7 @@ int ngx_garbage_collector_http_cache_handler(ngx_gc_t *gc, ngx_str_t *name, char *ngx_http_set_cache_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); +#endif + #endif /* _NGX_HTTP_CACHE_H_INCLUDED_ */ diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index c764b2a00..c4cb8b9f0 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -1828,7 +1828,7 @@ static char *ngx_http_lowat_check(ngx_conf_t *cf, void *post, void *data) return NGX_CONF_ERROR; } -#elif !(HAVE_SO_SNDLOWAT) +#elif !(NGX_HAVE_SO_SNDLOWAT) ngx_conf_log_error(NGX_LOG_WARN, cf, 0, "\"send_lowat\" is not supported, ignored"); diff --git a/src/http/ngx_http_file_cache.c b/src/http/ngx_http_file_cache.c index 8f920d240..1b258c943 100644 --- a/src/http/ngx_http_file_cache.c +++ b/src/http/ngx_http_file_cache.c @@ -9,19 +9,20 @@ #include <ngx_http.h> -#if (HAVE_OPENSSL_MD5_H) +#if (NGX_HAVE_OPENSSL_MD5_H) #include <openssl/md5.h> #else #include <md5.h> #endif -#if (HAVE_OPENSSL_MD5) +#if (NGX_OPENSSL_MD5) #define MD5Init MD5_Init #define MD5Update MD5_Update #define MD5Final MD5_Final #endif +#if 0 int ngx_http_cache_get_file(ngx_http_request_t *r, ngx_http_cache_ctx_t *ctx) { @@ -237,3 +238,5 @@ int ngx_garbage_collector_http_cache_handler(ngx_gc_t *gc, ngx_str_t *name, return NGX_OK; } + +#endif diff --git a/src/http/ngx_http_parse.c b/src/http/ngx_http_parse.c index bfe5efb17..a4e7d8045 100644 --- a/src/http/ngx_http_parse.c +++ b/src/http/ngx_http_parse.c @@ -686,7 +686,7 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r) ch = *p++; - while (p < r->uri_start + r->uri.len + 1 && r->args_start == NULL) { + while (p < r->uri_end && r->args_start == NULL) { /* * we use "ch = *p++" inside the cycle but this operation is safe diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c index a2cf1a025..b6013fcea 100644 --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -532,6 +532,7 @@ static void ngx_http_process_request_line(ngx_event_t *rev) r->uri.len = r->uri_end - r->uri_start; } + if (r->complex_uri || r->quoted_uri) { if (!(r->uri.data = ngx_palloc(r->pool, r->uri.len + 1))) { @@ -557,6 +558,7 @@ static void ngx_http_process_request_line(ngx_event_t *rev) r->uri.data = r->uri_start; } + r->unparsed_uri.len = r->uri_end - r->uri_start; r->unparsed_uri.data = r->uri_start; @@ -1751,7 +1753,7 @@ static void ngx_http_keepalive_handler(ngx_event_t *rev) ctx = (ngx_http_log_ctx_t *) rev->log->data; -#if (HAVE_KQUEUE) +#if (NGX_HAVE_KQUEUE) if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { if (rev->pending_eof) { diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h index 31b1187b0..141daa1b8 100644 --- a/src/http/ngx_http_request.h +++ b/src/http/ngx_http_request.h @@ -220,7 +220,7 @@ struct ngx_http_cleanup_s { struct { ngx_http_cache_hash_t *hash; - ngx_http_cache_t *cache; + ngx_http_cache_entry_t *cache; } cache; } data; @@ -254,7 +254,7 @@ struct ngx_http_request_s { void **srv_conf; void **loc_conf; - ngx_http_cache_t *cache; + ngx_http_cache_entry_t *cache; ngx_file_t file; diff --git a/src/os/unix/ngx_aio_read.c b/src/os/unix/ngx_aio_read.c index d01105412..2a66eb83c 100644 --- a/src/os/unix/ngx_aio_read.c +++ b/src/os/unix/ngx_aio_read.c @@ -9,7 +9,7 @@ #include <ngx_event.h> #include <ngx_aio.h> -#if (HAVE_KQUEUE) +#if (NGX_HAVE_KQUEUE) #include <ngx_kqueue_module.h> #endif @@ -46,7 +46,7 @@ ssize_t ngx_aio_read(ngx_connection_t *c, u_char *buf, size_t size) rev->aiocb.aio_buf = buf; rev->aiocb.aio_nbytes = size; -#if (HAVE_KQUEUE) +#if (NGX_HAVE_KQUEUE) rev->aiocb.aio_sigevent.sigev_notify_kqueue = ngx_kqueue; rev->aiocb.aio_sigevent.sigev_notify = SIGEV_KEVENT; rev->aiocb.aio_sigevent.sigev_value.sigval_ptr = rev; diff --git a/src/os/unix/ngx_aio_write.c b/src/os/unix/ngx_aio_write.c index f102ba338..1d8c1aacd 100644 --- a/src/os/unix/ngx_aio_write.c +++ b/src/os/unix/ngx_aio_write.c @@ -9,7 +9,7 @@ #include <ngx_event.h> #include <ngx_aio.h> -#if (HAVE_KQUEUE) +#if (NGX_HAVE_KQUEUE) #include <ngx_kqueue_module.h> #endif @@ -43,7 +43,7 @@ ssize_t ngx_aio_write(ngx_connection_t *c, u_char *buf, size_t size) wev->aiocb.aio_buf = buf; wev->aiocb.aio_nbytes = size; -#if (HAVE_KQUEUE) +#if (NGX_HAVE_KQUEUE) wev->aiocb.aio_sigevent.sigev_notify_kqueue = ngx_kqueue; wev->aiocb.aio_sigevent.sigev_notify = SIGEV_KEVENT; wev->aiocb.aio_sigevent.sigev_value.sigval_ptr = wev; diff --git a/src/os/unix/ngx_alloc.c b/src/os/unix/ngx_alloc.c index 7ec4f87c3..258a10fa9 100644 --- a/src/os/unix/ngx_alloc.c +++ b/src/os/unix/ngx_alloc.c @@ -40,7 +40,7 @@ void *ngx_calloc(size_t size, ngx_log_t *log) } -#if (HAVE_POSIX_MEMALIGN) +#if (NGX_HAVE_POSIX_MEMALIGN) void *ngx_memalign(size_t alignment, size_t size, ngx_log_t *log) { @@ -58,7 +58,7 @@ void *ngx_memalign(size_t alignment, size_t size, ngx_log_t *log) return p; } -#elif (HAVE_MEMALIGN) +#elif (NGX_HAVE_MEMALIGN) void *ngx_memalign(size_t alignment, size_t size, ngx_log_t *log) { diff --git a/src/os/unix/ngx_alloc.h b/src/os/unix/ngx_alloc.h index 0084c2c54..66562a191 100644 --- a/src/os/unix/ngx_alloc.h +++ b/src/os/unix/ngx_alloc.h @@ -25,7 +25,7 @@ void *ngx_calloc(size_t size, ngx_log_t *log); * allocations bigger than page size at the page boundary. */ -#if (HAVE_POSIX_MEMALIGN || HAVE_MEMALIGN) +#if (NGX_HAVE_POSIX_MEMALIGN || NGX_HAVE_MEMALIGN) void *ngx_memalign(size_t alignment, size_t size, ngx_log_t *log); diff --git a/src/os/unix/ngx_channel.c b/src/os/unix/ngx_channel.c index 0bfbd0de6..b1b36c5b3 100644 --- a/src/os/unix/ngx_channel.c +++ b/src/os/unix/ngx_channel.c @@ -17,7 +17,7 @@ ngx_int_t ngx_write_channel(ngx_socket_t s, ngx_channel_t *ch, size_t size, struct iovec iov[1]; struct msghdr msg; -#if (HAVE_MSGHDR_MSG_CONTROL) +#if (NGX_HAVE_MSGHDR_MSG_CONTROL) union { struct cmsghdr cm; @@ -83,7 +83,7 @@ ngx_int_t ngx_read_channel(ngx_socket_t s, ngx_channel_t *ch, size_t size, struct iovec iov[1]; struct msghdr msg; -#if (HAVE_MSGHDR_MSG_CONTROL) +#if (NGX_HAVE_MSGHDR_MSG_CONTROL) union { struct cmsghdr cm; char space[CMSG_SPACE(sizeof(int))]; @@ -100,7 +100,7 @@ ngx_int_t ngx_read_channel(ngx_socket_t s, ngx_channel_t *ch, size_t size, msg.msg_iov = iov; msg.msg_iovlen = 1; -#if (HAVE_MSGHDR_MSG_CONTROL) +#if (NGX_HAVE_MSGHDR_MSG_CONTROL) msg.msg_control = (caddr_t) &cmsg; msg.msg_controllen = sizeof(cmsg); #else @@ -131,7 +131,7 @@ ngx_int_t ngx_read_channel(ngx_socket_t s, ngx_channel_t *ch, size_t size, return NGX_ERROR; } -#if (HAVE_MSGHDR_MSG_CONTROL) +#if (NGX_HAVE_MSGHDR_MSG_CONTROL) if (ch->command == NGX_CMD_OPEN_CHANNEL) { diff --git a/src/os/unix/ngx_errno.c b/src/os/unix/ngx_errno.c index ced0eafcb..607b361d9 100644 --- a/src/os/unix/ngx_errno.c +++ b/src/os/unix/ngx_errno.c @@ -8,7 +8,7 @@ #include <ngx_core.h> -#if (NGX_STRERROR_R) +#if (NGX_HAVE_STRERROR_R) u_char *ngx_strerror_r(int err, u_char *errstr, size_t size) { @@ -28,7 +28,7 @@ u_char *ngx_strerror_r(int err, u_char *errstr, size_t size) return errstr; } -#elif (NGX_GNU_STRERROR_R) +#elif (NGX_HAVE_GNU_STRERROR_R) /* Linux strerror_r() */ diff --git a/src/os/unix/ngx_errno.h b/src/os/unix/ngx_errno.h index e87ec5f6f..c1c5801d3 100644 --- a/src/os/unix/ngx_errno.h +++ b/src/os/unix/ngx_errno.h @@ -46,7 +46,7 @@ typedef int ngx_err_t; #define ngx_set_socket_errno(err) errno = err -#if (HAVE_STRERROR_R || HAVE_GNU_STRERROR_R) +#if (NGX_HAVE_STRERROR_R || NGX_HAVE_GNU_STRERROR_R) u_char *ngx_strerror_r(int err, u_char *errstr, size_t size); diff --git a/src/os/unix/ngx_files.c b/src/os/unix/ngx_files.c index 52aa9b62a..e67b2cac7 100644 --- a/src/os/unix/ngx_files.c +++ b/src/os/unix/ngx_files.c @@ -15,7 +15,7 @@ ssize_t ngx_read_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset) ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0, "read: %d, %p, %uz, %O", file->fd, buf, size, offset); -#if (NGX_PREAD) +#if (NGX_HAVE_PREAD) n = pread(file->fd, buf, size, offset); @@ -60,7 +60,7 @@ ssize_t ngx_write_file(ngx_file_t *file, u_char *buf, size_t size, off_t offset) ngx_log_debug4(NGX_LOG_DEBUG_CORE, file->log, 0, "write: %d, %p, %uz, %O", file->fd, buf, size, offset); -#if (NGX_PWRITE) +#if (NGX_HAVE_PWRITE) n = pwrite(file->fd, buf, size, offset); diff --git a/src/os/unix/ngx_freebsd_config.h b/src/os/unix/ngx_freebsd_config.h index 7f3b286c3..35bf1f502 100644 --- a/src/os/unix/ngx_freebsd_config.h +++ b/src/os/unix/ngx_freebsd_config.h @@ -60,23 +60,23 @@ #include <ngx_auto_config.h> -#if (HAVE_POLL) +#if (NGX_HAVE_POLL) #include <poll.h> #endif -#if (HAVE_AIO) +#if (NGX_HAVE_AIO) #include <aio.h> #endif -#if (HAVE_KQUEUE) +#if (NGX_HAVE_KQUEUE) #include <sys/event.h> #endif -#if defined SO_ACCEPTFILTER && !defined HAVE_DEFERRED_ACCEPT -#define HAVE_DEFERRED_ACCEPT 1 +#if defined SO_ACCEPTFILTER && !defined NGX_HAVE_DEFERRED_ACCEPT +#define NGX_HAVE_DEFERRED_ACCEPT 1 #endif @@ -91,8 +91,8 @@ pid_t rfork_thread(int flags, void *stack, int (*func)(void *arg), void *arg); #endif -#ifndef HAVE_INHERITED_NONBLOCK -#define HAVE_INHERITED_NONBLOCK 1 +#ifndef NGX_HAVE_INHERITED_NONBLOCK +#define NGX_HAVE_INHERITED_NONBLOCK 1 #endif diff --git a/src/os/unix/ngx_freebsd_init.c b/src/os/unix/ngx_freebsd_init.c index faf8e9f1e..b76dc0cb9 100644 --- a/src/os/unix/ngx_freebsd_init.c +++ b/src/os/unix/ngx_freebsd_init.c @@ -30,7 +30,7 @@ ngx_os_io_t ngx_os_io = { ngx_unix_recv, ngx_readv_chain, ngx_unix_send, -#if (HAVE_SENDFILE) +#if (NGX_HAVE_SENDFILE) ngx_freebsd_sendfile_chain, NGX_IO_SENDFILE #else @@ -128,7 +128,7 @@ ngx_int_t ngx_os_init(ngx_log_t *log) version = ngx_freebsd_kern_osreldate; -#if (HAVE_SENDFILE) +#if (NGX_HAVE_SENDFILE) /* * The determination of the sendfile() "nbytes bug" is complex enough. @@ -161,7 +161,7 @@ ngx_int_t ngx_os_init(ngx_log_t *log) #endif -#endif /* HAVE_SENDFILE */ +#endif /* NGX_HAVE_SENDFILE */ if ((version < 500000 && version >= 440003) || version >= 500017) { diff --git a/src/os/unix/ngx_freebsd_rfork_thread.c b/src/os/unix/ngx_freebsd_rfork_thread.c index b64325bcd..5dfd46807 100644 --- a/src/os/unix/ngx_freebsd_rfork_thread.c +++ b/src/os/unix/ngx_freebsd_rfork_thread.c @@ -381,7 +381,7 @@ ngx_int_t ngx_mutex_dolock(ngx_mutex_t *m, ngx_int_t try) return NGX_AGAIN; } - if (ngx_freebsd_hw_ncpu > 1 && tries++ < 1000) { + if (ngx_ncpu > 1 && tries++ < 1000) { /* the spinlock is used only on the SMP system */ @@ -581,7 +581,7 @@ ngx_cond_t *ngx_cond_init(ngx_log_t *log) } cv->signo = NGX_CV_SIGNAL; - cv->tid = 0; + cv->tid = -1; cv->log = log; cv->kq = -1; @@ -640,6 +640,8 @@ ngx_int_t ngx_cond_wait(ngx_cond_t *cv, ngx_mutex_t *m) ngx_log_error(NGX_LOG_ALERT, cv->log, ngx_errno, "kevent() failed"); return NGX_ERROR; } + + cv->tid = ngx_thread_self(); } if (ngx_mutex_unlock(m) == NGX_ERROR) { @@ -714,6 +716,10 @@ ngx_int_t ngx_cond_signal(ngx_cond_t *cv) "cv %p to signal %P %d", cv, cv->tid, cv->signo); + if (cv->tid == -1) { + return NGX_OK; + } + if (kill(cv->tid, cv->signo) == -1) { err = ngx_errno; diff --git a/src/os/unix/ngx_freebsd_sendfile_chain.c b/src/os/unix/ngx_freebsd_sendfile_chain.c index 192a1a1ee..f86e1c0d7 100644 --- a/src/os/unix/ngx_freebsd_sendfile_chain.c +++ b/src/os/unix/ngx_freebsd_sendfile_chain.c @@ -55,7 +55,7 @@ ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, return in; } -#if (HAVE_KQUEUE) +#if (NGX_HAVE_KQUEUE) if ((ngx_event_flags & NGX_USE_KQUEUE_EVENT) && wev->pending_eof) { ngx_log_error(NGX_LOG_INFO, c->log, wev->kq_errno, diff --git a/src/os/unix/ngx_linux_config.h b/src/os/unix/ngx_linux_config.h index 57ee5057e..620b59d8c 100644 --- a/src/os/unix/ngx_linux_config.h +++ b/src/os/unix/ngx_linux_config.h @@ -56,35 +56,37 @@ #include <sys/prctl.h> #endif + #if (NGX_HAVE_SENDFILE64) #include <sys/sendfile.h> #else extern ssize_t sendfile(int s, int fd, int32_t *offset, size_t size); +#define NGX_SENDFILE_LIMIT (NGX_MAX_UINT32_VALUE + 1) #endif -#if (HAVE_POLL) +#if (NGX_HAVE_POLL) #include <poll.h> #endif -#if (HAVE_EPOLL) +#if (NGX_HAVE_EPOLL) #include <sys/epoll.h> -#endif /* HAVE_EPOLL */ +#endif -#if defined TCP_DEFER_ACCEPT && !defined HAVE_DEFERRED_ACCEPT -#define HAVE_DEFERRED_ACCEPT 1 +#if defined TCP_DEFER_ACCEPT && !defined NGX_HAVE_DEFERRED_ACCEPT +#define NGX_HAVE_DEFERRED_ACCEPT 1 #endif -#ifndef HAVE_INHERITED_NONBLOCK -#define HAVE_INHERITED_NONBLOCK 0 +#ifndef NGX_HAVE_INHERITED_NONBLOCK +#define NGX_HAVE_INHERITED_NONBLOCK 0 #endif -#ifndef HAVE_SELECT_CHANGE_TIMEOUT -#define HAVE_SELECT_CHANGE_TIMEOUT 1 +#ifndef NGX_HAVE_SELECT_CHANGE_TIMEOUT +#define NGX_HAVE_SELECT_CHANGE_TIMEOUT 1 #endif #ifndef NGX_SETPROCTITLE_USES_ENV diff --git a/src/os/unix/ngx_linux_init.c b/src/os/unix/ngx_linux_init.c index 397d342f0..9c1c84758 100644 --- a/src/os/unix/ngx_linux_init.c +++ b/src/os/unix/ngx_linux_init.c @@ -18,7 +18,7 @@ ngx_os_io_t ngx_os_io = { ngx_unix_recv, ngx_readv_chain, ngx_unix_send, -#if (HAVE_SENDFILE) +#if (NGX_HAVE_SENDFILE) ngx_linux_sendfile_chain, NGX_IO_SENDFILE #else diff --git a/src/os/unix/ngx_linux_sendfile_chain.c b/src/os/unix/ngx_linux_sendfile_chain.c index ad40f55d9..bcf9d4c76 100644 --- a/src/os/unix/ngx_linux_sendfile_chain.c +++ b/src/os/unix/ngx_linux_sendfile_chain.c @@ -13,7 +13,7 @@ * On Linux up to 2.4.21 sendfile() (syscall #187) works with 32-bit * offsets only and the including <sys/sendfile.h> breaks the compiling * if off_t is 64 bit wide. So we use own sendfile() definition where offset - * parameter is int32_t and use sendfile() with the file parts below 2G. + * parameter is int32_t and use sendfile() for the file parts below 2G only. * * Linux 2.4.21 has a new sendfile64() syscall #239. */ diff --git a/src/os/unix/ngx_os.h b/src/os/unix/ngx_os.h index dc9f7a803..ee91df336 100644 --- a/src/os/unix/ngx_os.h +++ b/src/os/unix/ngx_os.h @@ -15,18 +15,6 @@ #define NGX_IO_SENDFILE 1 #define NGX_IO_ZEROCOPY 2 -#if (HAVE_SENDFILE) -#define NGX_HAVE_SENDFILE NGX_IO_SENDFILE -#else -#define NGX_HAVE_SENDFILE 0 -#endif - -#if (HAVE_ZEROCOPY) -#define NGX_HAVE_ZEROCOPY NGX_IO_ZEROCOPY -#else -#define NGX_HAVE_ZEROCOPY 0 -#endif - typedef ssize_t (*ngx_recv_pt)(ngx_connection_t *c, u_char *buf, size_t size); typedef ssize_t (*ngx_recv_chain_pt)(ngx_connection_t *c, ngx_chain_t *in); diff --git a/src/os/unix/ngx_posix_config.h b/src/os/unix/ngx_posix_config.h index b187236e9..f9c91a4bf 100644 --- a/src/os/unix/ngx_posix_config.h +++ b/src/os/unix/ngx_posix_config.h @@ -70,17 +70,17 @@ #include <ngx_auto_config.h> -#if (HAVE_POLL) +#if (NGX_HAVE_POLL) #include <poll.h> #endif -#if (HAVE_KQUEUE) +#if (NGX_HAVE_KQUEUE) #include <sys/event.h> #endif -#if (HAVE_DEVPOLL) +#if (NGX_HAVE_DEVPOLL) #include <sys/ioctl.h> #include <sys/devpoll.h> #endif diff --git a/src/os/unix/ngx_posix_init.c b/src/os/unix/ngx_posix_init.c index 19d65a489..56be0cefb 100644 --- a/src/os/unix/ngx_posix_init.c +++ b/src/os/unix/ngx_posix_init.c @@ -121,7 +121,7 @@ ngx_int_t ngx_posix_init(ngx_log_t *log) ngx_max_sockets = rlmt.rlim_cur; -#if (HAVE_INHERITED_NONBLOCK) +#if (NGX_HAVE_INHERITED_NONBLOCK) ngx_inherited_nonblocking = 1; #else ngx_inherited_nonblocking = 0; diff --git a/src/os/unix/ngx_process_cycle.c b/src/os/unix/ngx_process_cycle.c index 37b2ef193..3d1c51bc0 100644 --- a/src/os/unix/ngx_process_cycle.c +++ b/src/os/unix/ngx_process_cycle.c @@ -607,6 +607,10 @@ static void ngx_master_exit(ngx_cycle_t *cycle) static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data) { + ngx_int_t n; + ngx_err_t err; + ngx_core_conf_t *ccf; + ngx_worker_process_init(cycle); ngx_setproctitle("worker process"); @@ -618,6 +622,8 @@ static void ngx_worker_process_cycle(ngx_cycle_t *cycle, void *data) exit(2); } + ccf = (ngx_core_conf_t *) ngx_get_conf(cycle->conf_ctx, ngx_core_module); + if (ngx_threads_n) { if (ngx_init_threads(ngx_threads_n, ccf->thread_stack_size, cycle) == NGX_ERROR) @@ -914,10 +920,9 @@ static void ngx_wakeup_worker_threads(ngx_cycle_t *cycle) for (i = 0; i < ngx_threads_n; i++) { if (ngx_threads[i].state < NGX_THREAD_EXIT) { - ngx_cond_signal(ngx_threads[i].cv); - - if (ngx_threads[i].cv->tid == (ngx_tid_t) -1) { + if (ngx_cond_signal(ngx_threads[i].cv) == NGX_ERROR) { ngx_threads[i].state = NGX_THREAD_DONE; + } else { live = 1; } @@ -955,8 +960,6 @@ static void *ngx_worker_thread_cycle(void *data) ngx_core_tls_t *tls; ngx_cycle_t *cycle; - thr->cv->tid = ngx_thread_self(); - cycle = (ngx_cycle_t *) ngx_cycle; sigemptyset(&set); diff --git a/src/os/unix/ngx_readv_chain.c b/src/os/unix/ngx_readv_chain.c index 2db998a86..7c57b7abe 100644 --- a/src/os/unix/ngx_readv_chain.c +++ b/src/os/unix/ngx_readv_chain.c @@ -9,7 +9,7 @@ #include <ngx_event.h> -#if (HAVE_KQUEUE) +#if (NGX_HAVE_KQUEUE) ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain) { @@ -136,7 +136,7 @@ ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain) return n; } -#else /* ! NAVE_KQUEUE */ +#else /* ! NGX_HAVE_KQUEUE */ ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain) { @@ -216,4 +216,4 @@ ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain) return n; } -#endif /* NAVE_KQUEUE */ +#endif /* NGX_HAVE_KQUEUE */ diff --git a/src/os/unix/ngx_recv.c b/src/os/unix/ngx_recv.c index d58ca9e3d..369be661a 100644 --- a/src/os/unix/ngx_recv.c +++ b/src/os/unix/ngx_recv.c @@ -9,7 +9,7 @@ #include <ngx_event.h> -#if (HAVE_KQUEUE) +#if (NGX_HAVE_KQUEUE) ssize_t ngx_unix_recv(ngx_connection_t *c, u_char *buf, size_t size) { @@ -115,7 +115,7 @@ ssize_t ngx_unix_recv(ngx_connection_t *c, u_char *buf, size_t size) return n; } -#else /* ! NAVE_KQUEUE */ +#else /* ! NGX_HAVE_KQUEUE */ ssize_t ngx_unix_recv(ngx_connection_t *c, u_char *buf, size_t size) { @@ -170,4 +170,4 @@ ssize_t ngx_unix_recv(ngx_connection_t *c, u_char *buf, size_t size) return n; } -#endif /* NAVE_KQUEUE */ +#endif /* NGX_HAVE_KQUEUE */ diff --git a/src/os/unix/ngx_send.c b/src/os/unix/ngx_send.c index ff501c30a..ecd136265 100644 --- a/src/os/unix/ngx_send.c +++ b/src/os/unix/ngx_send.c @@ -17,7 +17,7 @@ ssize_t ngx_unix_send(ngx_connection_t *c, u_char *buf, size_t size) wev = c->write; -#if (HAVE_KQUEUE) +#if (NGX_HAVE_KQUEUE) if ((ngx_event_flags & NGX_USE_KQUEUE_EVENT) && wev->pending_eof) { ngx_log_error(NGX_LOG_INFO, c->log, wev->kq_errno, diff --git a/src/os/unix/ngx_shared.c b/src/os/unix/ngx_shared.c index 0edc8cbe1..80b5f601f 100644 --- a/src/os/unix/ngx_shared.c +++ b/src/os/unix/ngx_shared.c @@ -8,7 +8,7 @@ #include <ngx_core.h> -#if (HAVE_MAP_ANON) +#if (NGX_HAVE_MAP_ANON) void *ngx_create_shared_memory(size_t size, ngx_log_t *log) { @@ -25,7 +25,7 @@ void *ngx_create_shared_memory(size_t size, ngx_log_t *log) return p; } -#elif (HAVE_MAP_DEVZERO) +#elif (NGX_HAVE_MAP_DEVZERO) void *ngx_create_shared_memory(size_t size, ngx_log_t *log) { @@ -56,7 +56,7 @@ void *ngx_create_shared_memory(size_t size, ngx_log_t *log) return p; } -#elif (HAVE_SYSVSHM) +#elif (NGX_HAVE_SYSVSHM) #include <sys/ipc.h> #include <sys/shm.h> diff --git a/src/os/unix/ngx_socket.c b/src/os/unix/ngx_socket.c index da936b2fb..523f1f4ce 100644 --- a/src/os/unix/ngx_socket.c +++ b/src/os/unix/ngx_socket.c @@ -20,7 +20,7 @@ */ -#if (HAVE_FIONBIO) +#if (NGX_HAVE_FIONBIO) int ngx_nonblocking(ngx_socket_t s) { diff --git a/src/os/unix/ngx_socket.h b/src/os/unix/ngx_socket.h index 4dcf924e0..b381967e6 100644 --- a/src/os/unix/ngx_socket.h +++ b/src/os/unix/ngx_socket.h @@ -19,7 +19,7 @@ typedef int ngx_socket_t; #define ngx_socket_n "socket()" -#if (HAVE_FIONBIO) +#if (NGX_HAVE_FIONBIO) int ngx_nonblocking(ngx_socket_t s); int ngx_blocking(ngx_socket_t s); diff --git a/src/os/unix/ngx_solaris_config.h b/src/os/unix/ngx_solaris_config.h index 8f1841793..452850c0f 100644 --- a/src/os/unix/ngx_solaris_config.h +++ b/src/os/unix/ngx_solaris_config.h @@ -49,35 +49,35 @@ #include <ngx_auto_config.h> -#if (HAVE_POLL) +#if (NGX_HAVE_POLL) #include <poll.h> #endif -#if (HAVE_SENDFILE) +#if (NGX_HAVE_SENDFILE) #include <sys/sendfile.h> #endif -#if (HAVE_AIO) +#if (NGX_HAVE_AIO) #include <aio.h> #endif -#if (HAVE_DEVPOLL) +#if (NGX_HAVE_DEVPOLL) #include <sys/ioctl.h> #include <sys/devpoll.h> #endif -#ifndef HAVE_INHERITED_NONBLOCK -#define HAVE_INHERITED_NONBLOCK 1 +#ifndef NGX_HAVE_INHERITED_NONBLOCK +#define NGX_HAVE_INHERITED_NONBLOCK 1 #endif -#ifndef HAVE_SO_SNDLOWAT +#ifndef NGX_HAVE_SO_SNDLOWAT /* setsockopt(SO_SNDLOWAT) returns error "Option not supported by protocol" */ -#define HAVE_SO_SNDLOWAT 0 +#define NGX_HAVE_SO_SNDLOWAT 0 #endif diff --git a/src/os/unix/ngx_solaris_init.c b/src/os/unix/ngx_solaris_init.c index c671197e0..03072edad 100644 --- a/src/os/unix/ngx_solaris_init.c +++ b/src/os/unix/ngx_solaris_init.c @@ -17,7 +17,7 @@ ngx_os_io_t ngx_os_io = { ngx_unix_recv, ngx_readv_chain, ngx_unix_send, -#if (HAVE_SENDFILE) +#if (NGX_HAVE_SENDFILE) ngx_solaris_sendfilev_chain, NGX_IO_SENDFILE #else diff --git a/src/os/unix/ngx_thread.h b/src/os/unix/ngx_thread.h index ac7cfad43..e630b356e 100644 --- a/src/os/unix/ngx_thread.h +++ b/src/os/unix/ngx_thread.h @@ -53,7 +53,6 @@ typedef struct { typedef struct { pthread_cond_t cond; - ngx_tid_t tid; ngx_log_t *log; } ngx_cond_t; diff --git a/src/os/unix/ngx_time.c b/src/os/unix/ngx_time.c index c4389503a..20ec4644b 100644 --- a/src/os/unix/ngx_time.c +++ b/src/os/unix/ngx_time.c @@ -10,7 +10,7 @@ void ngx_localtime(ngx_tm_t *tm) { -#if (HAVE_LOCALTIME_R) +#if (NGX_HAVE_LOCALTIME_R) time_t now; now = ngx_time(); diff --git a/src/os/unix/ngx_time.h b/src/os/unix/ngx_time.h index a6acf59e3..f257325d0 100644 --- a/src/os/unix/ngx_time.h +++ b/src/os/unix/ngx_time.h @@ -36,7 +36,7 @@ typedef struct tm ngx_tm_t; #define ngx_tm_wday_t int -#if (HAVE_GMTOFF) +#if (NGX_HAVE_GMTOFF) #define ngx_tm_gmtoff tm_gmtoff #define ngx_tm_zone tm_zone #endif diff --git a/src/os/unix/ngx_writev_chain.c b/src/os/unix/ngx_writev_chain.c index e3893226d..2af64699b 100644 --- a/src/os/unix/ngx_writev_chain.c +++ b/src/os/unix/ngx_writev_chain.c @@ -30,7 +30,7 @@ ngx_chain_t *ngx_writev_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit) return in; } -#if (HAVE_KQUEUE) +#if (NGX_HAVE_KQUEUE) if ((ngx_event_flags & NGX_USE_KQUEUE_EVENT) && wev->pending_eof) { ngx_log_error(NGX_LOG_INFO, c->log, wev->kq_errno, diff --git a/src/os/win32/ngx_os.h b/src/os/win32/ngx_os.h index c27f8a80a..6d720fa58 100644 --- a/src/os/win32/ngx_os.h +++ b/src/os/win32/ngx_os.h @@ -15,18 +15,6 @@ #define NGX_IO_SENDFILE 1 #define NGX_IO_ZEROCOPY 2 -#if (HAVE_SENDFILE) -#define NGX_HAVE_SENDFILE NGX_IO_SENDFILE -#else -#define NGX_HAVE_SENDFILE 0 -#endif - -#if (HAVE_ZEROCOPY) -#define NGX_HAVE_ZEROCOPY NGX_IO_ZEROCOPY -#else -#define NGX_HAVE_ZEROCOPY 0 -#endif - typedef ssize_t (*ngx_recv_pt)(ngx_connection_t *c, u_char *buf, size_t size); typedef ssize_t (*ngx_recv_chain_pt)(ngx_connection_t *c, ngx_chain_t *in); diff --git a/src/os/win32/ngx_time.h b/src/os/win32/ngx_time.h index 665976d88..4cb984194 100644 --- a/src/os/win32/ngx_time.h +++ b/src/os/win32/ngx_time.h @@ -39,7 +39,7 @@ typedef FILETIME ngx_mtime_t; #define ngx_msleep Sleep -#define HAVE_GETTIMEZONE 1 +#define NGX_HAVE_GETTIMEZONE 1 ngx_int_t ngx_gettimezone(void); 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 e7d3086e8..c7703c29e 100644 --- a/src/os/win32/ngx_win32_config.h +++ b/src/os/win32/ngx_win32_config.h @@ -115,37 +115,31 @@ typedef uint32_t ngx_atomic_t; #define TIME_T_LEN sizeof("-2147483648") - 1 +#define OFF_T_MAX_VALUE 9223372036854775807 +#define NGX_HAVE_LITTLE_ENDIAN 1 - -#define NGX_WIN_NT 200000 +#define NGX_THREADS 1 -#define NGX_THREADS 1 +#define NGX_WIN_NT 200000 -#ifndef HAVE_INHERITED_NONBLOCK -#define HAVE_INHERITED_NONBLOCK 1 +#ifndef NGX_HAVE_INHERITED_NONBLOCK +#define NGX_HAVE_INHERITED_NONBLOCK 1 #endif -#ifndef HAVE_WIN32_TRANSMITPACKETS -#define HAVE_WIN32_TRANSMITPACKETS 1 -#define HAVE_WIN32_TRANSMITFILE 0 +#ifndef NGX_HAVE_WIN32_TRANSMITPACKETS +#define NGX_HAVE_WIN32_TRANSMITPACKETS 1 +#define NGX_HAVE_WIN32_TRANSMITFILE 0 #endif -#ifndef HAVE_WIN32_TRANSMITFILE -#define HAVE_WIN32_TRANSMITFILE 1 +#ifndef NGX_HAVE_WIN32_TRANSMITFILE +#define NGX_HAVE_WIN32_TRANSMITFILE 1 #endif -#if (HAVE_WIN32_TRANSMITPACKETS) || (HAVE_WIN32_TRANSMITFILE) -#define HAVE_SENDFILE 1 +#if (NGX_HAVE_WIN32_TRANSMITPACKETS) || (NGX_HAVE_WIN32_TRANSMITFILE) +#define NGX_HAVE_SENDFILE 1 #endif -#define OFF_T_MAX_VALUE 9223372036854775807 - - -/* STUB */ -#define HAVE_LITTLE_ENDIAN 1 - - #endif /* _NGX_WIN32_CONFIG_H_INCLUDED_ */ |