Mercurial > hg > nginx
changeset 50:b288069a8696
nginx-0.0.1-2003-01-23-21:47:54 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 23 Jan 2003 18:47:54 +0000 |
parents | c091d5b853c8 |
children | a6afbb8a2ada |
files | src/event/modules/ngx_devpoll_module.c src/event/modules/ngx_kqueue_module.c src/event/modules/ngx_poll_module.c src/event/modules/ngx_select_module.c src/event/ngx_event.h src/event/ngx_event_close.c src/event/ngx_event_timer.c src/event/ngx_event_timer.h src/http/ngx_http.h src/http/ngx_http_event.c src/os/unix/ngx_time.h src/os/win32/ngx_time.h |
diffstat | 12 files changed, 138 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/event/modules/ngx_devpoll_module.c Tue Jan 21 17:36:01 2003 +0000 +++ b/src/event/modules/ngx_devpoll_module.c Thu Jan 23 18:47:54 2003 +0000 @@ -9,6 +9,7 @@ #include <ngx_log.h> #include <ngx_connection.h> #include <ngx_event.h> +#include <ngx_event_timer.h> #include <ngx_devpoll_module.h> #if (USE_DEVPOLL) && !(HAVE_DEVPOLL)
--- a/src/event/modules/ngx_kqueue_module.c Tue Jan 21 17:36:01 2003 +0000 +++ b/src/event/modules/ngx_kqueue_module.c Thu Jan 23 18:47:54 2003 +0000 @@ -9,6 +9,7 @@ #include <ngx_log.h> #include <ngx_connection.h> #include <ngx_event.h> +#include <ngx_event_timer.h> #include <ngx_kqueue_module.h> #if (USE_KQUEUE) && !(HAVE_KQUEUE) @@ -50,8 +51,14 @@ ngx_test_null(change_list, ngx_alloc(change_size, log), NGX_ERROR); ngx_test_null(event_list, ngx_alloc(event_size, log), NGX_ERROR); + if (ngx_event_init_timer(log) == NGX_ERROR) { + return NGX_ERROR; + } + +#if 0 timer_queue.timer_prev = &timer_queue; timer_queue.timer_next = &timer_queue; +#endif #if !(USE_KQUEUE) ngx_event_actions.add = ngx_kqueue_add_event;
--- a/src/event/modules/ngx_poll_module.c Tue Jan 21 17:36:01 2003 +0000 +++ b/src/event/modules/ngx_poll_module.c Thu Jan 23 18:47:54 2003 +0000 @@ -7,6 +7,7 @@ #include <ngx_time.h> #include <ngx_connection.h> #include <ngx_event.h> +#include <ngx_event_timer.h> #include <ngx_poll_module.h>
--- a/src/event/modules/ngx_select_module.c Tue Jan 21 17:36:01 2003 +0000 +++ b/src/event/modules/ngx_select_module.c Thu Jan 23 18:47:54 2003 +0000 @@ -6,6 +6,7 @@ #include <ngx_time.h> #include <ngx_connection.h> #include <ngx_event.h> +#include <ngx_event_timer.h> #include <ngx_select_module.h>
--- a/src/event/ngx_event.h Tue Jan 21 17:36:01 2003 +0000 +++ b/src/event/ngx_event.h Thu Jan 23 18:47:54 2003 +0000 @@ -10,6 +10,7 @@ #include <ngx_alloc.h> #include <ngx_array.h> + #define NGX_INVALID_INDEX 0x80000000 typedef struct ngx_event_s ngx_event_t; @@ -31,8 +32,8 @@ ngx_event_t *timer_prev; ngx_event_t *timer_next; - u_int timer_delta; - u_int timer; + ngx_msec_t timer_delta; + ngx_msec_t timer; ngx_log_t *log; @@ -150,7 +151,11 @@ #define ngx_process_events ngx_kqueue_process_events #define ngx_add_event ngx_kqueue_add_event #define ngx_del_event ngx_kqueue_del_event +#if 0 #define ngx_add_timer ngx_kqueue_add_timer +#else +#define ngx_add_timer ngx_event_add_timer +#endif #define ngx_event_recv ngx_event_recv_core #else @@ -159,12 +164,19 @@ #define ngx_process_events ngx_event_actions.process #define ngx_add_event ngx_event_actions.add #define ngx_del_event ngx_event_actions.del +#if 0 #define ngx_add_timer ngx_event_actions.timer +#else +#define ngx_add_timer ngx_event_add_timer +#endif #define ngx_event_recv ngx_event_recv_core #endif +#define ngx_del_timer ngx_event_del_timer + +#if 0 ngx_inline static void ngx_del_timer(ngx_event_t *ev) { #if (NGX_DEBUG_EVENT) @@ -186,7 +198,7 @@ ev->timer_prev = NULL; } } - +#endif
--- a/src/event/ngx_event_close.c Tue Jan 21 17:36:01 2003 +0000 +++ b/src/event/ngx_event_close.c Thu Jan 23 18:47:54 2003 +0000 @@ -3,6 +3,8 @@ #include <ngx_core.h> #include <ngx_types.h> #include <ngx_connection.h> +#include <ngx_event.h> +#include <ngx_event_timer.h> #include <ngx_event_close.h>
--- a/src/event/ngx_event_timer.c Tue Jan 21 17:36:01 2003 +0000 +++ b/src/event/ngx_event_timer.c Thu Jan 23 18:47:54 2003 +0000 @@ -1,7 +1,43 @@ + +#include <ngx_config.h> + +#include <ngx_core.h> +#include <ngx_log.h> +#include <ngx_alloc.h> +#include <ngx_connection.h> +#include <ngx_event.h> + +#include <ngx_event_timer.h> + +/* STUB */ +#define NGX_TIMER_HASH_SIZE 5 + +ngx_event_t *ngx_timer_queue; +int ngx_timer_hash_size; -void ngx_add_timer(ngx_event_t *ev, ngx_msec_t timer) +int ngx_event_init_timer(ngx_log_t *log) { + int i; + + ngx_timer_hash_size = NGX_TIMER_HASH_SIZE; + + ngx_test_null(ngx_timer_queue, + ngx_alloc(ngx_timer_hash_size * sizeof(ngx_event_t), log), + NGX_ERROR); + + for (i = 0; i < ngx_timer_hash_size; i++) { + ngx_timer_queue[i].timer_prev = &ngx_timer_queue[i]; + ngx_timer_queue[i].timer_next = &ngx_timer_queue[i]; + } + + return NGX_OK; +} + + +void ngx_event_add_timer(ngx_event_t *ev, ngx_msec_t timer) +{ + int n; ngx_event_t *e; #if (NGX_DEBUG_EVENT) @@ -16,8 +52,8 @@ n = timer % ngx_timer_hash_size; - for (e = timer_queue[n].timer_next; - e != &timer_queue[n] && timer > e->timer_delta; + for (e = ngx_timer_queue[n].timer_next; + e != &ngx_timer_queue[n] && timer > e->timer_delta; e = e->timer_next) { timer -= e->timer_delta;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/event/ngx_event_timer.h Thu Jan 23 18:47:54 2003 +0000 @@ -0,0 +1,65 @@ +#ifndef _NGX_EVENT_TIMER_H_INCLUDED_ +#define _NGX_EVENT_TIMER_H_INCLUDED_ + + +#include <ngx_config.h> + +#include <ngx_log.h> +#include <ngx_connection.h> +#include <ngx_event.h> + + +int ngx_event_init_timer(ngx_log_t *log); +void ngx_event_add_timer(ngx_event_t *ev, ngx_msec_t timer); + +extern ngx_event_t *ngx_timer_queue; +extern int ngx_timer_hash_size; + + +ngx_inline static int ngx_event_get_timer() +{ + int i; + ngx_msec_t timer; + + timer = NGX_MAX_MSEC; + + for (i = 0; i < ngx_timer_hash_size; i++) { + if (ngx_timer_queue[i].timer_next != &ngx_timer_queue[i]) { + if (timer > ngx_timer_queue[i].timer_next->timer_delta) { + timer = ngx_timer_queue[i].timer_next->timer_delta; + } + } + } + + if (timer == NGX_MAX_MSEC) { + return 0; + } else { + return timer; + } +} + + +ngx_inline static void ngx_event_del_timer(ngx_event_t *ev) +{ +#if (NGX_DEBUG_EVENT) + /* STUB - we can not cast (ngx_connection_t *) here */ + ngx_log_debug(ev->log, "del timer: %d" _ *(int *)(ev->data)); +#endif + + if (ev->timer_prev) { + ev->timer_prev->timer_next = ev->timer_next; + } + + if (ev->timer_next) { + ev->timer_next->timer_delta += ev->timer_delta; + ev->timer_next->timer_prev = ev->timer_prev; + ev->timer_next = NULL; + } + + if (ev->timer_prev) { + ev->timer_prev = NULL; + } +} + + +#endif _NGX_EVENT_TIMER_H_INCLUDED_
--- a/src/http/ngx_http.h Tue Jan 21 17:36:01 2003 +0000 +++ b/src/http/ngx_http.h Thu Jan 23 18:47:54 2003 +0000 @@ -12,6 +12,8 @@ #include <ngx_connection.h> #include <ngx_conf_file.h> +/* STUB */ +#include <ngx_event_timer.h> #define NGX_HTTP_VERSION_10 1000
--- a/src/http/ngx_http_event.c Tue Jan 21 17:36:01 2003 +0000 +++ b/src/http/ngx_http_event.c Thu Jan 23 18:47:54 2003 +0000 @@ -9,6 +9,8 @@ #include <ngx_table.h> #include <ngx_hunk.h> #include <ngx_connection.h> +#include <ngx_event.h> +#include <ngx_event_timer.h> #include <ngx_inet.h> #include <ngx_http.h> #include <ngx_http_config.h>