nginx-0.0.1-2003-05-13-20:02:32 import

This commit is contained in:
Igor Sysoev 2003-05-13 16:02:32 +00:00
parent 6b863e353d
commit d581fd58e1
18 changed files with 443 additions and 449 deletions

View File

@ -67,9 +67,11 @@ int main(int argc, char *const *argv)
#endif #endif
#if 0
if (ngx_os_init(&ngx_log) == NGX_ERROR) { if (ngx_os_init(&ngx_log) == NGX_ERROR) {
exit(1); exit(1);
} }
#endif
ngx_init_array(ngx_listening_sockets, ngx_pool, 10, sizeof(ngx_listen_t), ngx_init_array(ngx_listening_sockets, ngx_pool, 10, sizeof(ngx_listen_t),
1); 1);

View File

@ -73,6 +73,7 @@ void ngx_destroy_pool(ngx_pool_t *pool)
break; break;
} }
} }
pool = NULL;
} }
void *ngx_palloc(ngx_pool_t *pool, size_t size) void *ngx_palloc(ngx_pool_t *pool, size_t size)

View File

@ -26,7 +26,7 @@ struct ngx_connection_s {
off_t sent; off_t sent;
int (*handler)(ngx_connection_t *c); void (*handler)(ngx_connection_t *c);
void *ctx; void *ctx;
ngx_server_t *servers; ngx_server_t *servers;

View File

@ -22,7 +22,7 @@ typedef struct {
int protocol; int protocol;
int flags; /* Winsock2 flags */ int flags; /* Winsock2 flags */
int (*handler)(ngx_connection_t *c); /* handler of accepted void (*handler)(ngx_connection_t *c); /* handler of accepted
connection */ connection */
void *ctx; /* ngx_http_conf_ctx_t, for example */ void *ctx; /* ngx_http_conf_ctx_t, for example */
void *servers; /* array of ngx_http_in_addr_t, for example */ void *servers; /* array of ngx_http_in_addr_t, for example */

View File

@ -29,7 +29,9 @@ ngx_module_t *ngx_modules[] = {
/* &ngx_http_ssi_filter_module, */ /* &ngx_http_ssi_filter_module, */
&ngx_http_index_module, &ngx_http_index_module,
/*
&ngx_http_proxy_module, &ngx_http_proxy_module,
*/
NULL NULL
}; };

View File

@ -343,9 +343,7 @@ int ngx_kqueue_process_events(ngx_log_t *log)
case EVFILT_AIO: case EVFILT_AIO:
ev->ready = 1; ev->ready = 1;
if (ev->event_handler(ev) == NGX_ERROR) { ev->event_handler(ev);
ev->close_handler(ev);
}
break; break;

View File

@ -251,9 +251,7 @@ int ngx_poll_process_events(ngx_log_t *log)
} }
} }
if (ev->event_handler(ev) == NGX_ERROR) { ev->event_handler(ev);
ev->close_handler(ev);
}
} }
if (ready != 0) { if (ready != 0) {

View File

@ -306,8 +306,7 @@ int ngx_select_process_events(ngx_log_t *log)
ngx_select_del_event(ev, NGX_READ_EVENT, 0); ngx_select_del_event(ev, NGX_READ_EVENT, 0);
} }
if (ev->event_handler(ev) == NGX_ERROR) ev->event_handler(ev);
ev->close_handler(ev);
} }
if (ready != 0) { if (ready != 0) {

View File

@ -9,7 +9,6 @@
#include <ngx_listen.h> #include <ngx_listen.h>
#include <ngx_connection.h> #include <ngx_connection.h>
#include <ngx_event.h> #include <ngx_event.h>
#include <ngx_event_accept.h>
#include <ngx_select_module.h> #include <ngx_select_module.h>

View File

@ -28,9 +28,11 @@ typedef struct {
struct ngx_event_s { struct ngx_event_s {
void *data; void *data;
void (*event_handler)(ngx_event_t *ev);
int (*event_handler)(ngx_event_t *ev); #if 0
int (*close_handler)(ngx_event_t *ev); int (*close_handler)(ngx_event_t *ev);
#endif
void *context; void *context;
char *action; char *action;
@ -39,7 +41,9 @@ struct ngx_event_s {
ngx_event_t *prev; /* queue in mutex(), aio_read(), aio_write() */ ngx_event_t *prev; /* queue in mutex(), aio_read(), aio_write() */
ngx_event_t *next; /* */ ngx_event_t *next; /* */
#if 0
int (*timer_handler)(ngx_event_t *ev); int (*timer_handler)(ngx_event_t *ev);
#endif
ngx_event_t *timer_prev; ngx_event_t *timer_prev;
ngx_event_t *timer_next; ngx_event_t *timer_next;
@ -165,7 +169,7 @@ typedef struct {
#define NGX_HAVE_KQUEUE_EVENT 8 #define NGX_HAVE_KQUEUE_EVENT 8
/* The event filter supports low water mark - kqueue's NOTE_LOWAT. /* The event filter supports low water mark - kqueue's NOTE_LOWAT.
Early kqueue implementations have no NOTE_LOWAT so we need a separate flag */ kqueue in FreeBSD 4.1-4.2 has no NOTE_LOWAT so we need a separate flag */
#define NGX_HAVE_LOWAT_EVENT 0x00000010 #define NGX_HAVE_LOWAT_EVENT 0x00000010
/* The event filter notifies only the changes (the edges) /* The event filter notifies only the changes (the edges)
@ -294,6 +298,9 @@ extern int ngx_event_flags;
#endif #endif
void ngx_event_accept(ngx_event_t *ev);
ssize_t ngx_event_recv_core(ngx_connection_t *c, char *buf, size_t size); ssize_t ngx_event_recv_core(ngx_connection_t *c, char *buf, size_t size);
int ngx_event_close_connection(ngx_event_t *ev); int ngx_event_close_connection(ngx_event_t *ev);

View File

@ -7,14 +7,9 @@
#include <ngx_log.h> #include <ngx_log.h>
#include <ngx_connection.h> #include <ngx_connection.h>
#include <ngx_event.h> #include <ngx_event.h>
#include <ngx_event_close.h>
#include <ngx_event_accept.h>
/* This function should always return NGX_OK even there are some failures void ngx_event_accept(ngx_event_t *ev)
because if we return NGX_ERROR then listening socket would be closed */
int ngx_event_accept(ngx_event_t *ev)
{ {
int instance; int instance;
socklen_t len; socklen_t len;
@ -37,9 +32,16 @@ int ngx_event_accept(ngx_event_t *ev)
#endif #endif
do { do {
ngx_test_null(pool, ngx_create_pool(ls->pool_size, ev->log), NGX_OK); pool = ngx_create_pool(ls->pool_size, ev->log);
if (pool == NULL) {
return;
}
sa = ngx_palloc(pool, ls->socklen);
if (sa == NULL) {
return;
}
ngx_test_null(sa, ngx_palloc(pool, ls->socklen), NGX_OK);
len = ls->socklen; len = ls->socklen;
s = accept(ls->fd, sa, &len); s = accept(ls->fd, sa, &len);
@ -50,12 +52,12 @@ int ngx_event_accept(ngx_event_t *ev)
if (err == NGX_EAGAIN) { if (err == NGX_EAGAIN) {
ngx_log_error(NGX_LOG_NOTICE, ev->log, err, ngx_log_error(NGX_LOG_NOTICE, ev->log, err,
"EAGAIN while accept %s", ls->addr_text.data); "EAGAIN while accept %s", ls->addr_text.data);
return NGX_OK; return;
} }
ngx_log_error(NGX_LOG_ALERT, ev->log, err, ngx_log_error(NGX_LOG_ALERT, ev->log, err,
"accept %s failed", ls->addr_text.data); "accept %s failed", ls->addr_text.data);
return NGX_OK; return;
} }
@ -66,7 +68,7 @@ int ngx_event_accept(ngx_event_t *ev)
if (ngx_blocking(s) == -1) { if (ngx_blocking(s) == -1) {
ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_socket_errno, ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_socket_errno,
ngx_blocking_n " %s failed", ls->addr_text.data); ngx_blocking_n " %s failed", ls->addr_text.data);
return NGX_OK; return;
} }
} }
#endif #endif
@ -78,14 +80,14 @@ int ngx_event_accept(ngx_event_t *ev)
if (ngx_nonblocking(s) == -1) { if (ngx_nonblocking(s) == -1) {
ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_socket_errno, ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_socket_errno,
ngx_nonblocking_n " %s failed", ls->addr_text.data); ngx_nonblocking_n " %s failed", ls->addr_text.data);
return NGX_OK; return;
} }
} }
#else #else
if (ngx_nonblocking(s) == -1) { if (ngx_nonblocking(s) == -1) {
ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_socket_errno, ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_socket_errno,
ngx_nonblocking_n " %s failed", ls->addr_text.data); ngx_nonblocking_n " %s failed", ls->addr_text.data);
return NGX_OK; return;
} }
#endif #endif
@ -133,13 +135,13 @@ int ngx_event_accept(ngx_event_t *ev)
/* STUB ? */ wev->timer = rev->timer = 10000; /* STUB ? */ wev->timer = rev->timer = 10000;
wev->timer_handler = rev->timer_handler = ngx_event_close_connection;
wev->close_handler = rev->close_handler = ngx_event_close_connection;
c->ctx = ls->ctx; c->ctx = ls->ctx;
c->servers = ls->servers; c->servers = ls->servers;
ngx_test_null(c->log, ngx_palloc(c->pool, sizeof(ngx_log_t)), NGX_OK); c->log = ngx_palloc(c->pool, sizeof(ngx_log_t));
if (c->log == NULL) {
return;
}
ngx_memcpy(c->log, ev->log, sizeof(ngx_log_t)); ngx_memcpy(c->log, ev->log, sizeof(ngx_log_t));
rev->log = wev->log = c->log; rev->log = wev->log = c->log;
@ -159,7 +161,7 @@ int ngx_event_accept(ngx_event_t *ev)
if (ngx_event_flags & NGX_HAVE_EDGE_EVENT) { if (ngx_event_flags & NGX_HAVE_EDGE_EVENT) {
if (ngx_edge_add_event(ev) == NGX_ERROR) { if (ngx_edge_add_event(ev) == NGX_ERROR) {
return NGX_OK; return;
} }
} }
@ -183,5 +185,5 @@ int ngx_event_accept(ngx_event_t *ev)
#endif #endif
} while (ev->available); } while (ev->available);
return NGX_OK; return;
} }

View File

@ -1,10 +0,0 @@
#ifndef _NGX_EVENT_ACCEPT_H_INCLUDED_
#define _NGX_EVENT_ACCEPT_H_INCLUDED_
#include <ngx_event.h>
int ngx_event_accept(ngx_event_t *ev);
#endif /* _NGX_EVENT_ACCEPT_H_INCLUDED_ */

View File

@ -136,9 +136,7 @@ void ngx_event_expire_timers(ngx_msec_t timer)
ev->timedout = 1; ev->timedout = 1;
} }
if (ev->event_handler(ev) == NGX_ERROR) { ev->event_handler(ev);
ev->close_handler(ev);
}
} }
} }
} }

View File

@ -1,6 +1,6 @@
#include <ngx_config.h> #include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_string.h> #include <ngx_string.h>
#include <ngx_file.h> #include <ngx_file.h>
#include <ngx_hunk.h> #include <ngx_hunk.h>
@ -40,10 +40,7 @@ int ngx_http_static_handler(ngx_http_request_t *r)
"ngx_http_static_handler: " "ngx_http_static_handler: "
ngx_open_file_n " %s failed", r->file.name.data); ngx_open_file_n " %s failed", r->file.name.data);
if (err == NGX_ENOENT) { if (err == NGX_ENOENT || err == NGX_ENOTDIR) {
return NGX_HTTP_NOT_FOUND;
} else if (err == NGX_ENOTDIR) {
return NGX_HTTP_NOT_FOUND; return NGX_HTTP_NOT_FOUND;
} else { } else {
@ -126,11 +123,10 @@ int ngx_http_static_handler(ngx_http_request_t *r)
ngx_test_null(h->file, ngx_pcalloc(r->pool, sizeof(ngx_file_t)), ngx_test_null(h->file, ngx_pcalloc(r->pool, sizeof(ngx_file_t)),
NGX_HTTP_INTERNAL_SERVER_ERROR); NGX_HTTP_INTERNAL_SERVER_ERROR);
rc = ngx_http_send_header(r); ngx_http_send_header(r);
if (r->header_only) if (r->header_only)
return rc; return NGX_OK;
#if 1
h->type = NGX_HUNK_FILE|NGX_HUNK_LAST; h->type = NGX_HUNK_FILE|NGX_HUNK_LAST;
h->file_pos = 0; h->file_pos = 0;
@ -141,44 +137,14 @@ int ngx_http_static_handler(ngx_http_request_t *r)
rc = ngx_http_output_filter(r, h); rc = ngx_http_output_filter(r, h);
ngx_log_debug(r->connection->log, "0 output_filter: %d" _ rc); if (r->main == NULL) {
if (rc == NGX_AGAIN) {
ngx_http_set_write_handler(r);
#else } else {
ngx_http_finalize_request(r, 0);
#define BLK 10000
{
int i, s;
s = ngx_file_size(r->file.info);
for (i = 0; i < s; i += BLK) {
ngx_test_null(h, ngx_pcalloc(r->pool, sizeof(ngx_hunk_t)),
NGX_HTTP_INTERNAL_SERVER_ERROR);
ngx_test_null(h->file, ngx_pcalloc(r->pool, sizeof(ngx_file_t)),
NGX_HTTP_INTERNAL_SERVER_ERROR);
h->type = NGX_HUNK_FILE;
if (s - i <= BLK) {
h->type |= NGX_HUNK_LAST;
}
h->pos.file = i;
h->last.file = i + BLK;
if (h->last.file > s) {
h->last.file = s;
}
h->file->fd = r->file.fd;
h->file->log = r->connection->log;
rc = ngx_http_output_filter(r, h);
ngx_log_debug(r->connection->log, "0 output_filter: %d" _ rc);
} }
} }
#endif return NGX_OK;
return rc;
} }

View File

@ -235,6 +235,13 @@ void ngx_http_init_connection(ngx_connection_t *c);
int ngx_parse_http_request_line(ngx_http_request_t *r); int ngx_parse_http_request_line(ngx_http_request_t *r);
int ngx_parse_http_header_line(ngx_http_request_t *r, ngx_hunk_t *h); int ngx_parse_http_header_line(ngx_http_request_t *r, ngx_hunk_t *h);
int ngx_http_handler(ngx_http_request_t *r); int ngx_http_handler(ngx_http_request_t *r);
void ngx_http_finalize_request(ngx_http_request_t *r, int error);
void ngx_http_set_write_handler(ngx_http_request_t *r);
void ngx_http_close_request(ngx_http_request_t *r, int error);
void ngx_http_close_connection(ngx_connection_t *c);
int ngx_http_init_client_request_body(ngx_http_request_t *r, int size); int ngx_http_init_client_request_body(ngx_http_request_t *r, int size);

View File

@ -517,7 +517,8 @@ int ngx_http_redirect(ngx_http_request_t *r, int redirect)
/* log request */ /* log request */
return ngx_http_close_request(r, 0); ngx_http_close_request(r, 0);
return NGX_OK;
} }
@ -529,48 +530,8 @@ int ngx_http_error(ngx_http_request_t *r, int error)
/* log request */ /* log request */
ngx_http_special_response_handler(r, error); ngx_http_special_response_handler(r, error);
return ngx_http_close_request(r, 0); ngx_http_close_request(r, 0);
} return NGX_OK;
int ngx_http_close_request(ngx_http_request_t *r, int error)
{
ngx_connection_t *c;
ngx_http_log_ctx_t *ctx;
c = r->connection;
if (error) {
r->headers_out.status = error;
}
ngx_http_log_handler(r);
if (r->file.fd != NGX_INVALID_FILE) {
if (ngx_close_file(r->file.fd) == NGX_FILE_ERROR) {
ngx_log_error(NGX_LOG_ALERT, c->log, ngx_errno,
ngx_close_file_n " \"%s\" failed", r->file.name.data);
}
}
/* ctx->url was allocated from r->pool */
ctx = (ngx_http_log_ctx_t *) c->log->data;
ctx->url = NULL;
ngx_destroy_pool(r->pool);
if (c->read->timer_set) {
ngx_del_timer(c->read);
c->read->timer_set = 0;
}
if (c->write->timer_set) {
ngx_del_timer(c->write);
c->write->timer_set = 0;
}
ngx_log_debug(c->log, "http request closed");
return 0;
} }

View File

@ -103,8 +103,5 @@ int ngx_http_core_translate_handler(ngx_http_request_t *r);
int ngx_http_internal_redirect(ngx_http_request_t *r, ngx_str_t uri); int ngx_http_internal_redirect(ngx_http_request_t *r, ngx_str_t uri);
int ngx_http_error(ngx_http_request_t *r, int error); int ngx_http_error(ngx_http_request_t *r, int error);
int ngx_http_finalize_request(ngx_http_request_t *r, int error);
int ngx_http_close_request(ngx_http_request_t *r, int error);
#endif /* _NGX_HTTP_CORE_H_INCLUDED_ */ #endif /* _NGX_HTTP_CORE_H_INCLUDED_ */

File diff suppressed because it is too large Load Diff