nginx-0.0.1-2003-05-22-19:23:47 import

This commit is contained in:
Igor Sysoev 2003-05-22 15:23:47 +00:00
parent fa73aac774
commit 6a1cc903bf
13 changed files with 155 additions and 64 deletions

View File

@ -50,6 +50,10 @@
#endif
#ifndef INFTIM /* Linux */
#define INFTIM -1
#endif
#ifndef INADDR_NONE /* Solaris */
#define INADDR_NONE ((unsigned long) -1)
#endif

View File

@ -114,7 +114,7 @@ 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_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

View File

@ -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 *ev, int event, u_int flags)
}
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);

View File

@ -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

View File

@ -319,7 +319,7 @@ ngx_log_debug(r->connection->log, "trans: %s" _ lcfp[i]->name.data);
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;
}

View File

@ -33,6 +33,7 @@ static void ngx_http_set_keepalive(ngx_http_request_t *r);
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_http_request_t *r)
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_http_request_t *r)
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(ngx_http_request_t *r)
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_handler(ngx_event_t *rev)
}
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_connection_t *c)
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) {

View File

@ -58,15 +58,6 @@ ngx_module_t ngx_http_output_filter_module = {
#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_request_t *r, ngx_hunk_t *hunk)
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_request_t *r, ngx_hunk_t *hunk)
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_request_t *r, ngx_hunk_t *hunk)
/* 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_hunk(ngx_hunk_t *dst, ngx_hunk_t *src)
} 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;
}

View File

@ -6,22 +6,16 @@
#include <stddef.h> /* offsetof */
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <fcntl.h>
#include <signal.h>
#include <string.h>
#include <time.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/uio.h>
#include <sys/ioctl.h>
#include <sys/resource.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <osreldate.h>

View File

@ -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

View File

@ -12,7 +12,7 @@
#include <ngx_freebsd_init.h>
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;

View File

@ -2,24 +2,34 @@
#define _NGX_LINUX_CONFIG_H_INCLUDED_
#define _XOPEN_SOURCE 500
#include <unistd.h>
#include <stddef.h> /* offsetof */
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <fcntl.h>
#include <signal.h>
#include <string.h>
#include <time.h>
#define __USE_BSD
#include <string.h>
#undef __USE_BSD
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/select.h>
#include <sys/uio.h>
#include <sys/ioctl.h>
#include <sys/resource.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
typedef unsigned int u_int;
typedef unsigned char u_char;
#ifndef HAVE_SELECT

View File

@ -4,29 +4,24 @@
#define SOLARIS 1
#define _REENTRANT
#define _FILE_OFFSET_BITS 64 /* must be before sys/types.h */
#include <unistd.h>
#include <stddef.h> /* offsetof */
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <fcntl.h>
#include <time.h>
#include <signal.h>
#include <string.h>
#include <strings.h> /* bzero() */
#include <strings.h>
#include <sys/types.h>
#include <sys/filio.h> /* FIONBIO */
#include <sys/stropts.h> /* INFTIM */
#include <sys/mman.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <sys/uio.h>
#include <sys/resource.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
typedef uint32_t u_int32_t;

View File

@ -62,6 +62,8 @@ ngx_chain_t *ngx_writev_chain(ngx_connection_t *c, ngx_chain_t *in)
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_connection_t *c, ngx_chain_t *in)
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_connection_t *c, ngx_chain_t *in)
ce->hunk->pos += sent;
}
#if 0
if (ce->hunk->type & NGX_HUNK_FILE) {
ce->hunk->file_pos += sent;
}
#endif
break;
}