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
index b724129..b9a0988 100644
--- 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
index a8b8804..0210842 100644
--- a/src/core/ngx_connection.h
+++ b/src/core/ngx_connection.h
@@ -114,7 +114,7 @@
/* 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
index 24d049f..a5375e9 100644
--- a/src/event/modules/ngx_aio_module.c
+++ b/src/event/modules/ngx_aio_module.c
@@ -13,6 +13,7 @@
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 @@
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_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
index c3f925f..1df1ad3 100644
--- a/src/event/ngx_event.h
+++ b/src/event/ngx_event.h
@@ -280,6 +280,7 @@
#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
index 3ca006d..e9bda7a 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -319,7 +319,7 @@
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
index 83f0f68..f3f332a 100644
--- a/src/http/ngx_http_event.c
+++ b/src/http/ngx_http_event.c
@@ -33,6 +33,7 @@
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 @@
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 @@
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 @@
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_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 @@
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
index 53c32e1..53699ff 100644
--- a/src/http/ngx_http_output_filter.c
+++ b/src/http/ngx_http_output_filter.c
@@ -58,15 +58,6 @@
#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 @@
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 @@
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 @@
/* 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 @@
} 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
index f8066e5..73646fa 100644
--- a/src/os/unix/ngx_freebsd_config.h
+++ b/src/os/unix/ngx_freebsd_config.h
@@ -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>
diff --git a/src/os/unix/ngx_freebsd_init.c b/src/os/unix/ngx_freebsd_init.c
index aac8ed9..100dfc4 100644
--- a/src/os/unix/ngx_freebsd_init.c
+++ b/src/os/unix/ngx_freebsd_init.c
@@ -14,7 +14,7 @@
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 @@
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
similarity index 98%
rename from src/os/unix/ngx_freebsd_write_chain.c
rename to src/os/unix/ngx_freebsd_sendfile_chain.c
index 0317ade..fc510b7 100644
--- a/src/os/unix/ngx_freebsd_write_chain.c
+++ b/src/os/unix/ngx_freebsd_sendfile_chain.c
@@ -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;
diff --git a/src/os/unix/ngx_linux_config.h b/src/os/unix/ngx_linux_config.h
index 69a607e..e4c5dd0 100644
--- 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 <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
diff --git a/src/os/unix/ngx_solaris_config.h b/src/os/unix/ngx_solaris_config.h
index 1545fc9..786cf0b 100644
--- 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 <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;
diff --git a/src/os/unix/ngx_writev_chain.c b/src/os/unix/ngx_writev_chain.c
index fdaa52a..b667bc5 100644
--- a/src/os/unix/ngx_writev_chain.c
+++ b/src/os/unix/ngx_writev_chain.c
@@ -62,6 +62,8 @@
size = ce->hunk->last - ce->hunk->pos;
+ngx_log_debug(c->log, "SIZE: %d" _ size);
+
if (sent >= size) {
sent -= size;
@@ -69,9 +71,11 @@
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 @@
ce->hunk->pos += sent;
}
+#if 0
if (ce->hunk->type & NGX_HUNK_FILE) {
ce->hunk->file_pos += sent;
}
+#endif
break;
}