mirror of
https://github.com/nginx/nginx.git
synced 2025-01-03 12:47:21 -06:00
nginx-0.0.1-2002-09-27-19:05:29 import
This commit is contained in:
parent
170efb2b7d
commit
31f8818eb1
@ -27,7 +27,7 @@ static int nchanges, nevents;
|
||||
|
||||
static ngx_event_t timer_queue;
|
||||
|
||||
void ngx_kqueue_init(int max_connections, ngx_log_t *log)
|
||||
int ngx_kqueue_init(int max_connections, ngx_log_t *log)
|
||||
{
|
||||
int size = sizeof(struct kevent) * 512;
|
||||
|
||||
@ -38,11 +38,11 @@ void ngx_kqueue_init(int max_connections, ngx_log_t *log)
|
||||
|
||||
if (kq == -1) {
|
||||
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "kqueue() failed");
|
||||
exit(1);
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
change_list = ngx_alloc(size, log);
|
||||
event_list = ngx_alloc(size, log);
|
||||
ngx_test_null(change_list, ngx_alloc(size, log), NGX_ERROR);
|
||||
ngx_test_null(event_list, ngx_alloc(size, log), NGX_ERROR);
|
||||
|
||||
timer_queue.timer_prev = &timer_queue;
|
||||
timer_queue.timer_next = &timer_queue;
|
||||
@ -53,6 +53,8 @@ void ngx_kqueue_init(int max_connections, ngx_log_t *log)
|
||||
ngx_event_actions.timer = ngx_kqueue_add_timer;
|
||||
ngx_event_actions.process = ngx_kqueue_process_events;
|
||||
#endif
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
int ngx_kqueue_add_event(ngx_event_t *ev, int event, u_int flags)
|
||||
@ -77,7 +79,7 @@ int ngx_kqueue_set_event(ngx_event_t *ev, int filter, u_int flags)
|
||||
|
||||
if (nchanges >= nevents) {
|
||||
ngx_log_error(NGX_LOG_WARN, ev->log, 0,
|
||||
"ngx_kqueue_set_event: change list is filled up");
|
||||
"kqueue change list is filled up");
|
||||
|
||||
if (kevent(kq, change_list, nchanges, NULL, 0, &ts) == -1) {
|
||||
ngx_log_error(NGX_LOG_ALERT, ev->log, ngx_errno, "kevent failed");
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <ngx_log.h>
|
||||
#include <ngx_event.h>
|
||||
|
||||
void ngx_kqueue_init(int max_connections, ngx_log_t *log);
|
||||
int ngx_kqueue_init(int max_connections, ngx_log_t *log);
|
||||
int ngx_kqueue_add_event(ngx_event_t *ev, int event, u_int flags);
|
||||
int ngx_kqueue_del_event(ngx_event_t *ev, int event);
|
||||
int ngx_kqueue_set_event(ngx_event_t *ev, int filter, u_int flags);
|
||||
|
@ -20,14 +20,17 @@ static int max_write;
|
||||
static int max_fd;
|
||||
#endif
|
||||
|
||||
static ngx_event_t event_queue;
|
||||
static ngx_event_t timer_queue;
|
||||
static int nevents;
|
||||
|
||||
static ngx_event_t **event_index;
|
||||
static ngx_event_t **ready_index;
|
||||
static ngx_event_t timer_queue;
|
||||
|
||||
|
||||
static fd_set *ngx_select_get_fd_set(ngx_socket_t fd, int event,
|
||||
ngx_log_t *log);
|
||||
|
||||
void ngx_select_init(int max_connections, ngx_log_t *log)
|
||||
int ngx_select_init(int max_connections, ngx_log_t *log)
|
||||
{
|
||||
if (max_connections > FD_SETSIZE) {
|
||||
ngx_log_error(NGX_LOG_EMERG, log, 0,
|
||||
@ -44,8 +47,15 @@ void ngx_select_init(int max_connections, ngx_log_t *log)
|
||||
FD_ZERO(&master_read_fd_set);
|
||||
FD_ZERO(&master_write_fd_set);
|
||||
|
||||
event_queue.prev = &event_queue;
|
||||
event_queue.next = &event_queue;
|
||||
ngx_test_null(event_index,
|
||||
ngx_alloc(sizeof(ngx_event_t *) * 2 * max_connections, log),
|
||||
NGX_ERROR);
|
||||
|
||||
ngx_test_null(ready_index,
|
||||
ngx_alloc(sizeof(ngx_event_t *) * 2 * max_connections, log),
|
||||
NGX_ERROR);
|
||||
|
||||
nevents = 0;
|
||||
|
||||
timer_queue.timer_prev = &timer_queue;
|
||||
timer_queue.timer_next = &timer_queue;
|
||||
@ -60,6 +70,8 @@ void ngx_select_init(int max_connections, ngx_log_t *log)
|
||||
#else
|
||||
max_fd = -1;
|
||||
#endif
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
int ngx_select_add_event(ngx_event_t *ev, int event, u_int flags)
|
||||
@ -102,10 +114,9 @@ int ngx_select_add_event(ngx_event_t *ev, int event, u_int flags)
|
||||
|
||||
ev->oneshot = (flags & NGX_ONESHOT_EVENT) ? 1: 0;
|
||||
|
||||
ev->prev = &event_queue;
|
||||
ev->next = event_queue.next;
|
||||
event_queue.next->prev = ev;
|
||||
event_queue.next = ev;
|
||||
event_index[nevents] = ev;
|
||||
ev->index = nevents;
|
||||
nevents++;
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
@ -135,23 +146,19 @@ int ngx_select_del_event(ngx_event_t *ev, int event)
|
||||
max_fd = -1;
|
||||
#endif
|
||||
|
||||
if (ev->prev)
|
||||
ev->prev->next = ev->next;
|
||||
|
||||
if (ev->next) {
|
||||
ev->next->prev = ev->prev;
|
||||
ev->prev = NULL;
|
||||
if (ev->index < nevents) {
|
||||
event_index[ev->index] = event_index[nevents];
|
||||
event_index[ev->index]->index = ev->index;
|
||||
}
|
||||
|
||||
if (ev->prev)
|
||||
ev->next = NULL;
|
||||
nevents--;
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
int ngx_select_process_events(ngx_log_t *log)
|
||||
{
|
||||
int ready, found;
|
||||
int i, ready, found, nready;
|
||||
u_int timer, delta;
|
||||
ngx_event_t *ev, *nx;
|
||||
ngx_connection_t *c;
|
||||
@ -176,8 +183,8 @@ int ngx_select_process_events(ngx_log_t *log)
|
||||
|
||||
#if !(WIN32)
|
||||
if (max_fd == -1) {
|
||||
for (ev = event_queue.next; ev != &event_queue; ev = ev->next) {
|
||||
c = (ngx_connection_t *) ev->data;
|
||||
for (i = 0; i < nevents; i++) {
|
||||
c = (ngx_connection_t *) event_index[i]->data;
|
||||
if (max_fd < c->fd)
|
||||
max_fd = c->fd;
|
||||
}
|
||||
@ -231,7 +238,10 @@ int ngx_select_process_events(ngx_log_t *log)
|
||||
}
|
||||
}
|
||||
|
||||
for (ev = event_queue.next; ev != &event_queue; /* void */) {
|
||||
nready = 0;
|
||||
|
||||
for (i = 0; i < nevents; i++) {
|
||||
ev = event_index[i];
|
||||
c = (ngx_connection_t *) ev->data;
|
||||
found = 0;
|
||||
|
||||
@ -250,26 +260,28 @@ int ngx_select_process_events(ngx_log_t *log)
|
||||
}
|
||||
}
|
||||
|
||||
nx = ev->next;
|
||||
|
||||
if (found) {
|
||||
ev->ready = 1;
|
||||
ready_index[nready++] = ev;
|
||||
}
|
||||
}
|
||||
|
||||
if (ev->oneshot) {
|
||||
ngx_del_timer(ev);
|
||||
if (ev->write)
|
||||
ngx_select_del_event(ev, NGX_WRITE_EVENT);
|
||||
else
|
||||
ngx_select_del_event(ev, NGX_READ_EVENT);
|
||||
}
|
||||
for (i = 0; i < nready; i++) {
|
||||
ev = ready_index[i];
|
||||
|
||||
if (ev->event_handler(ev) == -1)
|
||||
ev->close_handler(ev);
|
||||
ev->ready = 1;
|
||||
|
||||
ready--;
|
||||
if (ev->oneshot) {
|
||||
ngx_del_timer(ev);
|
||||
if (ev->write)
|
||||
ngx_select_del_event(ev, NGX_WRITE_EVENT);
|
||||
else
|
||||
ngx_select_del_event(ev, NGX_READ_EVENT);
|
||||
}
|
||||
|
||||
ev = nx;
|
||||
if (ev->event_handler(ev) == -1)
|
||||
ev->close_handler(ev);
|
||||
|
||||
ready--;
|
||||
}
|
||||
|
||||
ngx_assert((ready == 0), /* void */ ; , log, "select ready != events");
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <ngx_log.h>
|
||||
#include <ngx_event.h>
|
||||
|
||||
void ngx_select_init(int max_connections, ngx_log_t *log);
|
||||
int ngx_select_init(int max_connections, ngx_log_t *log);
|
||||
int ngx_select_add_event(ngx_event_t *ev, int event, u_int flags);
|
||||
int ngx_select_del_event(ngx_event_t *ev, int event);
|
||||
int ngx_select_set_event(ngx_event_t *ev, int filter, u_int flags);
|
||||
|
@ -1,5 +1,6 @@
|
||||
|
||||
#include <ngx_config.h>
|
||||
#include <ngx_core.h>
|
||||
#include <ngx_types.h>
|
||||
#include <ngx_string.h>
|
||||
#include <ngx_log.h>
|
||||
@ -20,7 +21,7 @@ ngx_event_t *ngx_read_events, *ngx_write_events;
|
||||
|
||||
#if !(USE_KQUEUE)
|
||||
|
||||
#if 0
|
||||
#if 1
|
||||
ngx_event_type_e ngx_event_type = NGX_SELECT_EVENT;
|
||||
#else
|
||||
ngx_event_type_e ngx_event_type = NGX_KQUEUE_EVENT;
|
||||
@ -29,7 +30,7 @@ ngx_event_type_e ngx_event_type = NGX_KQUEUE_EVENT;
|
||||
ngx_event_actions_t ngx_event_actions;
|
||||
|
||||
/* ngx_event_type_e order */
|
||||
static void (*ngx_event_init[]) (int max_connections, ngx_log_t *log) = {
|
||||
static int (*ngx_event_init[]) (int max_connections, ngx_log_t *log) = {
|
||||
ngx_select_init,
|
||||
#if (HAVE_POLL)
|
||||
ngx_poll_init,
|
||||
@ -50,7 +51,8 @@ void ngx_pre_thread(ngx_array_t *ls, ngx_pool_t *pool, ngx_log_t *log)
|
||||
/* STUB */
|
||||
int max_connections = 512;
|
||||
|
||||
ngx_init_events(max_connections, log);
|
||||
if (ngx_init_events(max_connections, log) == NGX_ERROR)
|
||||
exit(1);
|
||||
|
||||
ngx_connections = ngx_alloc(sizeof(ngx_connection_t)
|
||||
* max_connections, log);
|
||||
|
@ -20,6 +20,8 @@ struct ngx_event_s {
|
||||
void *context;
|
||||
char *action;
|
||||
|
||||
int index;
|
||||
|
||||
ngx_event_t *prev; /* queue in select(), poll(), mutex(), */
|
||||
ngx_event_t *next; /* aio_read(), aio_write() */
|
||||
|
||||
|
@ -491,7 +491,7 @@ static int ngx_http_handler(ngx_http_request_t *r)
|
||||
r->connection->read->event_handler = ngx_http_block_read;
|
||||
|
||||
/* STUB: should find handler */
|
||||
#if 0
|
||||
#if 1
|
||||
r->filter = NGX_HTTP_FILTER_NEED_IN_MEMORY;
|
||||
#endif
|
||||
rc = ngx_http_set_default_handler(r);
|
||||
|
Loading…
Reference in New Issue
Block a user