# HG changeset patch # User Igor Sysoev # Date 1069085703 0 # Node ID 5a9bbe99008b9e6a3184a118546697b42a2ba474 # Parent c1f3a3c7c5db51ce28d461fe442c4984e7db56ff nginx-0.0.1-2003-11-17-19:15:03 import diff --git a/src/event/ngx_event_connectex.c b/src/event/ngx_event_connectex.c --- a/src/event/ngx_event_connectex.c +++ b/src/event/ngx_event_connectex.c @@ -14,8 +14,8 @@ static ngx_connection_t pending_connect static HANDLE pending_connect_event; __declspec(thread) int nevents = 0; -__declspec(thread) WSAEVENT events[WSA_MAXIMUM_WAIT_EVENTS]; -__declspec(thread) ngx_connection_t *conn[WSA_MAXIMUM_WAIT_EVENTS]; +__declspec(thread) WSAEVENT events[WSA_MAXIMUM_WAIT_EVENTS + 1]; +__declspec(thread) ngx_connection_t *conn[WSA_MAXIMUM_WAIT_EVENTS + 1]; @@ -121,7 +121,7 @@ void ngx_iocp_wait_events(int main) conn[0] = NULL; for ( ;; ) { - offset = (nevents == WSA_MAXIMUM_WAIT_EVENTS) ? 1: 0; + offset = (nevents == WSA_MAXIMUM_WAIT_EVENTS + 1) ? 1: 0; timeout = (nevents == 1 && !first) ? 60000: INFINITE; n = WSAWaitForMultipleEvents(nevents - offset, events[offset], @@ -133,7 +133,7 @@ void ngx_iocp_wait_events(int main) } if (n == WAIT_TIMEOUT) { - if (nevents == 1 && !main) { + if (nevents == 2 && !main) { ExitThread(0); } @@ -145,9 +145,9 @@ void ngx_iocp_wait_events(int main) n -= WSA_WAIT_EVENT_0; - if (n == 0) { + if (events[n] == NULL) { - /* the first event is pending_connect_event */ + /* the pending_connect_event */ if (nevents == WSA_MAXIMUM_WAIT_EVENTS) { ngx_iocp_new_thread(0); diff --git a/src/event/ngx_event_pipe.c b/src/event/ngx_event_pipe.c --- a/src/event/ngx_event_pipe.c +++ b/src/event/ngx_event_pipe.c @@ -451,26 +451,22 @@ int ngx_event_pipe_write_to_downstream(n static int ngx_event_pipe_write_chain_to_temp_file(ngx_event_pipe_t *p) { int size, hsize; - char *save_pos; ngx_hunk_t *h; - ngx_chain_t *cl, *tl, *next, *out, **ll, **last_free; - - ngx_log_debug(p->log, "write to file"); + ngx_chain_t *cl, *tl, *next, *out, **ll, **last_free, fl; - out = p->in; - - if (out->hunk->type & NGX_HUNK_PREREAD) { - save_pos = out->hunk->pos; - out->hunk->pos = out->hunk->start; + if (p->hunk_to_file) { + fl.hunk = p->hunk_to_file; + fl.next = p->in; + out = &fl; } else { - save_pos = NULL; + out = p->in; } if (!p->cachable) { size = 0; - cl = p->in; + cl = out; ll = NULL; ngx_log_debug(p->log, "offset: %d" _ p->temp_file->offset); @@ -519,10 +515,10 @@ ngx_log_debug(p->log, "size: %d" _ size) /* void */ } - if (out->hunk->type & NGX_HUNK_PREREAD) { - p->temp_file->offset += save_pos - out->hunk->pos; - out->hunk->pos = save_pos; - out->hunk->type &= ~NGX_HUNK_PREREAD; + if (p->hunk_to_file) { + p->temp_file->offset = p->hunk_to_file->last - p->hunk_to_file->pos; + p->hunk_to_file = NULL; + out = out->next; } for (cl = out; cl; cl = next) { @@ -566,8 +562,6 @@ int ngx_event_pipe_copy_input_filter(ngx ngx_hunk_t *h; ngx_chain_t *cl; -ngx_log_debug(p->log, "COPY"); - if (hunk->pos == hunk->last) { return NGX_OK; } diff --git a/src/event/ngx_event_pipe.h b/src/event/ngx_event_pipe.h --- a/src/event/ngx_event_pipe.h +++ b/src/event/ngx_event_pipe.h @@ -15,6 +15,9 @@ typedef int (*ngx_event_pipe_output_filt struct ngx_event_pipe_s { + ngx_connection_t *upstream; + ngx_connection_t *downstream; + ngx_chain_t *free_raw_hunks; ngx_chain_t *in; ngx_chain_t **last_in; @@ -59,9 +62,6 @@ struct ngx_event_pipe_s { off_t max_temp_file_size; int temp_file_write_size; - ngx_connection_t *upstream; - ngx_connection_t *downstream; - ngx_msec_t read_timeout; ngx_msec_t send_timeout; ssize_t send_lowat; @@ -71,6 +71,7 @@ struct ngx_event_pipe_s { ngx_chain_t *preread_hunks; int preread_size; + ngx_hunk_t *hunk_to_file; ngx_temp_file_t *temp_file; diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c --- a/src/http/modules/proxy/ngx_http_proxy_upstream.c +++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c @@ -956,10 +956,18 @@ static void ngx_http_proxy_send_response } ep->preread_hunks->hunk = p->header_in; ep->preread_hunks->next = NULL; - p->header_in->type |= NGX_HUNK_PREREAD; ep->preread_size = p->header_in->last - p->header_in->pos; + ep->hunk_to_file = ngx_calloc_hunk(r->pool); + if (ep->preread_hunks == NULL) { + ngx_http_proxy_finalize_request(p, 0); + return; + } + ep->hunk_to_file->pos = p->header_in->start; + ep->hunk_to_file->last = p->header_in->pos; + ep->hunk_to_file->type = NGX_HUNK_IN_MEMORY|NGX_HUNK_TEMP; + if (ngx_event_flags & NGX_USE_AIO_EVENT) { /* the posted aio operation can currupt shadow buf */