# HG changeset patch # User Igor Sysoev # Date 1053617027 0 # Node ID 8220378432a8e5352a43cc0039fbae3924ab2406 # Parent 738fe44c70d51e242c35fb16a59a120309aa247b nginx-0.0.1-2003-05-22-19:23:47 import diff --git a/src/core/ngx_config.h b/src/core/ngx_config.h --- a/src/core/ngx_config.h +++ b/src/core/ngx_config.h @@ -50,6 +50,10 @@ #endif +#ifndef INFTIM /* Linux */ +#define INFTIM -1 +#endif + #ifndef INADDR_NONE /* Solaris */ #define INADDR_NONE ((unsigned long) -1) #endif diff --git a/src/core/ngx_connection.h b/src/core/ngx_connection.h --- a/src/core/ngx_connection.h +++ b/src/core/ngx_connection.h @@ -114,7 +114,7 @@ ngx_chain_t *ngx_write_chain(ngx_connect /* 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_freebsd_sendfile_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 diff --git a/src/event/modules/ngx_aio_module.c b/src/event/modules/ngx_aio_module.c --- a/src/event/modules/ngx_aio_module.c +++ b/src/event/modules/ngx_aio_module.c @@ -13,6 +13,7 @@ static int ngx_aio_init(ngx_log_t *log); static void ngx_aio_done(ngx_log_t *log); static int ngx_aio_add_event(ngx_event_t *ev, int event, u_int flags); static int ngx_aio_del_event(ngx_event_t *ev, int event, u_int flags); +static int ngx_aio_del_connection(ngx_connection_t *c); static int ngx_aio_process_events(ngx_log_t *log); @@ -39,7 +40,7 @@ ngx_event_module_t ngx_aio_module_ctx = NULL, /* enable an event */ NULL, /* disable an event */ NULL, /* add an connection */ - NULL, /* delete an connection */ + ngx_aio_del_connection, /* delete an connection */ ngx_aio_process_events, /* process the events */ ngx_aio_init, /* init the events */ ngx_aio_done /* done the events */ @@ -94,6 +95,58 @@ static int ngx_aio_del_event(ngx_event_t } +static int ngx_aio_del_connection(ngx_connection_t *c) +{ + int rc; + + if (c->read->active || c->write->active) { + rc = aio_cancel(c->fd, NULL); + if (rc == -1) { + ngx_log_error(NGX_LOG_CRIT, c->log, ngx_errno, + "aio_cancel() failed"); + return NGX_ERROR; + } + + ngx_log_debug(c->log, "aio_cancel: %d" _ rc); + +#if 0 + rc = aio_error(&c->read->aiocb); + if (rc == -1) { + ngx_log_error(NGX_LOG_CRIT, c->log, ngx_errno, + "aio_error() failed"); + return NGX_ERROR; + } + + ngx_log_debug(c->log, "aio_error: %d" _ rc); +#endif + } + +#if 0 + if (c->write->active) { + rc = aio_cancel(c->fd, &c->write->aiocb); + if (rc == -1) { + ngx_log_error(NGX_LOG_CRIT, c->log, ngx_errno, + "aio_cancel() failed"); + return NGX_ERROR; + } + + ngx_log_debug(c->log, "aio_cancel: %d" _ rc); + + rc = aio_error(&c->read->aiocb); + if (rc == -1) { + ngx_log_error(NGX_LOG_CRIT, c->log, ngx_errno, + "aio_error() failed"); + return NGX_ERROR; + } + + ngx_log_debug(c->log, "aio_error: %d" _ rc); + } +#endif + + return NGX_OK; +} + + static int ngx_aio_process_events(ngx_log_t *log) { return ngx_kqueue_module_ctx.actions.process(log); diff --git a/src/event/ngx_event.h b/src/event/ngx_event.h --- a/src/event/ngx_event.h +++ b/src/event/ngx_event.h @@ -280,6 +280,7 @@ typedef struct { #define ngx_process_events ngx_event_actions.process #define ngx_add_event ngx_event_actions.add #define ngx_del_event ngx_event_actions.del +#define ngx_del_conn ngx_event_actions.del_conn #if 0 #define ngx_add_timer ngx_event_actions.timer diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -319,7 +319,7 @@ ngx_log_debug(r->connection->log, "trans lcf = (ngx_http_core_loc_conf_t *) ngx_http_get_module_loc_conf(r, ngx_http_core_module_ctx); - if (lcf->sendfile == 0) { + if ((ngx_io.flags & NGX_IO_SENDFILE) == 0 || lcf->sendfile == 0) { r->filter = NGX_HTTP_FILTER_NEED_IN_MEMORY; } diff --git a/src/http/ngx_http_event.c b/src/http/ngx_http_event.c --- a/src/http/ngx_http_event.c +++ b/src/http/ngx_http_event.c @@ -33,6 +33,7 @@ static void ngx_http_set_keepalive(ngx_h static void ngx_http_keepalive_handler(ngx_event_t *ev); static void ngx_http_set_lingering_close(ngx_http_request_t *r); static void ngx_http_lingering_close_handler(ngx_event_t *ev); +static void ngx_http_empty_handler(ngx_event_t *wev); static void ngx_http_header_parse_error(ngx_http_request_t *r, int parse_err); static size_t ngx_http_log_error(void *data, char *buf, size_t len); @@ -1001,6 +1002,8 @@ static void ngx_http_set_keepalive(ngx_h c = (ngx_connection_t *) r->connection; rev = c->read; + ngx_log_debug(c->log, "set http keepalive handler"); + ctx = (ngx_http_log_ctx_t *) c->log->data; ctx->action = "closing request"; ngx_http_close_request(r, 0); @@ -1061,10 +1064,15 @@ static void ngx_http_set_keepalive(ngx_h rev->event_handler = ngx_http_keepalive_handler; wev = c->write; - if (wev->active && (ngx_event_flags & NGX_USE_LEVEL_EVENT)) { - if (ngx_del_event(wev, NGX_WRITE_EVENT, 0) == NGX_ERROR) { - ngx_http_close_connection(c); - return; + if (wev->active) { + if (ngx_event_flags & NGX_USE_LEVEL_EVENT) { + if (ngx_del_event(wev, NGX_WRITE_EVENT, 0) == NGX_ERROR) { + ngx_http_close_connection(c); + return; + } + + } else if ((ngx_event_flags & NGX_HAVE_AIO_EVENT) == 0) { + wev->event_handler = ngx_http_empty_handler; } } @@ -1158,11 +1166,16 @@ static void ngx_http_set_lingering_close rev->blocked = 0; } - if (c->write->active && (ngx_event_flags & NGX_USE_LEVEL_EVENT)) { - if (ngx_del_event(c->write, NGX_WRITE_EVENT, 0) == NGX_ERROR) { - ngx_http_close_request(r, 0); - ngx_http_close_connection(c); - return; + if (c->write->active) { + if (ngx_event_flags & NGX_USE_LEVEL_EVENT) { + if (ngx_del_event(c->write, NGX_WRITE_EVENT, 0) == NGX_ERROR) { + ngx_http_close_request(r, 0); + ngx_http_close_connection(c); + return; + } + + } else if ((ngx_event_flags & NGX_HAVE_AIO_EVENT) == 0) { + c->write->event_handler = ngx_http_empty_handler; } } @@ -1259,6 +1272,14 @@ static void ngx_http_lingering_close_han } +static void ngx_http_empty_handler(ngx_event_t *wev) +{ + ngx_log_debug(wev->log, "http empty handler"); + + return; +} + + void ngx_http_close_request(ngx_http_request_t *r, int error) { ngx_http_log_ctx_t *ctx; @@ -1306,17 +1327,22 @@ void ngx_http_close_connection(ngx_conne c->read->timer_set = 0; } - if (c->read->active) { - ngx_del_event(c->read, NGX_READ_EVENT, NGX_CLOSE_EVENT); - } - if (c->write->timer_set) { ngx_del_timer(c->write); c->write->timer_set = 0; } - if (c->write->active) { - ngx_del_event(c->write, NGX_WRITE_EVENT, NGX_CLOSE_EVENT); + if (1) { + ngx_del_conn(c); + + } else { + if (c->read->active) { + ngx_del_event(c->read, NGX_READ_EVENT, NGX_CLOSE_EVENT); + } + + if (c->write->active) { + ngx_del_event(c->write, NGX_WRITE_EVENT, NGX_CLOSE_EVENT); + } } if (ngx_close_socket(c->fd) == -1) { diff --git a/src/http/ngx_http_output_filter.c b/src/http/ngx_http_output_filter.c --- a/src/http/ngx_http_output_filter.c +++ b/src/http/ngx_http_output_filter.c @@ -58,15 +58,6 @@ ngx_module_t ngx_http_output_filter_mod #define next_filter (*ngx_http_top_body_filter) -#if 0 -static int (*next_filter) (ngx_http_request_t *r, ngx_chain_t *ch); -#endif - - -#if 0 -#define next_filter ngx_http_output_filter_module_ctx.next_output_body_filter -#endif - #define need_to_copy(r, hunk) \ (((r->filter & NGX_HTTP_FILTER_NEED_IN_MEMORY) \ && (hunk->type & NGX_HUNK_IN_MEMORY) == 0) \ @@ -159,6 +150,8 @@ int ngx_http_output_filter(ngx_http_requ return rc; } +ngx_log_debug(r->connection->log, "HERE"); + /* NGX_OK */ /* set our hunk free */ ctx->hunk->pos = ctx->hunk->last = ctx->hunk->start; @@ -211,6 +204,20 @@ int ngx_http_output_filter(ngx_http_requ return rc; } #endif + + if (ctx->incoming->hunk->type & NGX_HUNK_IN_MEMORY) { + size = ctx->incoming->hunk->last - ctx->incoming->hunk->pos; + + } else { + size = ctx->incoming->hunk->file_last + - ctx->incoming->hunk->file_pos; + } + + /* delete the completed hunk from the incoming chain */ + if (size == 0) { + ctx->incoming = ctx->incoming->next; + } + ctx->out.hunk = ctx->hunk; ctx->out.next = NULL; @@ -226,19 +233,8 @@ int ngx_http_output_filter(ngx_http_requ /* repeat until we will have copied the whole first hunk from the chain ctx->incoming */ - if (ctx->incoming->hunk->type & NGX_HUNK_IN_MEMORY) { - size = ctx->incoming->hunk->last - ctx->incoming->hunk->pos; - - } else { - size = ctx->incoming->hunk->file_last - - ctx->incoming->hunk->file_pos; - } - } while (size); - /* delete the completed hunk from the incoming chain */ - ctx->incoming = ctx->incoming->next; - /* repeat until we will have processed the whole chain ctx->incoming */ } while (ctx->incoming); @@ -276,6 +272,12 @@ static int ngx_http_output_filter_copy_h } else { n = ngx_read_file(src->file, dst->pos, size, src->file_pos); +if (n == 0) { +ngx_log_debug(src->file->log, "READ: %qd:%qd %X:%X %X:%X" _ + src->file_pos _ src->file_last _ + dst->pos _ dst->last _ dst->start _ dst->end); +} + if (n == NGX_ERROR) { return n; } diff --git a/src/os/unix/ngx_freebsd_config.h b/src/os/unix/ngx_freebsd_config.h --- a/src/os/unix/ngx_freebsd_config.h +++ b/src/os/unix/ngx_freebsd_config.h @@ -6,22 +6,16 @@ #include /* offsetof */ #include #include -#include #include #include -#include -#include #include -#include -#include -#include +#include #include #include #include +#include #include #include -#include - #include diff --git a/src/os/unix/ngx_freebsd_init.c b/src/os/unix/ngx_freebsd_init.c --- a/src/os/unix/ngx_freebsd_init.c +++ b/src/os/unix/ngx_freebsd_init.c @@ -14,7 +14,7 @@ ngx_os_io_t ngx_os_io = { ngx_unix_recv, ngx_readv_chain, NULL, - ngx_freebsd_write_chain, + ngx_freebsd_sendfile_chain, NGX_HAVE_SENDFILE|NGX_HAVE_ZEROCOPY }; @@ -56,7 +56,7 @@ int ngx_os_init(ngx_log_t *log) ngx_freebsd_kern_osreldate, __FreeBSD_version); -#if HAVE_FREEBSD_SENDFILE +#if (HAVE_FREEBSD_SENDFILE) /* The determination of the sendfile() nbytes bug is complex enough. There're two sendfile() syscalls: a new 393 has no bug while diff --git a/src/os/unix/ngx_freebsd_write_chain.c b/src/os/unix/ngx_freebsd_sendfile_chain.c rename from src/os/unix/ngx_freebsd_write_chain.c rename to src/os/unix/ngx_freebsd_sendfile_chain.c --- a/src/os/unix/ngx_freebsd_write_chain.c +++ b/src/os/unix/ngx_freebsd_sendfile_chain.c @@ -12,7 +12,7 @@ #include -ngx_chain_t *ngx_freebsd_write_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; char *prev; diff --git a/src/os/unix/ngx_linux_config.h b/src/os/unix/ngx_linux_config.h --- a/src/os/unix/ngx_linux_config.h +++ b/src/os/unix/ngx_linux_config.h @@ -2,24 +2,34 @@ #define _NGX_LINUX_CONFIG_H_INCLUDED_ +#define _XOPEN_SOURCE 500 + + #include #include /* offsetof */ #include #include -#include #include #include +#include + +#define __USE_BSD #include -#include +#undef __USE_BSD + #include -#include -#include +#include +#include +#include +#include +#include #include -#include -#include #include #include -#include + + +typedef unsigned int u_int; +typedef unsigned char u_char; #ifndef HAVE_SELECT diff --git a/src/os/unix/ngx_solaris_config.h b/src/os/unix/ngx_solaris_config.h --- a/src/os/unix/ngx_solaris_config.h +++ b/src/os/unix/ngx_solaris_config.h @@ -4,29 +4,24 @@ #define SOLARIS 1 +#define _REENTRANT #define _FILE_OFFSET_BITS 64 /* must be before sys/types.h */ + #include #include /* offsetof */ #include #include -#include #include -#include #include -#include -#include /* bzero() */ +#include + #include #include /* FIONBIO */ #include /* INFTIM */ -#include -#include #include -#include -#include #include #include -#include typedef uint32_t u_int32_t; diff --git a/src/os/unix/ngx_writev_chain.c b/src/os/unix/ngx_writev_chain.c --- a/src/os/unix/ngx_writev_chain.c +++ b/src/os/unix/ngx_writev_chain.c @@ -62,6 +62,8 @@ ngx_chain_t *ngx_writev_chain(ngx_connec size = ce->hunk->last - ce->hunk->pos; +ngx_log_debug(c->log, "SIZE: %d" _ size); + if (sent >= size) { sent -= size; @@ -69,9 +71,11 @@ ngx_chain_t *ngx_writev_chain(ngx_connec ce->hunk->pos = ce->hunk->last; } +#if 0 if (ce->hunk->type & NGX_HUNK_FILE) { ce->hunk->file_pos = ce->hunk->file_last; } +#endif continue; } @@ -80,9 +84,11 @@ ngx_chain_t *ngx_writev_chain(ngx_connec ce->hunk->pos += sent; } +#if 0 if (ce->hunk->type & NGX_HUNK_FILE) { ce->hunk->file_pos += sent; } +#endif break; }