summaryrefslogtreecommitdiffhomepage
path: root/src/event
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/event/modules/ngx_kqueue_module.c175
-rw-r--r--src/event/ngx_event.c81
-rw-r--r--src/event/ngx_event.h8
-rw-r--r--src/event/ngx_event_accept.c2
-rw-r--r--src/event/ngx_event_timer.c15
-rw-r--r--src/event/ngx_event_timer.h4
6 files changed, 71 insertions, 214 deletions
diff --git a/src/event/modules/ngx_kqueue_module.c b/src/event/modules/ngx_kqueue_module.c
index 51df43bb2..bdd1ff4c3 100644
--- a/src/event/modules/ngx_kqueue_module.c
+++ b/src/event/modules/ngx_kqueue_module.c
@@ -11,16 +11,13 @@
typedef struct {
- int kqueue;
- struct kevent *change_list;
u_int changes;
- struct kevent *event_list;
u_int events;
} ngx_kqueue_conf_t;
-static int ngx_kqueue_init(ngx_log_t *log);
-static void ngx_kqueue_done(ngx_log_t *log);
+static int ngx_kqueue_init(ngx_cycle_t *cycle);
+static void ngx_kqueue_done(ngx_cycle_t *cycle);
static int ngx_kqueue_add_event(ngx_event_t *ev, int event, u_int flags);
static int ngx_kqueue_del_event(ngx_event_t *ev, int event, u_int flags);
static int ngx_kqueue_set_event(ngx_event_t *ev, int filter, u_int flags);
@@ -72,10 +69,6 @@ ngx_event_module_t ngx_kqueue_module_ctx = {
NULL, /* delete an connection */
ngx_kqueue_process_events, /* process the events */
ngx_kqueue_init, /* init the events */
-#if 0
- ngx_kqueue_commit, /* commit the events */
- ngx_kqueue_rollback, /* rollback the events */
-#endif
ngx_kqueue_done /* done the events */
}
@@ -87,158 +80,27 @@ ngx_module_t ngx_kqueue_module = {
ngx_kqueue_commands, /* module directives */
NGX_EVENT_MODULE, /* module type */
NULL, /* init module */
- NULL, /* commit module */
- NULL, /* rollback module */
-#if 0
NULL /* init child */
-#endif
};
-#if 0
-static int ngx_kqueue_init(ngx_cycle_t *cycle, ngx_log_t *log)
+static int ngx_kqueue_init(ngx_cycle_t *cycle)
{
struct timespec ts;
ngx_kqueue_conf_t *kcf;
kcf = ngx_event_get_conf(cycle->conf_ctx, ngx_kqueue_module);
-ngx_log_debug(log, "CH: %d" _ kcf->changes);
-ngx_log_debug(log, "EV: %d" _ kcf->events);
-
- if (ngx_kqueue == -1) {
- kcf->kqueue = kqueue();
-
- if (kcf->kqueue == -1) {
- ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "kqueue() failed");
- return NGX_ERROR;
- }
-
- } else {
- kcf->kqueue = ngx_kqueue;
- }
-
- if (max_changes < kcf->changes) {
- if (nchanges) {
- ts.tv_sec = 0;
- ts.tv_nsec = 0;
-
- if (kevent(ngx_kqueue, change_list, nchanges, NULL, 0, &ts) == -1) {
- ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "kevent() failed");
- return NGX_ERROR;
- }
-
- nchanges = 0;
- }
-
- ngx_test_null(kcf->change_list,
- ngx_alloc(kcf->changes * sizeof(struct kevent), log),
- NGX_ERROR);
-
- } else {
- kcf->change_list = change_list;
- }
-
- if (nevents < kcf->events) {
- ngx_test_null(kcf->event_list,
- ngx_alloc(kcf->events * sizeof(struct kevent), log),
- NGX_ERROR);
- } else {
- kcf->event_list = event_list;
- }
-
- if (ngx_event_timer_init(cycle, log) == NGX_ERROR) {
- return NGX_ERROR;
- }
-
- return NGX_OK;
-}
-
-
-static void ngx_kqueue_commit(ngx_cycle_t *cycle, ngx_log_t *log)
-{
- ngx_kqueue_conf_t *kcf;
-
- kcf = ngx_event_get_conf(cycle->conf_ctx, ngx_kqueue_module);
-
- ngx_kqueue = kcf->kqueue;
-
- if (change_list != kcf->change_list) {
- ngx_free(change_list);
- change_list = kcf->change_list;
- }
-
- max_changes = kcf->changes;
-
- if (event_list != kcf->event_list) {
- ngx_free(event_list);
- event_list = kcf->event_list;
- }
-
- nevents = kcf->events;
-
- ngx_event_timer_commit(cycle, log);
-
- ngx_event_actions = ngx_kqueue_module_ctx.actions;
- ngx_io = ngx_os_io;
-
- ngx_event_flags = NGX_HAVE_LEVEL_EVENT
- |NGX_HAVE_ONESHOT_EVENT
-#if (HAVE_CLEAR_EVENT)
- |NGX_HAVE_CLEAR_EVENT
-#else
- |NGX_USE_LEVEL_EVENT
-#endif
-#if (HAVE_LOWAT_EVENT)
- |NGX_HAVE_LOWAT_EVENT
-#endif
- |NGX_HAVE_KQUEUE_EVENT;
-}
-
-
-static void ngx_kqueue_rollback(ngx_cycle_t *cycle, ngx_log_t *log)
-{
- ngx_kqueue_conf_t *kcf;
-
- kcf = ngx_event_get_conf(cycle->conf_ctx, ngx_kqueue_module);
-
- if (ngx_kqueue == -1) {
- if (close(kcf->kqueue) == -1) {
- ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
- "kqueue close() failed");
- }
- }
-
- if (change_list != kcf->change_list) {
- ngx_free(kcf->change_list);
- }
-
- if (event_list != kcf->event_list) {
- ngx_free(kcf->event_list);
- }
-
- ngx_event_timer_rollback(cycle, log);
-}
-
-#endif
-
-
-static int ngx_kqueue_init(ngx_log_t *log)
-{
- struct timespec ts;
- ngx_kqueue_conf_t *kcf;
-
- kcf = ngx_event_get_conf(ngx_kqueue_module);
-
-ngx_log_debug(log, "CH: %d" _ kcf->changes);
-ngx_log_debug(log, "EV: %d" _ kcf->events);
+ngx_log_debug(cycle->log, "CH: %d" _ kcf->changes);
+ngx_log_debug(cycle->log, "EV: %d" _ kcf->events);
if (ngx_kqueue == -1) {
ngx_kqueue = kqueue();
if (ngx_kqueue == -1) {
- ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "kqueue() failed");
+ ngx_log_error(NGX_LOG_EMERG, cycle->log, ngx_errno,
+ "kqueue() failed");
return NGX_ERROR;
}
}
@@ -249,9 +111,11 @@ ngx_log_debug(log, "EV: %d" _ kcf->events);
ts.tv_nsec = 0;
if (kevent(ngx_kqueue, change_list, nchanges, NULL, 0, &ts) == -1) {
- ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "kevent() failed");
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+ "kevent() failed");
return NGX_ERROR;
}
+ nchanges = 0;
}
if (change_list) {
@@ -259,12 +123,12 @@ ngx_log_debug(log, "EV: %d" _ kcf->events);
}
ngx_test_null(change_list,
- ngx_alloc(kcf->changes * sizeof(struct kevent), log),
+ ngx_alloc(kcf->changes * sizeof(struct kevent),
+ cycle->log),
NGX_ERROR);
}
max_changes = kcf->changes;
- nchanges = 0;
if (nevents < kcf->events) {
if (event_list) {
@@ -272,18 +136,18 @@ ngx_log_debug(log, "EV: %d" _ kcf->events);
}
ngx_test_null(event_list,
- ngx_alloc(kcf->events * sizeof(struct kevent), log),
+ ngx_alloc(kcf->events * sizeof(struct kevent),
+ cycle->log),
NGX_ERROR);
}
nevents = kcf->events;
- if (ngx_event_timer_init(log) == NGX_ERROR) {
+ if (ngx_event_timer_init(cycle) == NGX_ERROR) {
return NGX_ERROR;
}
- /* TODO: re-add active events with new udata
- if ecf->connections was increased */
+ ngx_io = ngx_os_io;
ngx_event_actions = ngx_kqueue_module_ctx.actions;
@@ -303,15 +167,16 @@ ngx_log_debug(log, "EV: %d" _ kcf->events);
}
-static void ngx_kqueue_done(ngx_log_t *log)
+static void ngx_kqueue_done(ngx_cycle_t *cycle)
{
if (close(ngx_kqueue) == -1) {
- ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "kqueue close() failed");
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, ngx_errno,
+ "kqueue close() failed");
}
ngx_kqueue = -1;
- ngx_event_timer_done(log);
+ ngx_event_timer_done(cycle);
ngx_free(change_list);
ngx_free(event_list);
diff --git a/src/event/ngx_event.c b/src/event/ngx_event.c
index b5d3b26e2..bc4386a77 100644
--- a/src/event/ngx_event.c
+++ b/src/event/ngx_event.c
@@ -4,7 +4,7 @@
#include <ngx_event.h>
-#define DEF_CONNECTIONS 512
+#define DEFAULT_CONNECTIONS 512
extern ngx_module_t ngx_select_module;
@@ -21,6 +21,9 @@ extern ngx_module_t ngx_devpoll_module;
#include <ngx_aio_module.h>
#endif
+static int ngx_event_init_module(ngx_cycle_t *cycle);
+static int ngx_event_init_child(ngx_cycle_t *cycle);
+static int ngx_event_init(ngx_cycle_t *cycle);
static char *ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static char *ngx_event_use(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
@@ -31,15 +34,14 @@ static char *ngx_event_init_conf(ngx_pool_t *pool, void *conf);
int ngx_event_flags;
ngx_event_actions_t ngx_event_actions;
+int ngx_max_connections;
ngx_connection_t *ngx_connections;
ngx_event_t *ngx_read_events, *ngx_write_events;
-static int ngx_event_max_module;
+static int ngx_event_max_module;
-static int ngx_event_connections;
-
static ngx_str_t events_name = ngx_string("events");
@@ -61,7 +63,8 @@ ngx_module_t ngx_events_module = {
&events_name, /* module context */
ngx_events_commands, /* module directives */
NGX_CORE_MODULE, /* module type */
- NULL /* init module */
+ NULL, /* init module */
+ NULL /* init child */
};
@@ -109,17 +112,15 @@ ngx_module_t ngx_event_core_module = {
ngx_event_core_commands, /* module directives */
NGX_EVENT_MODULE, /* module type */
ngx_event_init_module, /* init module */
- ngx_event_commit, /* commit module */
- ngx_event_rollback, /* rollback module */
ngx_event_init_child /* init child */
};
-static int ngx_event_init_module(ngx_cycle_t *cycle, ngx_log_t *log)
+static int ngx_event_init_module(ngx_cycle_t *cycle)
{
if (cycle->one_process) {
- return ngx_event_init(cycle, log);
+ return ngx_event_init(cycle);
}
return NGX_OK;
@@ -128,18 +129,15 @@ static int ngx_event_init_module(ngx_cycle_t *cycle, ngx_log_t *log)
static int ngx_event_init_child(ngx_cycle_t *cycle)
{
- if (!cycle->one_process) {
- if (ngx_event_init(cycle, cycle->log) == NGX_ERROR) {
- return NGX_ERROR;
- }
- ngx_event_commit(cycle, cycle->log);
+ if (cycle->one_process) {
+ return NGX_OK;
}
- return NGX_OK;
+ return ngx_event_init(cycle);
}
-static int ngx_event_init(ngx_cycle_t *cycle, ngx_log_t *log)
+static int ngx_event_init(ngx_cycle_t *cycle)
{
int m, i, fd;
ngx_event_t *rev, *wev;
@@ -153,8 +151,8 @@ static int ngx_event_init(ngx_cycle_t *cycle, ngx_log_t *log)
ecf = ngx_event_get_conf(cycle->conf_ctx, ngx_event_core_module);
-ngx_log_debug(log, "CONN: %d" _ ecf->connections);
-ngx_log_debug(log, "TYPE: %d" _ ecf->use);
+ngx_log_debug(cycle->log, "CONN: %d" _ ecf->connections);
+ngx_log_debug(cycle->log, "TYPE: %d" _ ecf->use);
for (m = 0; ngx_modules[m]; m++) {
if (ngx_modules[m]->type != NGX_EVENT_MODULE) {
@@ -163,31 +161,37 @@ ngx_log_debug(log, "TYPE: %d" _ ecf->use);
if (ngx_modules[m]->ctx_index == ecf->use) {
module = ngx_modules[m]->ctx;
- if (module->actions.init(log) == NGX_ERROR) {
+ if (module->actions.init(cycle) == NGX_ERROR) {
return NGX_ERROR;
}
break;
}
}
- if (ecf->connections) {
+ if (ngx_max_connections && ngx_max_connections < ecf->connections) {
+ /* TODO: push into delayed array and temporary pool */
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "NOT READY");
+ exit(1);
}
+ ngx_max_connections = ecf->connections;
+
ngx_test_null(ngx_connections,
- ngx_alloc(sizeof(ngx_connection_t) * ecf->connections, log),
+ ngx_alloc(sizeof(ngx_connection_t) * ecf->connections,
+ cycle->log),
NGX_ERROR);
ngx_test_null(ngx_read_events,
- ngx_alloc(sizeof(ngx_event_t) * ecf->connections, log),
+ ngx_alloc(sizeof(ngx_event_t) * ecf->connections, cycle->log),
NGX_ERROR);
ngx_test_null(ngx_write_events,
- ngx_alloc(sizeof(ngx_event_t) * ecf->connections, log),
+ ngx_alloc(sizeof(ngx_event_t) * ecf->connections, cycle->log),
NGX_ERROR);
/* for each listening socket */
- for (s = ls->elts, i = 0; i < ls->nelts; i++) {
+ for (s = cycle->listening.elts, i = 0; i < cycle->listening.nelts; i++) {
fd = s[i].fd;
@@ -216,7 +220,8 @@ ngx_log_debug(log, "TYPE: %d" _ ecf->use);
c->servers = s[i].servers;
c->log = s[i].log;
- ngx_test_null(rev->log, ngx_palloc(pool, sizeof(ngx_log_t)), NGX_ERROR);
+ ngx_test_null(rev->log, ngx_palloc(cycle->pool, sizeof(ngx_log_t)),
+ NGX_ERROR);
ngx_memcpy(rev->log, c->log, sizeof(ngx_log_t));
c->read = rev;
@@ -264,26 +269,6 @@ ngx_log_debug(log, "TYPE: %d" _ ecf->use);
}
-static void ngx_event_commit(ngx_cycle_t *cycle, ngx_log_t *log)
-{
-}
-
-
-static void ngx_event_rollback(ngx_cycle_t *cycle, ngx_log_t *log)
-{
-}
-
-
-void ngx_worker(ngx_cycle_t *cycle)
-{
- for ( ;; ) {
- ngx_log_debug(cycle->log, "ngx_worker cycle");
-
- ngx_process_events(cycle->log);
- }
-}
-
-
static char *ngx_events_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
int m;
@@ -407,18 +392,18 @@ static char *ngx_event_init_conf(ngx_pool_t *pool, void *conf)
#if (HAVE_KQUEUE)
- ngx_conf_init_value(ecf->connections, DEF_CONNECTIONS);
+ ngx_conf_init_value(ecf->connections, DEFAULT_CONNECTIONS);
ngx_conf_init_value(ecf->use, ngx_kqueue_module.ctx_index);
#elif (HAVE_DEVPOLL)
- ngx_conf_init_value(ecf->connections, DEF_CONNECTIONS);
+ ngx_conf_init_value(ecf->connections, DEFAULT_CONNECTIONS);
ngx_conf_init_value(ecf->use, ngx_devpoll_module.ctx_index);
#else /* HAVE_SELECT */
ngx_conf_init_value(ecf->connections,
- FD_SETSIZE < DEF_CONNECTIONS ? FD_SETSIZE : DEF_CONNECTIONS);
+ FD_SETSIZE < DEFAULT_CONNECTIONS ? FD_SETSIZE : DEFAULT_CONNECTIONS);
ngx_conf_init_value(ecf->use, ngx_select_module.ctx_index);
diff --git a/src/event/ngx_event.h b/src/event/ngx_event.h
index 393699f0a..2d64c11c6 100644
--- a/src/event/ngx_event.h
+++ b/src/event/ngx_event.h
@@ -151,8 +151,8 @@ typedef struct {
int (*del_conn)(ngx_connection_t *c);
int (*process)(ngx_log_t *log);
- int (*init)(ngx_log_t *log);
- void (*done)(ngx_log_t *log);
+ int (*init)(ngx_cycle_t *cycle);
+ void (*done)(ngx_cycle_t *cycle);
} ngx_event_actions_t;
@@ -348,8 +348,8 @@ extern ngx_module_t ngx_events_module;
extern ngx_module_t ngx_event_core_module;
-#define ngx_event_get_conf(module) \
- (*(ngx_get_conf(ngx_events_module))) [module.ctx_index];
+#define ngx_event_get_conf(conf_ctx, module) \
+ (*(ngx_get_conf(conf_ctx, ngx_events_module))) [module.ctx_index];
diff --git a/src/event/ngx_event_accept.c b/src/event/ngx_event_accept.c
index 2d2eed4f4..a71dced8a 100644
--- a/src/event/ngx_event_accept.c
+++ b/src/event/ngx_event_accept.c
@@ -17,7 +17,7 @@ void ngx_event_accept(ngx_event_t *ev)
ngx_connection_t *c, *ls;
ngx_event_conf_t *ecf;
- ecf = ngx_event_get_conf(ngx_event_core_module);
+ ecf = ngx_event_get_conf(ngx_cycle.conf_ctx, ngx_event_core_module);
ls = ev->data;
diff --git a/src/event/ngx_event_timer.c b/src/event/ngx_event_timer.c
index 9ca3fe504..412298312 100644
--- a/src/event/ngx_event_timer.c
+++ b/src/event/ngx_event_timer.c
@@ -9,17 +9,18 @@ static int ngx_timer_cur_queue;
static int ngx_timer_queue_num;
-int ngx_event_timer_init(ngx_log_t *log)
+int ngx_event_timer_init(ngx_cycle_t *cycle)
{
int i;
ngx_event_t *new_queue;
ngx_event_conf_t *ecf;
- ecf = ngx_event_get_conf(ngx_event_core_module);
+ ecf = ngx_event_get_conf(cycle->conf_ctx, ngx_event_core_module);
if (ngx_timer_queue_num < ecf->timer_queues) {
ngx_test_null(new_queue,
- ngx_alloc(ecf->timer_queues * sizeof(ngx_event_t), log),
+ ngx_alloc(ecf->timer_queues * sizeof(ngx_event_t),
+ cycle->log),
NGX_ERROR);
for (i = 0; i < ngx_timer_queue_num; i++) {
@@ -39,16 +40,22 @@ int ngx_event_timer_init(ngx_log_t *log)
ngx_timer_queue[i].timer_prev = &ngx_timer_queue[i];
ngx_timer_queue[i].timer_next = &ngx_timer_queue[i];
}
+
+ } else if (ngx_timer_queue_num > ecf->timer_queues) {
+ /* STUB */
+ ngx_log_error(NGX_LOG_ALERT, cycle->log, 0, "NOT READY");
+ exit(1);
}
return NGX_OK;;
}
-void ngx_event_timer_done(ngx_log_t *log)
+void ngx_event_timer_done(ngx_cycle_t *cycle)
{
ngx_free(ngx_timer_queue);
ngx_timer_queue = NULL;
+ ngx_timer_queue_num = 0;
}
diff --git a/src/event/ngx_event_timer.h b/src/event/ngx_event_timer.h
index 2704c58c9..7a6c52cb2 100644
--- a/src/event/ngx_event_timer.h
+++ b/src/event/ngx_event_timer.h
@@ -7,8 +7,8 @@
#include <ngx_event.h>
-int ngx_event_timer_init(ngx_log_t *log);
-void ngx_event_timer_done(ngx_log_t *log);
+int ngx_event_timer_init(ngx_cycle_t *cycle);
+void ngx_event_timer_done(ngx_cycle_t *cycle);
void ngx_event_add_timer(ngx_event_t *ev, ngx_msec_t timer);
int ngx_event_find_timer(void);
void ngx_event_expire_timers(ngx_msec_t timer);