mirror of
https://github.com/nginx/nginx.git
synced 2024-12-20 06:03:31 -06:00
nginx-0.0.1-2003-02-26-23:21:43 import
This commit is contained in:
parent
9a5f495afd
commit
ff148df8f6
@ -79,4 +79,19 @@ EV_VNODE should notify by some signal if diretory tree is changed
|
|||||||
or stat if aged >= N seconds (big enough)
|
or stat if aged >= N seconds (big enough)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
extern ngx_chain_t *(*ngx_write_chain_proc)
|
||||||
|
(ngx_connection_t *c, ngx_chain_t *in);
|
||||||
|
|
||||||
|
|
||||||
|
ngx_chain_t *ngx_write_chain(ngx_connection_t *c, ngx_chain_t *in, off_t flush);
|
||||||
|
|
||||||
|
|
||||||
|
/* TODO: move it to OS specific file */
|
||||||
|
#if (__FreeBSD__)
|
||||||
|
ngx_chain_t *ngx_freebsd_write_chain(ngx_connection_t *c, ngx_chain_t *in);
|
||||||
|
ngx_chain_t *ngx_aio_write_chain(ngx_connection_t *c, ngx_chain_t *in);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif /* _NGX_CONNECTION_H_INCLUDED_ */
|
#endif /* _NGX_CONNECTION_H_INCLUDED_ */
|
||||||
|
@ -7,197 +7,44 @@
|
|||||||
#include <ngx_array.h>
|
#include <ngx_array.h>
|
||||||
#include <ngx_hunk.h>
|
#include <ngx_hunk.h>
|
||||||
#include <ngx_connection.h>
|
#include <ngx_connection.h>
|
||||||
#include <ngx_sendv.h>
|
|
||||||
#include <ngx_sendfile.h>
|
|
||||||
|
|
||||||
#include <ngx_write_chain.h>
|
|
||||||
|
ngx_chain_t *(*ngx_write_chain_proc)(ngx_connection_t *c, ngx_chain_t *in);
|
||||||
|
|
||||||
|
|
||||||
ngx_chain_t *ngx_write_chain(ngx_connection_t *c, ngx_chain_t *in, off_t flush)
|
ngx_chain_t *ngx_write_chain(ngx_connection_t *c, ngx_chain_t *in, off_t flush)
|
||||||
{
|
{
|
||||||
int rc, i, last;
|
#if (NGX_EVENT)
|
||||||
u_int flags;
|
|
||||||
char *prev;
|
return (*ngx_write_chain_proc)(c, in);
|
||||||
|
|
||||||
|
#elif (NGX_EVENT_THREAD)
|
||||||
|
|
||||||
off_t sent;
|
off_t sent;
|
||||||
ngx_iovec_t *iov;
|
ngx_chain_t *rc;
|
||||||
ngx_array_t header, trailer;
|
|
||||||
ngx_hunk_t *file;
|
|
||||||
ngx_chain_t *ce;
|
|
||||||
|
|
||||||
ch = in;
|
sent = flush - c->sent;
|
||||||
file = NULL;
|
|
||||||
last = 0;
|
|
||||||
|
|
||||||
ngx_init_array(header, c->pool, 10, sizeof(ngx_iovec_t), NGX_CHAIN_ERROR);
|
|
||||||
ngx_init_array(trailer, c->pool, 10, sizeof(ngx_iovec_t), NGX_CHAIN_ERROR);
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
header.nelts = 0;
|
rc = (*ngx_write_chain_proc)(c, in);
|
||||||
trailer.nelts = 0;
|
|
||||||
|
|
||||||
if (ce->hunk->type & NGX_HUNK_IN_MEMORY) {
|
if (rc == NGX_CHAIN_ERROR && rc == NULL) {
|
||||||
prev = NULL;
|
return rc;
|
||||||
iov = NULL;
|
|
||||||
|
|
||||||
/* create iovec and coalesce the neighbouring chain entries */
|
|
||||||
while (ce && (ce->hunk->type & NGX_HUNK_IN_MEMORY))
|
|
||||||
{
|
|
||||||
if (prev == ce->hunk->pos.mem) {
|
|
||||||
iov->ngx_iov_len += ce->hunk->last.mem - ce->hunk->pos.mem;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
ngx_test_null(iov, ngx_push_array(&header),
|
|
||||||
NGX_CHAIN_ERROR);
|
|
||||||
iov->ngx_iov_base = ce->hunk->pos.mem;
|
|
||||||
iov->ngx_iov_len = ce->hunk->last.mem - ce->hunk->pos.mem;
|
|
||||||
prev = ce->hunk->last.mem;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ce->hunk->type & NGX_HUNK_LAST) {
|
|
||||||
last = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ce = ce->next;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ce && (ce->hunk->type & NGX_HUNK_FILE)) {
|
} while (c->thread && flush > c->sent - sent);
|
||||||
file = ce->hunk;
|
|
||||||
ce = ce->next;
|
|
||||||
|
|
||||||
if (ce->hunk->type & NGX_HUNK_LAST) {
|
#else
|
||||||
last = 1;
|
|
||||||
}
|
ngx_chain_t *rc;
|
||||||
}
|
|
||||||
|
do {
|
||||||
|
|
||||||
|
rc = (*ngx_write_chain_proc)(c, in);
|
||||||
|
|
||||||
|
} while (rc != NGX_CHAIN_ERROR && rc != NULL);
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
|
||||||
#if (HAVE_MAX_SENDFILE_IOVEC)
|
|
||||||
if (file && header->nelts > HAVE_MAX_SENDFILE_IOVEC) {
|
|
||||||
rc = ngx_sendv(c->fd, (ngx_iovec_t *) header->elts, header->nelts,
|
|
||||||
&sent);
|
|
||||||
} else {
|
|
||||||
#endif
|
#endif
|
||||||
if (ch && ch->hunk->type & NGX_HUNK_IN_MEMORY) {
|
|
||||||
prev = NULL;
|
|
||||||
iov = NULL;
|
|
||||||
|
|
||||||
while (ch && (ch->hunk->type & NGX_HUNK_IN_MEMORY)) {
|
|
||||||
|
|
||||||
if (prev == ch->hunk->pos.mem) {
|
|
||||||
iov->ngx_iov_len +=
|
|
||||||
ch->hunk->last.mem - ch->hunk->pos.mem;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
ngx_test_null(iov, ngx_push_array(trailer),
|
|
||||||
NGX_CHAIN_ERROR);
|
|
||||||
iov->ngx_iov_base = ch->hunk->pos.mem;
|
|
||||||
iov->ngx_iov_len =
|
|
||||||
ch->hunk->last.mem - ch->hunk->pos.mem;
|
|
||||||
prev = ch->hunk->last.mem;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ch->hunk->type & NGX_HUNK_LAST) {
|
|
||||||
last = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ch = ch->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (file) {
|
|
||||||
flags = ngx_sendfile_flags;
|
|
||||||
#if (HAVE_SENDFILE_DISCONNECT)
|
|
||||||
if (last && c->close) {
|
|
||||||
flags |= NGX_SENDFILE_DISCONNECT;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
rc = ngx_sendfile(c,
|
|
||||||
(ngx_iovec_t *) header->elts, header->nelts,
|
|
||||||
file->file->fd, file->pos.file,
|
|
||||||
(size_t) (file->last.file - file->pos.file),
|
|
||||||
(ngx_iovec_t *) trailer->elts, trailer->nelts,
|
|
||||||
&sent, flags);
|
|
||||||
|
|
||||||
#if (HAVE_AIO_EVENT) && !(HAVE_IOCP_EVENT)
|
|
||||||
} else if (ngx_event_flags & NGX_HAVE_AIO_EVENT) {
|
|
||||||
|
|
||||||
sent = 0;
|
|
||||||
rc = NGX_AGAIN;
|
|
||||||
iov = (ngx_iovec_t *) header->elts;
|
|
||||||
for (i = 0; i < header->nelts; i++) {
|
|
||||||
rc = ngx_event_aio_write(c, iov[i].ngx_iov_base,
|
|
||||||
iov[i].ngx_iov_len);
|
|
||||||
|
|
||||||
if (rc > 0) {
|
|
||||||
sent += rc;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rc < (int) iov->ngx_iov_len) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
} else {
|
|
||||||
rc = ngx_sendv(c, (ngx_iovec_t *) header->elts, header->nelts);
|
|
||||||
|
|
||||||
sent = rc > 0 ? rc: 0;
|
|
||||||
|
|
||||||
#if (NGX_DEBUG_EVENT_WRITE)
|
|
||||||
ngx_log_debug(c->log, "sendv: " OFF_FMT _ sent);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#if (HAVE_MAX_SENDFILE_IOVEC)
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (rc == NGX_ERROR)
|
|
||||||
return (ngx_chain_t *) NGX_ERROR;
|
|
||||||
|
|
||||||
c->sent += sent;
|
|
||||||
flush -= sent;
|
|
||||||
|
|
||||||
for (ch = in; ch; ch = ch->next) {
|
|
||||||
|
|
||||||
#if (NGX_DEBUG_EVENT_WRITE)
|
|
||||||
ngx_log_debug(c->log, "event write: %x " QX_FMT " " OFF_FMT _
|
|
||||||
ch->hunk->type _
|
|
||||||
ch->hunk->pos.file _
|
|
||||||
ch->hunk->last.file - ch->hunk->pos.file);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (sent >= ch->hunk->last.file - ch->hunk->pos.file) {
|
|
||||||
sent -= ch->hunk->last.file - ch->hunk->pos.file;
|
|
||||||
ch->hunk->pos.file = ch->hunk->last.file;
|
|
||||||
|
|
||||||
#if (NGX_DEBUG_EVENT_WRITE)
|
|
||||||
ngx_log_debug(c->log, "event write: " QX_FMT " 0 " OFF_FMT _
|
|
||||||
ch->hunk->pos.file _ sent);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
if (ch->hunk->type & NGX_HUNK_LAST)
|
|
||||||
break;
|
|
||||||
*/
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
ch->hunk->pos.file += sent;
|
|
||||||
|
|
||||||
#if (NGX_DEBUG_EVENT_WRITE)
|
|
||||||
ngx_log_debug(c->log, "event write: " QX_FMT " " OFF_FMT _
|
|
||||||
ch->hunk->pos.file _
|
|
||||||
ch->hunk->last.file - ch->hunk->pos.file);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* flush hunks if threaded state */
|
|
||||||
} while (c->write->context && flush > 0);
|
|
||||||
|
|
||||||
ngx_destroy_array(&trailer);
|
|
||||||
ngx_destroy_array(&header);
|
|
||||||
|
|
||||||
return ch;
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,39 @@
|
|||||||
|
|
||||||
|
#include <ngx_config.h>
|
||||||
|
|
||||||
|
#include <ngx_core.h>
|
||||||
|
#include <ngx_types.h>
|
||||||
|
#include <ngx_log.h>
|
||||||
|
#include <ngx_connection.h>
|
||||||
|
#include <ngx_event.h>
|
||||||
|
#include <ngx_event_timer.h>
|
||||||
|
|
||||||
|
#if (HAVE_KQUEUE)
|
||||||
|
#include <ngx_kqueue_module.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
int ngx_aio_init(int max_connections, ngx_log_t *log)
|
||||||
|
{
|
||||||
|
#if (HAVE_KQUEUE)
|
||||||
|
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
rc = ngx_kqueue_init(max_connections, log);
|
||||||
|
|
||||||
|
ngx_event_flags = NGX_HAVE_AIO_EVENT;
|
||||||
|
ngx_write_chain_proc = ngx_aio_write_chain;
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
/* 1 */
|
/* 1 */
|
||||||
int ngx_posix_aio_process_events(ngx_log_t *log)
|
int ngx_posix_aio_process_events(ngx_log_t *log)
|
||||||
{
|
{
|
||||||
@ -47,4 +82,4 @@ void aio_sig_handler(int signo, siginfo_t *siginfo, void *context)
|
|||||||
{
|
{
|
||||||
push siginfo->si_value.sival_ptr
|
push siginfo->si_value.sival_ptr
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
14
src/event/modules/ngx_aio_module.h
Normal file
14
src/event/modules/ngx_aio_module.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#ifndef _NGX_AIO_MODULE_H_INCLUDED_
|
||||||
|
#define _NGX_AIO_MODULE_H_INCLUDED_
|
||||||
|
|
||||||
|
|
||||||
|
#include <ngx_types.h>
|
||||||
|
#include <ngx_log.h>
|
||||||
|
#include <ngx_event.h>
|
||||||
|
|
||||||
|
|
||||||
|
int ngx_aio_init(int max_connections, ngx_log_t *log);
|
||||||
|
int ngx_aio_process_events(ngx_log_t *log);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* _NGX_AIO_MODULE_H_INCLUDED_ */
|
@ -79,6 +79,8 @@ int ngx_kqueue_init(int max_connections, ngx_log_t *log)
|
|||||||
#endif
|
#endif
|
||||||
|NGX_HAVE_KQUEUE_EVENT;
|
|NGX_HAVE_KQUEUE_EVENT;
|
||||||
|
|
||||||
|
ngx_write_chain_proc = ngx_freebsd_write_chain;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -25,6 +25,10 @@
|
|||||||
#include <ngx_kqueue_module.h>
|
#include <ngx_kqueue_module.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if (HAVE_AIO)
|
||||||
|
#include <ngx_aio_module.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#if (HAVE_IOCP)
|
#if (HAVE_IOCP)
|
||||||
#include <ngx_event_acceptex.h>
|
#include <ngx_event_acceptex.h>
|
||||||
#include <ngx_iocp_module.h>
|
#include <ngx_iocp_module.h>
|
||||||
@ -54,6 +58,9 @@ static int (*ngx_event_init[]) (int max_connections, ngx_log_t *log) = {
|
|||||||
#if (HAVE_KQUEUE)
|
#if (HAVE_KQUEUE)
|
||||||
ngx_kqueue_init,
|
ngx_kqueue_init,
|
||||||
#endif
|
#endif
|
||||||
|
#if (HAVE_AIO)
|
||||||
|
ngx_aio_init,
|
||||||
|
#endif
|
||||||
#if (HAVE_IOCP)
|
#if (HAVE_IOCP)
|
||||||
ngx_iocp_init
|
ngx_iocp_init
|
||||||
#endif
|
#endif
|
||||||
@ -82,6 +89,9 @@ void ngx_pre_thread(ngx_array_t *ls, ngx_pool_t *pool, ngx_log_t *log)
|
|||||||
#if 0
|
#if 0
|
||||||
ngx_event_type = NGX_DEVPOLL_EVENT_N;
|
ngx_event_type = NGX_DEVPOLL_EVENT_N;
|
||||||
#endif
|
#endif
|
||||||
|
#if 0
|
||||||
|
ngx_event_type = NGX_AIO_EVENT_N;
|
||||||
|
#endif
|
||||||
#if 0
|
#if 0
|
||||||
ngx_event_type = NGX_IOCP_EVENT_N;
|
ngx_event_type = NGX_IOCP_EVENT_N;
|
||||||
#endif
|
#endif
|
||||||
|
@ -116,6 +116,9 @@ typedef enum {
|
|||||||
#if (HAVE_KQUEUE)
|
#if (HAVE_KQUEUE)
|
||||||
NGX_KQUEUE_EVENT_N,
|
NGX_KQUEUE_EVENT_N,
|
||||||
#endif
|
#endif
|
||||||
|
#if (HAVE_AIO)
|
||||||
|
NGX_AIO_EVENT_N,
|
||||||
|
#endif
|
||||||
#if (HAVE_IOCP)
|
#if (HAVE_IOCP)
|
||||||
NGX_IOCP_EVENT_N,
|
NGX_IOCP_EVENT_N,
|
||||||
#endif
|
#endif
|
||||||
|
@ -156,6 +156,9 @@ int ngx_event_accept(ngx_event_t *ev)
|
|||||||
|
|
||||||
#elif (HAVE_KQUEUE)
|
#elif (HAVE_KQUEUE)
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (ngx_event_type == NGX_HAVE_AIO_EVENT or NGX_HAVE_KQUEUE_EVENT) {
|
||||||
|
*/
|
||||||
if (ngx_event_type == NGX_HAVE_KQUEUE_EVENT) {
|
if (ngx_event_type == NGX_HAVE_KQUEUE_EVENT) {
|
||||||
ev->available--;
|
ev->available--;
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <ngx_log.h>
|
#include <ngx_log.h>
|
||||||
#include <ngx_recv.h>
|
#include <ngx_recv.h>
|
||||||
#include <ngx_connection.h>
|
#include <ngx_connection.h>
|
||||||
|
#include <ngx_event.h>
|
||||||
|
|
||||||
#if (HAVE_KQUEUE)
|
#if (HAVE_KQUEUE)
|
||||||
#include <ngx_kqueue_module.h>
|
#include <ngx_kqueue_module.h>
|
||||||
|
@ -141,7 +141,7 @@ int ngx_http_static_handler(ngx_http_request_t *r)
|
|||||||
if (r->header_only)
|
if (r->header_only)
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
#if 0
|
#if 1
|
||||||
|
|
||||||
h->type = NGX_HUNK_FILE|NGX_HUNK_LAST;
|
h->type = NGX_HUNK_FILE|NGX_HUNK_LAST;
|
||||||
h->pos.file = 0;
|
h->pos.file = 0;
|
||||||
|
@ -95,7 +95,8 @@ static int ngx_http_header_filter(ngx_http_request_t *r)
|
|||||||
ngx_log_debug(r->connection->log, "%d %d" _
|
ngx_log_debug(r->connection->log, "%d %d" _
|
||||||
ims _ r->headers_out.last_modified_time);
|
ims _ r->headers_out.last_modified_time);
|
||||||
|
|
||||||
if (ims != NGX_ERROR && ims >= r->headers_out.last_modified_time) {
|
/* I think that the date equality is correcter */
|
||||||
|
if (ims != NGX_ERROR && ims == r->headers_out.last_modified_time) {
|
||||||
r->headers_out.status = NGX_HTTP_NOT_MODIFIED;
|
r->headers_out.status = NGX_HTTP_NOT_MODIFIED;
|
||||||
r->headers_out.content_length = -1;
|
r->headers_out.content_length = -1;
|
||||||
r->headers_out.content_type->key.len = 0;
|
r->headers_out.content_type->key.len = 0;
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <ngx_core.h>
|
#include <ngx_core.h>
|
||||||
#include <ngx_hunk.h>
|
#include <ngx_hunk.h>
|
||||||
#include <ngx_conf_file.h>
|
#include <ngx_conf_file.h>
|
||||||
|
#include <ngx_connection.h>
|
||||||
|
|
||||||
#include <ngx_event_write.h>
|
#include <ngx_event_write.h>
|
||||||
|
|
||||||
@ -81,7 +82,7 @@ int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
|||||||
le = &ce->next;
|
le = &ce->next;
|
||||||
size += ce->hunk->last.file - ce->hunk->pos.file;
|
size += ce->hunk->last.file - ce->hunk->pos.file;
|
||||||
|
|
||||||
#if (NGX_DEBUG_WRITE_FILTER0)
|
#if (NGX_DEBUG_WRITE_FILTER)
|
||||||
ngx_log_debug(r->connection->log, "write filter: old chunk: %x "
|
ngx_log_debug(r->connection->log, "write filter: old chunk: %x "
|
||||||
QX_FMT " " QD_FMT _
|
QX_FMT " " QD_FMT _
|
||||||
ce->hunk->type _ ce->hunk->pos.file _
|
ce->hunk->type _ ce->hunk->pos.file _
|
||||||
@ -107,7 +108,7 @@ int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
|||||||
le = &ce->next;
|
le = &ce->next;
|
||||||
size += ce->hunk->last.file - ce->hunk->pos.file;
|
size += ce->hunk->last.file - ce->hunk->pos.file;
|
||||||
|
|
||||||
#if (NGX_DEBUG_WRITE_FILTER0)
|
#if (NGX_DEBUG_WRITE_FILTER)
|
||||||
ngx_log_debug(r->connection->log, "write filter: new hunk: %x "
|
ngx_log_debug(r->connection->log, "write filter: new hunk: %x "
|
||||||
QX_FMT " " QD_FMT _
|
QX_FMT " " QD_FMT _
|
||||||
ce->hunk->type _ ce->hunk->pos.file _
|
ce->hunk->type _ ce->hunk->pos.file _
|
||||||
@ -127,7 +128,7 @@ int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
|||||||
ngx_http_get_module_loc_conf(r->main ? r->main : r,
|
ngx_http_get_module_loc_conf(r->main ? r->main : r,
|
||||||
ngx_http_write_filter_module);
|
ngx_http_write_filter_module);
|
||||||
|
|
||||||
#if (NGX_DEBUG_WRITE_FILTER0)
|
#if (NGX_DEBUG_WRITE_FILTER)
|
||||||
ngx_log_debug(r->connection->log, "write filter: last:%d flush:%d" _
|
ngx_log_debug(r->connection->log, "write filter: last:%d flush:%d" _
|
||||||
last _ flush);
|
last _ flush);
|
||||||
#endif
|
#endif
|
||||||
@ -138,7 +139,7 @@ int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
|
|||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
chain = ngx_event_write(r->connection, ctx->out, flush);
|
chain = ngx_write_chain(r->connection, ctx->out, flush);
|
||||||
|
|
||||||
#if (NGX_DEBUG_WRITE_FILTER)
|
#if (NGX_DEBUG_WRITE_FILTER)
|
||||||
ngx_log_debug(r->connection->log, "write filter %x" _ chain);
|
ngx_log_debug(r->connection->log, "write filter %x" _ chain);
|
||||||
|
92
src/os/unix/ngx_aio_write_chain.c
Normal file
92
src/os/unix/ngx_aio_write_chain.c
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
|
||||||
|
#include <ngx_config.h>
|
||||||
|
|
||||||
|
#include <ngx_core.h>
|
||||||
|
#include <ngx_types.h>
|
||||||
|
#include <ngx_alloc.h>
|
||||||
|
#include <ngx_array.h>
|
||||||
|
#include <ngx_hunk.h>
|
||||||
|
#include <ngx_connection.h>
|
||||||
|
#include <ngx_sendv.h>
|
||||||
|
#include <ngx_sendfile.h>
|
||||||
|
|
||||||
|
|
||||||
|
ngx_chain_t *ngx_aio_write_chain(ngx_connection_t *c, ngx_chain_t *in)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
char *buf, *prev;
|
||||||
|
off_t sent;
|
||||||
|
size_t size;
|
||||||
|
ngx_err_t err;
|
||||||
|
ngx_chain_t *ce;
|
||||||
|
|
||||||
|
sent = 0;
|
||||||
|
ce = in;
|
||||||
|
|
||||||
|
while (ce) {
|
||||||
|
|
||||||
|
ngx_log_debug(c->log, "aio_write ce: %x" _ ce->hunk->pos.mem);
|
||||||
|
|
||||||
|
buf = prev = ce->hunk->pos.mem;
|
||||||
|
size = 0;
|
||||||
|
|
||||||
|
/* coalesce the neighbouring chain entries */
|
||||||
|
while (ce && prev == ce->hunk->pos.mem) {
|
||||||
|
size += ce->hunk->last.mem - ce->hunk->pos.mem;
|
||||||
|
prev = ce->hunk->last.mem;
|
||||||
|
ce = ce->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
rc = ngx_event_aio_write(c, buf, size);
|
||||||
|
|
||||||
|
ngx_log_debug(c->log, "aio_write rc: %d" _ rc);
|
||||||
|
|
||||||
|
if (rc > 0) {
|
||||||
|
sent += rc;
|
||||||
|
c->sent += rc;
|
||||||
|
|
||||||
|
} else if (rc == NGX_ERROR) {
|
||||||
|
return NGX_CHAIN_ERROR;
|
||||||
|
|
||||||
|
} else if (rc == NGX_AGAIN) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if (NGX_DEBUG_WRITE_CHAIN)
|
||||||
|
ngx_log_debug(c->log, "aio_write sent: " OFF_FMT _ c->sent);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (ce = in; ce; ce = ce->next) {
|
||||||
|
|
||||||
|
#if (NGX_DEBUG_WRITE_CHAIN)
|
||||||
|
ngx_log_debug(c->log, "write chain: %x %qx %qd" _
|
||||||
|
ce->hunk->type _
|
||||||
|
ce->hunk->pos.file _
|
||||||
|
ce->hunk->last.file - ce->hunk->pos.file);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (sent >= ce->hunk->last.file - ce->hunk->pos.file) {
|
||||||
|
sent -= ce->hunk->last.file - ce->hunk->pos.file;
|
||||||
|
ce->hunk->pos.file = ce->hunk->last.file;
|
||||||
|
|
||||||
|
#if (NGX_DEBUG_WRITE_CHAIN)
|
||||||
|
ngx_log_debug(c->log, "write chain done: %qx %qd" _
|
||||||
|
ce->hunk->pos.file _ sent);
|
||||||
|
#endif
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ce->hunk->pos.file += sent;
|
||||||
|
|
||||||
|
#if (NGX_DEBUG_WRITE_CHAIN)
|
||||||
|
ngx_log_debug(c->log, "write chain rest: %qx %qd" _
|
||||||
|
ce->hunk->pos.file _
|
||||||
|
ce->hunk->last.file - ce->hunk->pos.file);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ce;
|
||||||
|
}
|
178
src/os/unix/ngx_freebsd_write_chain.c
Normal file
178
src/os/unix/ngx_freebsd_write_chain.c
Normal file
@ -0,0 +1,178 @@
|
|||||||
|
|
||||||
|
#include <ngx_config.h>
|
||||||
|
|
||||||
|
#include <ngx_core.h>
|
||||||
|
#include <ngx_types.h>
|
||||||
|
#include <ngx_alloc.h>
|
||||||
|
#include <ngx_array.h>
|
||||||
|
#include <ngx_hunk.h>
|
||||||
|
#include <ngx_connection.h>
|
||||||
|
#include <ngx_sendv.h>
|
||||||
|
#include <ngx_sendfile.h>
|
||||||
|
|
||||||
|
|
||||||
|
ngx_chain_t *ngx_freebsd_write_chain(ngx_connection_t *c, ngx_chain_t *in)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
char *prev;
|
||||||
|
size_t hsize;
|
||||||
|
off_t sent;
|
||||||
|
struct iovec *iov;
|
||||||
|
struct sf_hdtr hdtr;
|
||||||
|
ngx_err_t err;
|
||||||
|
ngx_array_t header, trailer;
|
||||||
|
ngx_hunk_t *file;
|
||||||
|
ngx_chain_t *ce;
|
||||||
|
|
||||||
|
ce = in;
|
||||||
|
file = NULL;
|
||||||
|
hsize = 0;
|
||||||
|
|
||||||
|
ngx_init_array(header, c->pool, 10, sizeof(struct iovec), NGX_CHAIN_ERROR);
|
||||||
|
ngx_init_array(trailer, c->pool, 10, sizeof(struct iovec), NGX_CHAIN_ERROR);
|
||||||
|
|
||||||
|
/* create the header iovec */
|
||||||
|
if (ce->hunk->type & NGX_HUNK_IN_MEMORY) {
|
||||||
|
prev = NULL;
|
||||||
|
iov = NULL;
|
||||||
|
|
||||||
|
/* create the iovec and coalesce the neighbouring chain entries */
|
||||||
|
while (ce && (ce->hunk->type & NGX_HUNK_IN_MEMORY))
|
||||||
|
{
|
||||||
|
if (prev == ce->hunk->pos.mem) {
|
||||||
|
iov->iov_len += ce->hunk->last.mem - ce->hunk->pos.mem;
|
||||||
|
prev = ce->hunk->last.mem;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
ngx_test_null(iov, ngx_push_array(&header), NGX_CHAIN_ERROR);
|
||||||
|
iov->iov_base = ce->hunk->pos.mem;
|
||||||
|
iov->iov_len = ce->hunk->last.mem - ce->hunk->pos.mem;
|
||||||
|
prev = ce->hunk->last.mem;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if (HAVE_FREEBSD_SENDFILE_NBYTES_BUG)
|
||||||
|
hsize += ce->hunk->last.mem - ce->hunk->pos.mem;
|
||||||
|
#endif
|
||||||
|
ce = ce->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TODO: coalesce the neighbouring shadow file hunks */
|
||||||
|
if (ce && (ce->hunk->type & NGX_HUNK_FILE)) {
|
||||||
|
file = ce->hunk;
|
||||||
|
ce = ce->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* create the trailer iovec */
|
||||||
|
if (ce && ce->hunk->type & NGX_HUNK_IN_MEMORY) {
|
||||||
|
prev = NULL;
|
||||||
|
iov = NULL;
|
||||||
|
|
||||||
|
/* create the iovec and coalesce the neighbouring chain entries */
|
||||||
|
while (ce && (ce->hunk->type & NGX_HUNK_IN_MEMORY)) {
|
||||||
|
|
||||||
|
if (prev == ce->hunk->pos.mem) {
|
||||||
|
iov->iov_len += ce->hunk->last.mem - ce->hunk->pos.mem;
|
||||||
|
prev = ce->hunk->last.mem;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
ngx_test_null(iov, ngx_push_array(&trailer), NGX_CHAIN_ERROR);
|
||||||
|
iov->iov_base = ce->hunk->pos.mem;
|
||||||
|
iov->iov_len = ce->hunk->last.mem - ce->hunk->pos.mem;
|
||||||
|
prev = ce->hunk->last.mem;
|
||||||
|
}
|
||||||
|
|
||||||
|
ce = ce->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file) {
|
||||||
|
hdtr.headers = (struct iovec *) header.elts;
|
||||||
|
hdtr.hdr_cnt = header.nelts;
|
||||||
|
hdtr.trailers = (struct iovec *) trailer.elts;
|
||||||
|
hdtr.trl_cnt = trailer.nelts;
|
||||||
|
|
||||||
|
rc = sendfile(file->file->fd, c->fd, file->pos.file,
|
||||||
|
(size_t) (file->last.file - file->pos.file) + hsize,
|
||||||
|
&hdtr, &sent, 0);
|
||||||
|
|
||||||
|
if (rc == -1) {
|
||||||
|
err = ngx_errno;
|
||||||
|
if (err == NGX_EAGAIN || err == NGX_EINTR) {
|
||||||
|
ngx_log_error(NGX_LOG_INFO, c->log, err,
|
||||||
|
"sendfile() sent only %qd bytes", sent);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
ngx_log_error(NGX_LOG_CRIT, c->log, err, "sendfile() failed");
|
||||||
|
return NGX_CHAIN_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if (NGX_DEBUG_WRITE_CHAIN)
|
||||||
|
ngx_log_debug(c->log, "sendfile: %d, @%qd %qd:%d" _
|
||||||
|
rc _ file->pos.file _ *sent _
|
||||||
|
(size_t) (file->last.file - file->pos.file) + hsize);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} else {
|
||||||
|
rc = writev(c->fd, (struct iovec *) header.elts, header.nelts);
|
||||||
|
|
||||||
|
if (rc == -1) {
|
||||||
|
err = ngx_errno;
|
||||||
|
if (err == NGX_EAGAIN) {
|
||||||
|
ngx_log_error(NGX_LOG_INFO, c->log, err, "writev() EAGAIN");
|
||||||
|
|
||||||
|
} else if (err == NGX_EINTR) {
|
||||||
|
ngx_log_error(NGX_LOG_INFO, c->log, err, "writev() EINTR");
|
||||||
|
|
||||||
|
} else {
|
||||||
|
ngx_log_error(NGX_LOG_CRIT, c->log, err, "writev() failed");
|
||||||
|
return NGX_CHAIN_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sent = rc > 0 ? rc : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if (NGX_DEBUG_WRITE_CHAIN)
|
||||||
|
ngx_log_debug(c->log, "sendv: %qd" _ sent);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
c->sent += sent;
|
||||||
|
|
||||||
|
for (ce = in; ce; ce = ce->next) {
|
||||||
|
|
||||||
|
#if (NGX_DEBUG_WRITE_CHAIN)
|
||||||
|
ngx_log_debug(c->log, "write chain: %x %qx %qd" _
|
||||||
|
ce->hunk->type _
|
||||||
|
ce->hunk->pos.file _
|
||||||
|
ce->hunk->last.file - ce->hunk->pos.file);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (sent >= ce->hunk->last.file - ce->hunk->pos.file) {
|
||||||
|
sent -= ce->hunk->last.file - ce->hunk->pos.file;
|
||||||
|
ce->hunk->pos.file = ce->hunk->last.file;
|
||||||
|
|
||||||
|
#if (NGX_DEBUG_WRITE_CHAIN)
|
||||||
|
ngx_log_debug(c->log, "write chain done: %qx %qd" _
|
||||||
|
ce->hunk->pos.file _ sent);
|
||||||
|
#endif
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ce->hunk->pos.file += sent;
|
||||||
|
|
||||||
|
#if (NGX_DEBUG_WRITE_CHAIN)
|
||||||
|
ngx_log_debug(c->log, "write chain rest: %qx %qd" _
|
||||||
|
ce->hunk->pos.file _
|
||||||
|
ce->hunk->last.file - ce->hunk->pos.file);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ngx_destroy_array(&trailer);
|
||||||
|
ngx_destroy_array(&header);
|
||||||
|
|
||||||
|
return ce;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user