mirror of
https://github.com/nginx/nginx.git
synced 2025-06-07 17:52:38 +08:00
nginx-0.0.1-2003-10-21-11:47:21 import
This commit is contained in:
parent
54276be80c
commit
9760a1336f
@ -10,6 +10,7 @@ ngx_inline static void ngx_remove_shadow_free_raw_hunk(ngx_chain_t **free,
|
|||||||
ngx_hunk_t *h);
|
ngx_hunk_t *h);
|
||||||
ngx_inline static void ngx_add_after_partially_filled_hunk(ngx_chain_t **chain,
|
ngx_inline static void ngx_add_after_partially_filled_hunk(ngx_chain_t **chain,
|
||||||
ngx_chain_t *ce);
|
ngx_chain_t *ce);
|
||||||
|
static int ngx_drain_chains(ngx_event_proxy_t *p);
|
||||||
|
|
||||||
|
|
||||||
int ngx_event_proxy(ngx_event_proxy_t *p, int do_write)
|
int ngx_event_proxy(ngx_event_proxy_t *p, int do_write)
|
||||||
@ -53,11 +54,22 @@ int ngx_event_proxy_read_upstream(ngx_event_proxy_t *p)
|
|||||||
ngx_hunk_t *h;
|
ngx_hunk_t *h;
|
||||||
ngx_chain_t *chain, *ce, *te;
|
ngx_chain_t *chain, *ce, *te;
|
||||||
|
|
||||||
|
if (p->upstream_eof || p->upstream_error || p->upstream_done) {
|
||||||
|
return NGX_OK;
|
||||||
|
}
|
||||||
|
|
||||||
ngx_log_debug(p->log, "read upstream: %d" _ p->upstream->read->ready);
|
ngx_log_debug(p->log, "read upstream: %d" _ p->upstream->read->ready);
|
||||||
|
|
||||||
while (p->preread_hunks
|
for ( ;; ) {
|
||||||
|| (p->upstream->read->ready && !p->upstream_done))
|
|
||||||
{
|
if (p->upstream_eof || p->upstream_error || p->upstream_done) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p->preread_hunks == NULL && !p->upstream->read->ready) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (p->preread_hunks) {
|
if (p->preread_hunks) {
|
||||||
|
|
||||||
/* use the pre-read hunks if they exist */
|
/* use the pre-read hunks if they exist */
|
||||||
@ -184,14 +196,12 @@ ngx_log_debug(p->log, "FREE: %08X:%d" _ chain->hunk->pos _ chain->hunk->end - ch
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO THINK about eof */
|
|
||||||
p->read = 1;
|
p->read = 1;
|
||||||
|
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
p->upstream_eof = 1;
|
p->upstream_eof = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ce = chain;
|
ce = chain;
|
||||||
@ -244,13 +254,16 @@ ngx_log_debug(p->log, "PART: %08X:%d" _ ce->hunk->pos _ ce->hunk->end - ce->hunk
|
|||||||
|
|
||||||
int ngx_event_proxy_write_to_downstream(ngx_event_proxy_t *p)
|
int ngx_event_proxy_write_to_downstream(ngx_event_proxy_t *p)
|
||||||
{
|
{
|
||||||
int rc;
|
size_t busy_len;
|
||||||
ngx_hunk_t *h;
|
ngx_hunk_t *h;
|
||||||
ngx_chain_t *out, *ce, *te;
|
ngx_chain_t *out, *ce, *te;
|
||||||
|
|
||||||
ngx_log_debug(p->log, "write downstream: %d" _ p->downstream->write->ready);
|
ngx_log_debug(p->log, "write downstream: %d" _ p->downstream->write->ready);
|
||||||
|
|
||||||
for ( ;; ) {
|
for ( ;; ) {
|
||||||
|
if (p->downstream_error) {
|
||||||
|
return ngx_drain_chains(p);
|
||||||
|
}
|
||||||
|
|
||||||
if ((p->upstream_eof || p->upstream_error || p->upstream_done)
|
if ((p->upstream_eof || p->upstream_error || p->upstream_done)
|
||||||
&& p->out == NULL && p->in == NULL)
|
&& p->out == NULL && p->in == NULL)
|
||||||
@ -263,10 +276,22 @@ int ngx_event_proxy_write_to_downstream(ngx_event_proxy_t *p)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
busy_len = 0;
|
||||||
|
|
||||||
|
if (!(p->upstream_eof || p->upstream_error || p->upstream_done)) {
|
||||||
|
/* calculate p->busy_len */
|
||||||
|
for (ce = p->busy; ce; ce = ce->next) {
|
||||||
|
busy_len += ngx_hunk_size(ce->hunk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (p->out) {
|
if (p->out) {
|
||||||
out = p->out;
|
out = p->out;
|
||||||
|
|
||||||
if (p->busy_len + ngx_hunk_size(out->hunk) > p->max_busy_len) {
|
if (!(p->upstream_eof || p->upstream_error || p->upstream_done)
|
||||||
|
&& (busy_len + ngx_hunk_size(out->hunk) > p->max_busy_len))
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -277,7 +302,7 @@ int ngx_event_proxy_write_to_downstream(ngx_event_proxy_t *p)
|
|||||||
out = p->in;
|
out = p->in;
|
||||||
|
|
||||||
if (!(p->upstream_eof || p->upstream_error || p->upstream_done)
|
if (!(p->upstream_eof || p->upstream_error || p->upstream_done)
|
||||||
&& (p->busy_len + ngx_hunk_size(out->hunk) > p->max_busy_len))
|
&& (busy_len + ngx_hunk_size(out->hunk) > p->max_busy_len))
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -290,22 +315,14 @@ int ngx_event_proxy_write_to_downstream(ngx_event_proxy_t *p)
|
|||||||
|
|
||||||
out->next = NULL;
|
out->next = NULL;
|
||||||
|
|
||||||
rc = p->output_filter(p->output_ctx, out->hunk);
|
|
||||||
|
|
||||||
if (rc == NGX_ERROR) {
|
if (p->output_filter(p->output_ctx, out->hunk) == NGX_ERROR) {
|
||||||
p->downstream_error = 1;
|
p->downstream_error = 1;
|
||||||
return NGX_ERROR;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ngx_chain_update_chains(&p->free, &p->busy, &out);
|
ngx_chain_update_chains(&p->free, &p->busy, &out);
|
||||||
|
|
||||||
/* calculate p->busy_len */
|
|
||||||
|
|
||||||
p->busy_len = 0;
|
|
||||||
for (ce = p->busy; ce; ce = ce->next) {
|
|
||||||
p->busy_len += ngx_hunk_size(ce->hunk);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* add the free shadow raw hunks to p->free_raw_hunks */
|
/* add the free shadow raw hunks to p->free_raw_hunks */
|
||||||
|
|
||||||
for (ce = p->free; ce; ce = ce->next) {
|
for (ce = p->free; ce; ce = ce->next) {
|
||||||
@ -323,13 +340,6 @@ ngx_log_debug(p->log, "RAW %08X" _ h->pos);
|
|||||||
}
|
}
|
||||||
ce->hunk->shadow = NULL;
|
ce->hunk->shadow = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0 /* TODO THINK p->read_priority ??? */
|
|
||||||
if (p->upstream->read->ready) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngx_log_debug(p->log, "STATE %d:%d:%d:%X:%X" _
|
ngx_log_debug(p->log, "STATE %d:%d:%d:%X:%X" _
|
||||||
@ -340,21 +350,15 @@ ngx_log_debug(p->log, "RAW %08X" _ h->pos);
|
|||||||
p->out
|
p->out
|
||||||
);
|
);
|
||||||
|
|
||||||
if ((p->upstream_eof || p->upstream_error || p->upstream_done)
|
|
||||||
&& p->in == NULL && p->out == NULL)
|
|
||||||
{
|
|
||||||
p->downstream_done = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int ngx_event_proxy_write_chain_to_temp_file(ngx_event_proxy_t *p)
|
static int ngx_event_proxy_write_chain_to_temp_file(ngx_event_proxy_t *p)
|
||||||
{
|
{
|
||||||
int rc, size;
|
int rc, size, hunk_size;
|
||||||
ngx_hunk_t *h;
|
ngx_hunk_t *h;
|
||||||
ngx_chain_t *ce, *te, *next, *in, **last, **last_free;
|
ngx_chain_t *ce, *te, *next, *in, **le, **last_free;
|
||||||
|
|
||||||
ngx_log_debug(p->log, "write to file");
|
ngx_log_debug(p->log, "write to file");
|
||||||
|
|
||||||
@ -379,31 +383,41 @@ static int ngx_event_proxy_write_chain_to_temp_file(ngx_event_proxy_t *p)
|
|||||||
|
|
||||||
size = 0;
|
size = 0;
|
||||||
ce = p->in;
|
ce = p->in;
|
||||||
|
le = NULL;
|
||||||
|
|
||||||
|
ngx_log_debug(p->log, "offset: %d" _ p->temp_offset);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (size + ce->hunk->last - ce->hunk->pos
|
hunk_size = ce->hunk->last - ce->hunk->pos;
|
||||||
>= p->temp_file_write_size)
|
|
||||||
|
ngx_log_debug(p->log, "hunk size: %d" _ hunk_size);
|
||||||
|
|
||||||
|
if ((size + hunk_size > p->temp_file_write_size)
|
||||||
|
|| (p->temp_offset + hunk_size > p->max_temp_file_size))
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
size += ce->hunk->last - ce->hunk->pos;
|
|
||||||
|
size += hunk_size;
|
||||||
|
le = &ce->next;
|
||||||
ce = ce->next;
|
ce = ce->next;
|
||||||
|
|
||||||
} while (ce);
|
} while (ce);
|
||||||
|
|
||||||
|
ngx_log_debug(p->log, "size: %d" _ size);
|
||||||
|
|
||||||
if (ce) {
|
if (ce) {
|
||||||
in = ce->next;
|
in = ce;
|
||||||
last = &ce->next;
|
*le = NULL;
|
||||||
ce->next = NULL;
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
in = NULL;
|
in = NULL;
|
||||||
last = &p->in;
|
p->last_in = &p->in;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
in = NULL;
|
in = NULL;
|
||||||
last = &p->in;
|
p->last_in = &p->in;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ngx_write_chain_to_file(p->temp_file, p->in, p->temp_offset,
|
if (ngx_write_chain_to_file(p->temp_file, p->in, p->temp_offset,
|
||||||
@ -413,7 +427,7 @@ static int ngx_event_proxy_write_chain_to_temp_file(ngx_event_proxy_t *p)
|
|||||||
|
|
||||||
for (last_free = &p->free_raw_hunks;
|
for (last_free = &p->free_raw_hunks;
|
||||||
*last_free != NULL;
|
*last_free != NULL;
|
||||||
last_free = &(*last)->next)
|
last_free = &(*last_free)->next)
|
||||||
{
|
{
|
||||||
/* void */
|
/* void */
|
||||||
}
|
}
|
||||||
@ -440,7 +454,6 @@ static int ngx_event_proxy_write_chain_to_temp_file(ngx_event_proxy_t *p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
p->in = in;
|
p->in = in;
|
||||||
p->last_in = last;
|
|
||||||
|
|
||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
}
|
}
|
||||||
@ -552,3 +565,43 @@ ngx_inline static void ngx_add_after_partially_filled_hunk(ngx_chain_t **chain,
|
|||||||
(*chain) = ce;
|
(*chain) = ce;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int ngx_drain_chains(ngx_event_proxy_t *p)
|
||||||
|
{
|
||||||
|
ngx_hunk_t *h;
|
||||||
|
ngx_chain_t *ce, *te;
|
||||||
|
|
||||||
|
for ( ;; ) {
|
||||||
|
if (p->busy) {
|
||||||
|
ce = p->busy;
|
||||||
|
|
||||||
|
} else if (p->out) {
|
||||||
|
ce = p->out;
|
||||||
|
|
||||||
|
} else if (p->in) {
|
||||||
|
ce = p->in;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return NGX_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (ce) {
|
||||||
|
if (ce->hunk->type & NGX_HUNK_LAST_SHADOW) {
|
||||||
|
h = ce->hunk->shadow;
|
||||||
|
/* THINK NEEDED ??? */ h->pos = h->last = h->start;
|
||||||
|
h->shadow = NULL;
|
||||||
|
ngx_alloc_ce_and_set_hunk(te, h, p->pool, NGX_ABORT);
|
||||||
|
ngx_add_after_partially_filled_hunk(&p->free_raw_hunks, te);
|
||||||
|
|
||||||
|
ce->hunk->type &= ~NGX_HUNK_LAST_SHADOW;
|
||||||
|
}
|
||||||
|
|
||||||
|
ce->hunk->shadow = NULL;
|
||||||
|
te = ce->next;
|
||||||
|
ce->next = p->free;
|
||||||
|
p->free = ce;
|
||||||
|
ce = te;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -47,7 +47,6 @@ struct ngx_event_proxy_s {
|
|||||||
int hunks;
|
int hunks;
|
||||||
ngx_bufs_t bufs;
|
ngx_bufs_t bufs;
|
||||||
|
|
||||||
size_t busy_len;
|
|
||||||
size_t max_busy_len;
|
size_t max_busy_len;
|
||||||
|
|
||||||
off_t temp_offset;
|
off_t temp_offset;
|
||||||
|
@ -742,6 +742,12 @@ static void ngx_http_proxy_send_response(ngx_http_proxy_ctx_t *p)
|
|||||||
|
|
||||||
ep->preread_size = p->header_in->last - p->header_in->pos;
|
ep->preread_size = p->header_in->last - p->header_in->pos;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* event_proxy would do p->header_in->last += ep->preread_size
|
||||||
|
* as these bytes were read.
|
||||||
|
*/
|
||||||
|
p->header_in->last = p->header_in->pos;
|
||||||
|
|
||||||
/* STUB */ ep->cachable = 0;
|
/* STUB */ ep->cachable = 0;
|
||||||
|
|
||||||
p->event_proxy = ep;
|
p->event_proxy = ep;
|
||||||
@ -806,7 +812,7 @@ static void ngx_http_proxy_process_body(ngx_event_t *ev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (ep->upstream_done || ep->upstream_eof || ep->upstream_error) {
|
if (ep->upstream_done || ep->upstream_eof || ep->upstream_error) {
|
||||||
ngx_http_proxy_close_connection(c);
|
ngx_http_proxy_close_connection(p->upstream.connection);
|
||||||
p->upstream.connection = NULL;
|
p->upstream.connection = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -819,7 +825,7 @@ static void ngx_http_proxy_process_body(ngx_event_t *ev)
|
|||||||
|
|
||||||
if (ep->downstream_error) {
|
if (ep->downstream_error) {
|
||||||
if (!p->cachable && p->upstream.connection) {
|
if (!p->cachable && p->upstream.connection) {
|
||||||
ngx_http_proxy_close_connection(c);
|
ngx_http_proxy_close_connection(p->upstream.connection);
|
||||||
p->upstream.connection = NULL;
|
p->upstream.connection = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1052,7 +1058,9 @@ static void ngx_http_proxy_finalize_request(ngx_http_proxy_ctx_t *p, int rc)
|
|||||||
p->upstream.connection = NULL;
|
p->upstream.connection = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p->header_sent) {
|
if (p->header_sent
|
||||||
|
&& (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE))
|
||||||
|
{
|
||||||
rc = 0;
|
rc = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1152,7 +1160,12 @@ static void *ngx_http_proxy_create_loc_conf(ngx_conf_t *cf)
|
|||||||
conf->bufs.num = 10;
|
conf->bufs.num = 10;
|
||||||
conf->bufs.size = 4096;
|
conf->bufs.size = 4096;
|
||||||
conf->max_busy_len = 8192 + 4096;
|
conf->max_busy_len = 8192 + 4096;
|
||||||
|
|
||||||
|
|
||||||
|
/* CHECK in _init conf->max_temp_size >= conf->bufs.size !!! */
|
||||||
conf->max_temp_file_size = 4096 * 6;
|
conf->max_temp_file_size = 4096 * 6;
|
||||||
|
|
||||||
|
|
||||||
conf->temp_file_write_size = 4096 * 2;
|
conf->temp_file_write_size = 4096 * 2;
|
||||||
|
|
||||||
ngx_test_null(conf->temp_path, ngx_pcalloc(cf->pool, sizeof(ngx_path_t)),
|
ngx_test_null(conf->temp_path, ngx_pcalloc(cf->pool, sizeof(ngx_path_t)),
|
||||||
|
@ -207,13 +207,31 @@ void ngx_http_handler(ngx_http_request_t *r)
|
|||||||
lcx = r->connection->log->data;
|
lcx = r->connection->log->data;
|
||||||
lcx->action = NULL;
|
lcx->action = NULL;
|
||||||
|
|
||||||
|
/* STUB */
|
||||||
r->keepalive = 1;
|
r->keepalive = 1;
|
||||||
|
if (r->headers_in.connection) {
|
||||||
|
if (r->headers_in.connection->value.len == 5
|
||||||
|
&& ngx_strcasecmp(r->headers_in.connection->value.data, "close")
|
||||||
|
== 0)
|
||||||
|
{
|
||||||
|
r->keepalive = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
/* TEST STUB */ r->keepalive = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (r->headers_in.content_length_n > 0) {
|
if (r->headers_in.content_length_n > 0) {
|
||||||
r->lingering_close = 1;
|
r->lingering_close = 1;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
r->lingering_close = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
/* TEST STUB */ r->lingering_close = 1;
|
/* TEST STUB */ r->lingering_close = 1;
|
||||||
|
#endif
|
||||||
|
|
||||||
r->connection->write->event_handler = ngx_http_phase_event_handler;
|
r->connection->write->event_handler = ngx_http_phase_event_handler;
|
||||||
|
|
||||||
@ -258,6 +276,11 @@ static void ngx_http_run_phases(ngx_http_request_t *r)
|
|||||||
{
|
{
|
||||||
rc = h[r->phase_handler](r);
|
rc = h[r->phase_handler](r);
|
||||||
|
|
||||||
|
if (rc == NGX_DONE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TODO THINK: is it dupliate NGX_DONE ??? */
|
||||||
if (r->closed) {
|
if (r->closed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -435,7 +458,7 @@ int ngx_http_internal_redirect(ngx_http_request_t *r,
|
|||||||
|
|
||||||
ngx_http_handler(r);
|
ngx_http_handler(r);
|
||||||
|
|
||||||
return NGX_OK;
|
return NGX_DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -583,6 +583,7 @@ static void ngx_http_process_request_headers(ngx_event_t *rev)
|
|||||||
if (ngx_strcasecmp(headers_in[i].name.data, h->key.data) == 0) {
|
if (ngx_strcasecmp(headers_in[i].name.data, h->key.data) == 0) {
|
||||||
*((ngx_table_elt_t **)
|
*((ngx_table_elt_t **)
|
||||||
((char *) &r->headers_in + headers_in[i].offset)) = h;
|
((char *) &r->headers_in + headers_in[i].offset)) = h;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ int ngx_os_init(ngx_log_t *log)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* The determination of the sendfile() nbytes bug is complex enough.
|
* The determination of the sendfile() nbytes bug is complex enough.
|
||||||
* There're two sendfile() syscalls: a new 393 has no bug while
|
* There are two sendfile() syscalls: a new 393 has no bug while
|
||||||
* an old 336 has the bug in some versions and has not in others.
|
* an old 336 has the bug in some versions and has not in others.
|
||||||
* Besides libc_r wrapper also emulates the bug in some versions.
|
* Besides libc_r wrapper also emulates the bug in some versions.
|
||||||
* There's no way to say exactly if a given FreeBSD version has the bug.
|
* There's no way to say exactly if a given FreeBSD version has the bug.
|
||||||
|
@ -14,8 +14,8 @@
|
|||||||
* and the first part of the file in one packet but also sends 4K pages
|
* and the first part of the file in one packet but also sends 4K pages
|
||||||
* in the full packets.
|
* in the full packets.
|
||||||
*
|
*
|
||||||
* Until FreeBSD 4.5 the turning TCP_NOPUSH off does not flush
|
* Until FreeBSD 4.5 the turning TCP_NOPUSH off does not flush the pending
|
||||||
* the pending data that less than MSS so the data is sent with 5 second delay.
|
* data that less than MSS so the data can be sent with 5 second delay.
|
||||||
* We do not use TCP_NOPUSH on FreeBSD prior to 4.5 although it can be used
|
* We do not use TCP_NOPUSH on FreeBSD prior to 4.5 although it can be used
|
||||||
* for non-keepalive HTTP connections.
|
* for non-keepalive HTTP connections.
|
||||||
*/
|
*/
|
||||||
@ -23,10 +23,10 @@
|
|||||||
|
|
||||||
ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in)
|
ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in)
|
||||||
{
|
{
|
||||||
int rc, eintr;
|
int rc, eintr, eagain;
|
||||||
char *prev;
|
char *prev;
|
||||||
ssize_t hsize, size;
|
ssize_t hsize, fsize, size;
|
||||||
off_t sent;
|
off_t sent, fprev;
|
||||||
struct iovec *iov;
|
struct iovec *iov;
|
||||||
struct sf_hdtr hdtr;
|
struct sf_hdtr hdtr;
|
||||||
ngx_err_t err;
|
ngx_err_t err;
|
||||||
@ -41,8 +41,10 @@ ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in)
|
|||||||
do {
|
do {
|
||||||
ce = in;
|
ce = in;
|
||||||
file = NULL;
|
file = NULL;
|
||||||
|
fsize = 0;
|
||||||
hsize = 0;
|
hsize = 0;
|
||||||
eintr = 0;
|
eintr = 0;
|
||||||
|
eagain = 0;
|
||||||
|
|
||||||
ngx_init_array(header, c->pool, 10, sizeof(struct iovec),
|
ngx_init_array(header, c->pool, 10, sizeof(struct iovec),
|
||||||
NGX_CHAIN_ERROR);
|
NGX_CHAIN_ERROR);
|
||||||
@ -77,11 +79,27 @@ ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in)
|
|||||||
hsize += ce->hunk->last - ce->hunk->pos;
|
hsize += ce->hunk->last - ce->hunk->pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: coalesce the neighbouring file hunks */
|
/* get the file hunk */
|
||||||
|
|
||||||
if (ce && (ce->hunk->type & NGX_HUNK_FILE)) {
|
if (ce && (ce->hunk->type & NGX_HUNK_FILE)) {
|
||||||
file = ce->hunk;
|
file = ce->hunk;
|
||||||
ce = ce->next;
|
ce = ce->next;
|
||||||
|
fsize = (size_t) (file->file_last - file->file_pos);
|
||||||
|
fprev = file->file_last;
|
||||||
|
|
||||||
|
/* coalesce the neighbouring file hunks */
|
||||||
|
|
||||||
|
while (ce && (ce->hunk->type & NGX_HUNK_FILE)) {
|
||||||
|
if (file->file->fd != ce->hunk->file->fd
|
||||||
|
|| fprev != ce->hunk->file_pos)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
fsize += (size_t) (ce->hunk->file_last - ce->hunk->file_pos);
|
||||||
|
fprev = ce->hunk->file_last;
|
||||||
|
ce = ce->next;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create the iovec and coalesce the neighbouring chain entries */
|
/* create the iovec and coalesce the neighbouring chain entries */
|
||||||
@ -110,6 +128,11 @@ ngx_chain_t *ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* the tail is the rest of the chain that exceeded
|
||||||
|
* a single sendfile() capability
|
||||||
|
*/
|
||||||
|
|
||||||
tail = ce;
|
tail = ce;
|
||||||
|
|
||||||
if (file) {
|
if (file) {
|
||||||
@ -136,8 +159,7 @@ ngx_log_debug(c->log, "NOPUSH");
|
|||||||
}
|
}
|
||||||
|
|
||||||
rc = sendfile(file->file->fd, c->fd, file->file_pos,
|
rc = sendfile(file->file->fd, c->fd, file->file_pos,
|
||||||
(size_t) (file->file_last - file->file_pos) + hsize,
|
fsize + hsize, &hdtr, &sent, 0);
|
||||||
&hdtr, &sent, 0);
|
|
||||||
|
|
||||||
if (rc == -1) {
|
if (rc == -1) {
|
||||||
err = ngx_errno;
|
err = ngx_errno;
|
||||||
@ -146,6 +168,10 @@ ngx_log_debug(c->log, "NOPUSH");
|
|||||||
eintr = 1;
|
eintr = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (err == NGX_EAGAIN) {
|
||||||
|
eagain = 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (err == NGX_EAGAIN || err == NGX_EINTR) {
|
if (err == NGX_EAGAIN || err == NGX_EINTR) {
|
||||||
ngx_log_error(NGX_LOG_INFO, c->log, err,
|
ngx_log_error(NGX_LOG_INFO, c->log, err,
|
||||||
"sendfile() sent only %qd bytes", sent);
|
"sendfile() sent only %qd bytes", sent);
|
||||||
@ -159,8 +185,7 @@ ngx_log_debug(c->log, "NOPUSH");
|
|||||||
|
|
||||||
#if (NGX_DEBUG_WRITE_CHAIN)
|
#if (NGX_DEBUG_WRITE_CHAIN)
|
||||||
ngx_log_debug(c->log, "sendfile: %d, @%qd %qd:%d" _
|
ngx_log_debug(c->log, "sendfile: %d, @%qd %qd:%d" _
|
||||||
rc _ file->file_pos _ sent _
|
rc _ file->file_pos _ sent _ fsize + hsize);
|
||||||
(size_t) (file->file_last - file->file_pos) + hsize);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -169,6 +194,7 @@ ngx_log_debug(c->log, "NOPUSH");
|
|||||||
if (rc == -1) {
|
if (rc == -1) {
|
||||||
err = ngx_errno;
|
err = ngx_errno;
|
||||||
if (err == NGX_EAGAIN) {
|
if (err == NGX_EAGAIN) {
|
||||||
|
eagain = 1;
|
||||||
ngx_log_error(NGX_LOG_INFO, c->log, err, "writev() EAGAIN");
|
ngx_log_error(NGX_LOG_INFO, c->log, err, "writev() EAGAIN");
|
||||||
|
|
||||||
} else if (err == NGX_EINTR) {
|
} else if (err == NGX_EINTR) {
|
||||||
@ -190,14 +216,18 @@ ngx_log_debug(c->log, "NOPUSH");
|
|||||||
|
|
||||||
c->sent += sent;
|
c->sent += sent;
|
||||||
|
|
||||||
for (ce = in; ce && sent > 0; ce = ce->next) {
|
for (ce = in; ce; ce = ce->next) {
|
||||||
|
|
||||||
if (ce->hunk->type & NGX_HUNK_IN_MEMORY) {
|
if (ngx_hunk_special(ce->hunk)) {
|
||||||
size = ce->hunk->last - ce->hunk->pos;
|
continue;
|
||||||
} else {
|
|
||||||
size = ce->hunk->file_last - ce->hunk->file_pos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sent == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
size = ngx_hunk_size(ce->hunk);
|
||||||
|
|
||||||
if (sent >= size) {
|
if (sent >= size) {
|
||||||
sent -= size;
|
sent -= size;
|
||||||
|
|
||||||
@ -223,16 +253,20 @@ ngx_log_debug(c->log, "NOPUSH");
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ngx_destroy_array(&trailer);
|
|
||||||
ngx_destroy_array(&header);
|
|
||||||
|
|
||||||
in = ce;
|
in = ce;
|
||||||
|
|
||||||
} while ((tail && tail == ce) || eintr);
|
if (eagain) {
|
||||||
|
c->write->ready = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (ce) {
|
/* "tail == in" means that a single sendfile() is complete */
|
||||||
|
|
||||||
|
} while ((tail && tail == in) || eintr);
|
||||||
|
|
||||||
|
if (in) {
|
||||||
c->write->ready = 0;
|
c->write->ready = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ce;
|
return in;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user