nginx-0.0.1-2003-11-17-19:15:03 import

This commit is contained in:
Igor Sysoev 2003-11-17 16:15:03 +00:00
parent f2e676aa15
commit d7fdb3535b
4 changed files with 30 additions and 27 deletions

View File

@ -14,8 +14,8 @@ static ngx_connection_t pending_connects[NGX_MAX_PENDING_CONN];
static HANDLE pending_connect_event; static HANDLE pending_connect_event;
__declspec(thread) int nevents = 0; __declspec(thread) int nevents = 0;
__declspec(thread) WSAEVENT events[WSA_MAXIMUM_WAIT_EVENTS]; __declspec(thread) WSAEVENT events[WSA_MAXIMUM_WAIT_EVENTS + 1];
__declspec(thread) ngx_connection_t *conn[WSA_MAXIMUM_WAIT_EVENTS]; __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; conn[0] = NULL;
for ( ;; ) { for ( ;; ) {
offset = (nevents == WSA_MAXIMUM_WAIT_EVENTS) ? 1: 0; offset = (nevents == WSA_MAXIMUM_WAIT_EVENTS + 1) ? 1: 0;
timeout = (nevents == 1 && !first) ? 60000: INFINITE; timeout = (nevents == 1 && !first) ? 60000: INFINITE;
n = WSAWaitForMultipleEvents(nevents - offset, events[offset], n = WSAWaitForMultipleEvents(nevents - offset, events[offset],
@ -133,7 +133,7 @@ void ngx_iocp_wait_events(int main)
} }
if (n == WAIT_TIMEOUT) { if (n == WAIT_TIMEOUT) {
if (nevents == 1 && !main) { if (nevents == 2 && !main) {
ExitThread(0); ExitThread(0);
} }
@ -145,9 +145,9 @@ void ngx_iocp_wait_events(int main)
n -= WSA_WAIT_EVENT_0; 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) { if (nevents == WSA_MAXIMUM_WAIT_EVENTS) {
ngx_iocp_new_thread(0); ngx_iocp_new_thread(0);

View File

@ -451,26 +451,22 @@ int ngx_event_pipe_write_to_downstream(ngx_event_pipe_t *p)
static int ngx_event_pipe_write_chain_to_temp_file(ngx_event_pipe_t *p) static int ngx_event_pipe_write_chain_to_temp_file(ngx_event_pipe_t *p)
{ {
int size, hsize; int size, hsize;
char *save_pos;
ngx_hunk_t *h; ngx_hunk_t *h;
ngx_chain_t *cl, *tl, *next, *out, **ll, **last_free; ngx_chain_t *cl, *tl, *next, *out, **ll, **last_free, fl;
ngx_log_debug(p->log, "write to file"); if (p->hunk_to_file) {
fl.hunk = p->hunk_to_file;
out = p->in; fl.next = p->in;
out = &fl;
if (out->hunk->type & NGX_HUNK_PREREAD) {
save_pos = out->hunk->pos;
out->hunk->pos = out->hunk->start;
} else { } else {
save_pos = NULL; out = p->in;
} }
if (!p->cachable) { if (!p->cachable) {
size = 0; size = 0;
cl = p->in; cl = out;
ll = NULL; ll = NULL;
ngx_log_debug(p->log, "offset: %d" _ p->temp_file->offset); ngx_log_debug(p->log, "offset: %d" _ p->temp_file->offset);
@ -519,10 +515,10 @@ ngx_log_debug(p->log, "size: %d" _ size);
/* void */ /* void */
} }
if (out->hunk->type & NGX_HUNK_PREREAD) { if (p->hunk_to_file) {
p->temp_file->offset += save_pos - out->hunk->pos; p->temp_file->offset = p->hunk_to_file->last - p->hunk_to_file->pos;
out->hunk->pos = save_pos; p->hunk_to_file = NULL;
out->hunk->type &= ~NGX_HUNK_PREREAD; out = out->next;
} }
for (cl = out; cl; cl = next) { for (cl = out; cl; cl = next) {
@ -566,8 +562,6 @@ int ngx_event_pipe_copy_input_filter(ngx_event_pipe_t *p, ngx_hunk_t *hunk)
ngx_hunk_t *h; ngx_hunk_t *h;
ngx_chain_t *cl; ngx_chain_t *cl;
ngx_log_debug(p->log, "COPY");
if (hunk->pos == hunk->last) { if (hunk->pos == hunk->last) {
return NGX_OK; return NGX_OK;
} }

View File

@ -15,6 +15,9 @@ typedef int (*ngx_event_pipe_output_filter_pt)(void *data, ngx_chain_t *chain);
struct ngx_event_pipe_s { struct ngx_event_pipe_s {
ngx_connection_t *upstream;
ngx_connection_t *downstream;
ngx_chain_t *free_raw_hunks; ngx_chain_t *free_raw_hunks;
ngx_chain_t *in; ngx_chain_t *in;
ngx_chain_t **last_in; ngx_chain_t **last_in;
@ -59,9 +62,6 @@ struct ngx_event_pipe_s {
off_t max_temp_file_size; off_t max_temp_file_size;
int temp_file_write_size; int temp_file_write_size;
ngx_connection_t *upstream;
ngx_connection_t *downstream;
ngx_msec_t read_timeout; ngx_msec_t read_timeout;
ngx_msec_t send_timeout; ngx_msec_t send_timeout;
ssize_t send_lowat; ssize_t send_lowat;
@ -71,6 +71,7 @@ struct ngx_event_pipe_s {
ngx_chain_t *preread_hunks; ngx_chain_t *preread_hunks;
int preread_size; int preread_size;
ngx_hunk_t *hunk_to_file;
ngx_temp_file_t *temp_file; ngx_temp_file_t *temp_file;

View File

@ -956,10 +956,18 @@ static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p)
} }
ep->preread_hunks->hunk = p->header_in; ep->preread_hunks->hunk = p->header_in;
ep->preread_hunks->next = NULL; ep->preread_hunks->next = NULL;
p->header_in->type |= NGX_HUNK_PREREAD;
ep->preread_size = p->header_in->last - p->header_in->pos; 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) { if (ngx_event_flags & NGX_USE_AIO_EVENT) {
/* the posted aio operation can currupt shadow buf */ /* the posted aio operation can currupt shadow buf */