nginx-quic/src/event/ngx_event.h

389 lines
9.3 KiB
C
Raw Normal View History

#ifndef _NGX_EVENT_H_INCLUDED_
#define _NGX_EVENT_H_INCLUDED_
#include <ngx_config.h>
2003-05-20 11:37:55 -04:00
#include <ngx_core.h>
2002-12-15 03:25:09 -03:00
#define NGX_INVALID_INDEX 0x80000000
2003-05-19 12:39:14 -04:00
2003-02-06 14:21:13 -03:00
#if (HAVE_IOCP)
2003-06-06 10:59:20 -04:00
2003-02-06 14:21:13 -03:00
typedef struct {
WSAOVERLAPPED ovlp;
ngx_event_t *event;
int error;
} ngx_event_ovlp_t;
2003-06-06 10:59:20 -04:00
2003-02-06 14:21:13 -03:00
#endif
struct ngx_event_s {
void *data;
2003-05-13 12:02:32 -04:00
void (*event_handler)(ngx_event_t *ev);
2003-05-13 12:02:32 -04:00
#if 0
int (*close_handler)(ngx_event_t *ev);
2003-05-13 12:02:32 -04:00
#endif
void *context;
char *action;
2002-12-23 03:29:22 -03:00
unsigned int index;
2002-09-27 11:05:29 -04:00
2002-12-06 13:32:33 -03:00
ngx_event_t *prev; /* queue in mutex(), aio_read(), aio_write() */
ngx_event_t *next; /* */
2003-05-13 12:02:32 -04:00
#if 0
int (*timer_handler)(ngx_event_t *ev);
2003-05-13 12:02:32 -04:00
#endif
ngx_event_t *timer_prev;
ngx_event_t *timer_next;
2003-01-23 15:47:54 -03:00
ngx_msec_t timer_delta;
ngx_msec_t timer;
ngx_log_t *log;
int available; /* kqueue only: */
/* accept: number of sockets that wait */
/* to be accepted */
/* read: bytes to read */
/* write: available space in buffer */
/* otherwise: */
/* accept: 1 if accept many, 0 otherwise */
2002-09-02 10:48:24 -04:00
unsigned oneshot:1;
2002-12-06 13:32:33 -03:00
2003-02-06 14:21:13 -03:00
#if 0
unsigned listening:1;
2003-02-06 14:21:13 -03:00
#endif
unsigned write:1;
2003-05-12 11:52:24 -04:00
unsigned instance:1; /* used to detect stale events in kqueue,
rt signals and epoll */
2002-12-24 14:30:59 -03:00
unsigned active:1;
unsigned ready:1;
unsigned timedout:1;
2002-09-02 10:48:24 -04:00
unsigned blocked:1;
2003-01-26 18:08:14 -03:00
unsigned timer_set:1;
2003-04-17 13:59:35 -04:00
unsigned delayed:1;
2002-09-02 10:48:24 -04:00
unsigned process:1;
unsigned read_discarded:1;
2003-03-11 16:38:13 -04:00
unsigned ignore_econnreset:1;
unsigned unexpected_eof:1;
2002-08-26 11:18:19 -04:00
unsigned deferred_accept:1;
2003-02-06 14:21:13 -03:00
2003-06-06 10:59:20 -04:00
#if (WIN32)
unsigned accept_context_updated:1;
#endif
#if (HAVE_KQUEUE)
unsigned eof:1;
2002-08-15 13:20:26 -04:00
int error;
#endif
2003-01-26 18:08:14 -03:00
2003-03-04 03:33:48 -03:00
#if (HAVE_LOWAT_EVENT) /* kqueue's NOTE_LOWAT */
int lowat;
#endif
2003-02-06 14:21:13 -03:00
#if (HAVE_AIO)
#if (HAVE_IOCP)
ngx_event_ovlp_t ovlp;
#else
struct aiocb aiocb;
#endif
#endif
2003-01-26 18:08:14 -03:00
#if 0
void *thr_ctx; /* event thread context if $(CC) doesn't
understand __thread declaration
and pthread_getspecific() is too costly */
#if (NGX_EVENT_T_PADDING)
int padding[NGX_EVENT_T_PADDING]; /* event should not cross
cache line in SMP */
#endif
#endif
};
2003-05-12 11:52:24 -04:00
2003-05-20 11:37:55 -04:00
#if 1
typedef enum {
2003-02-11 04:14:40 -03:00
NGX_SELECT_EVENT_N = 0,
#if (HAVE_POLL)
2003-02-11 04:14:40 -03:00
NGX_POLL_EVENT_N,
#endif
2002-12-24 14:30:59 -03:00
#if (HAVE_DEVPOLL)
2003-02-11 04:14:40 -03:00
NGX_DEVPOLL_EVENT_N,
2002-12-24 14:30:59 -03:00
#endif
#if (HAVE_KQUEUE)
2003-02-11 04:14:40 -03:00
NGX_KQUEUE_EVENT_N,
#endif
2003-02-26 17:21:43 -03:00
#if (HAVE_AIO)
NGX_AIO_EVENT_N,
#endif
2003-02-06 14:21:13 -03:00
#if (HAVE_IOCP)
2003-02-11 04:14:40 -03:00
NGX_IOCP_EVENT_N,
2003-02-06 14:21:13 -03:00
#endif
2003-02-11 04:14:40 -03:00
NGX_DUMMY_EVENT_N /* avoid comma at end of enumerator list */
} ngx_event_type_e ;
2003-05-20 11:37:55 -04:00
#endif
2003-05-19 12:39:14 -04:00
typedef struct {
2003-05-19 12:39:14 -04:00
int (*add)(ngx_event_t *ev, int event, u_int flags);
int (*del)(ngx_event_t *ev, int event, u_int flags);
int (*enable)(ngx_event_t *ev, int event, u_int flags);
int (*disable)(ngx_event_t *ev, int event, u_int flags);
int (*add_conn)(ngx_connection_t *c);
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);
} ngx_event_actions_t;
2002-08-15 13:20:26 -04:00
2003-04-22 11:02:58 -04:00
/* The event filter requires to read/write the whole data -
2003-01-26 18:08:14 -03:00
select, poll, /dev/poll, kqueue. */
2003-05-20 11:37:55 -04:00
#define NGX_HAVE_LEVEL_EVENT 0x00000001
2003-01-30 04:28:09 -03:00
2003-04-22 11:02:58 -04:00
/* The event filter is deleted after a notification without an additional
syscall - select, poll, kqueue. */
2003-05-20 11:37:55 -04:00
#define NGX_HAVE_ONESHOT_EVENT 0x00000002
2003-01-30 04:28:09 -03:00
2003-04-22 11:02:58 -04:00
/* The event filter notifies only the changes and an initial level - kqueue */
2003-05-20 11:37:55 -04:00
#define NGX_HAVE_CLEAR_EVENT 0x00000004
2003-01-30 04:28:09 -03:00
2003-04-22 11:02:58 -04:00
/* The event filter has kqueue features - the eof flag, errno,
available data, etc */
2003-05-20 11:37:55 -04:00
#define NGX_HAVE_KQUEUE_EVENT 0x00000008
2003-02-11 04:14:40 -03:00
2003-04-22 11:02:58 -04:00
/* The event filter supports low water mark - kqueue's NOTE_LOWAT.
2003-05-13 12:02:32 -04:00
kqueue in FreeBSD 4.1-4.2 has no NOTE_LOWAT so we need a separate flag */
2003-03-11 16:38:13 -04:00
#define NGX_HAVE_LOWAT_EVENT 0x00000010
2003-03-04 03:33:48 -03:00
2003-04-22 11:02:58 -04:00
/* The event filter notifies only the changes (the edges)
but not an initial level - epoll */
2003-03-11 16:38:13 -04:00
#define NGX_HAVE_EDGE_EVENT 0x00000020
2003-02-11 04:14:40 -03:00
2003-04-22 11:02:58 -04:00
/* No need to add or delete the event filters - rt signals */
2003-03-11 16:38:13 -04:00
#define NGX_HAVE_SIGIO_EVENT 0x00000040
2003-01-30 04:28:09 -03:00
2003-04-22 11:02:58 -04:00
/* No need to add or delete the event filters - overlapped, aio_read, aioread */
2003-03-11 16:38:13 -04:00
#define NGX_HAVE_AIO_EVENT 0x00000080
2003-01-26 18:08:14 -03:00
2003-03-11 16:38:13 -04:00
/* Need to add socket or handle only once - i/o completion port.
It also requires HAVE_AIO_EVENT and NGX_HAVE_AIO_EVENT to be set */
#define NGX_HAVE_IOCP_EVENT 0x00000100
#define NGX_USE_LEVEL_EVENT 0x00010000
2003-04-14 13:04:58 -04:00
#define NGX_USE_AIO_EVENT 0x00020000
2003-03-04 03:33:48 -03:00
2003-02-06 14:21:13 -03:00
2003-03-20 12:09:44 -04:00
/* Event filter is deleted before closing file.
Has no meaning for select, poll, epoll.
2003-01-28 12:56:37 -03:00
2003-01-26 18:08:14 -03:00
kqueue: kqueue deletes event filters for file that closed
so we need only to delete filters in user-level batch array
2003-01-28 12:56:37 -03:00
/dev/poll: we need to flush POLLREMOVE event before closing file */
2003-05-20 11:37:55 -04:00
2003-01-26 18:08:14 -03:00
#define NGX_CLOSE_EVENT 1
2002-12-15 03:25:09 -03:00
#if (HAVE_KQUEUE)
#define NGX_READ_EVENT EVFILT_READ
#define NGX_WRITE_EVENT EVFILT_WRITE
2003-03-20 12:09:44 -04:00
/* NGX_CLOSE_EVENT is the module flag and it would not go into a kernel
so we need to choose the value that would not interfere with any existent
and future flags. kqueue has such values - EV_FLAG1, EV_EOF and EV_ERROR.
They are reserved and cleared on a kernel entrance */
#undef NGX_CLOSE_EVENT
#define NGX_CLOSE_EVENT EV_FLAG1
2002-08-26 11:18:19 -04:00
#define NGX_LEVEL_EVENT 0
#define NGX_ONESHOT_EVENT EV_ONESHOT
2003-03-20 12:09:44 -04:00
#define NGX_CLEAR_EVENT EV_CLEAR
2002-09-02 10:48:24 -04:00
#ifndef HAVE_CLEAR_EVENT
#define HAVE_CLEAR_EVENT 1
2002-09-07 06:14:25 -04:00
#endif
2002-12-24 14:30:59 -03:00
#elif (HAVE_POLL) || (HAVE_DEVPOLL)
2002-12-23 03:29:22 -03:00
#define NGX_READ_EVENT POLLIN
#define NGX_WRITE_EVENT POLLOUT
#define NGX_LEVEL_EVENT 0
#define NGX_ONESHOT_EVENT 1
#else
#define NGX_READ_EVENT 0
#define NGX_WRITE_EVENT 1
2002-08-26 11:18:19 -04:00
#define NGX_LEVEL_EVENT 0
#define NGX_ONESHOT_EVENT 1
2002-12-18 13:31:23 -03:00
#endif /* HAVE_KQUEUE */
2003-05-20 11:37:55 -04:00
#ifndef NGX_CLEAR_EVENT
#define NGX_CLEAR_EVENT 0 /* dummy */
#endif
#if (USE_KQUEUE)
2002-08-15 13:20:26 -04:00
#define ngx_init_events ngx_kqueue_init
#define ngx_process_events ngx_kqueue_process_events
2002-12-15 03:25:09 -03:00
#define ngx_add_event ngx_kqueue_add_event
2002-12-19 04:08:55 -03:00
#define ngx_del_event ngx_kqueue_del_event
2003-01-23 15:47:54 -03:00
#if 0
2002-09-02 10:48:24 -04:00
#define ngx_add_timer ngx_kqueue_add_timer
2003-01-23 15:47:54 -03:00
#else
#define ngx_add_timer ngx_event_add_timer
#endif
2002-08-15 13:20:26 -04:00
#define ngx_event_recv ngx_event_recv_core
#else
2002-08-15 13:20:26 -04:00
#define ngx_init_events (ngx_event_init[ngx_event_type])
#define ngx_process_events ngx_event_actions.process
#define ngx_add_event ngx_event_actions.add
#define ngx_del_event ngx_event_actions.del
2003-05-29 09:02:09 -04:00
#define ngx_add_conn ngx_event_actions.add_conn
2003-05-22 11:23:47 -04:00
#define ngx_del_conn ngx_event_actions.del_conn
2003-02-06 14:21:13 -03:00
2003-01-23 15:47:54 -03:00
#if 0
2003-02-06 14:21:13 -03:00
#if (HAVE_IOCP_EVENT)
#define ngx_event_recv ngx_event_wsarecv
#elif (HAVE_AIO_EVENT)
#define ngx_event_recv ngx_event_aio_read
#else
2003-05-19 12:39:14 -04:00
#define ngx_event_recv ngx_io.recv
#define ngx_write_chain ngx_io.send_chain
#endif
2003-06-11 11:28:34 -04:00
#endif
2002-12-24 04:09:57 -03:00
#endif
2003-06-06 10:59:20 -04:00
2003-06-11 11:28:34 -04:00
/* ***************************** */
#define ngx_recv ngx_io.recv
#define ngx_write_chain ngx_io.send_chain
#define ngx_add_timer ngx_event_add_timer
#define ngx_del_timer ngx_event_del_timer
2003-06-06 10:59:20 -04:00
#if (HAVE_IOCP_EVENT)
#define NGX_IOCP_ACCEPT 0
#define NGX_IOCP_IO 1
#endif
2003-06-11 11:28:34 -04:00
/* ***************************** */
2003-06-06 10:59:20 -04:00
2002-08-29 12:59:54 -04:00
extern ngx_event_t *ngx_read_events;
extern ngx_event_t *ngx_write_events;
extern ngx_connection_t *ngx_connections;
#if !(USE_KQUEUE)
extern ngx_event_actions_t ngx_event_actions;
extern ngx_event_type_e ngx_event_type;
2003-01-26 18:08:14 -03:00
extern int ngx_event_flags;
#endif
2003-04-22 11:02:58 -04:00
2003-06-11 11:28:34 -04:00
/* ***************************** */
2003-05-27 08:18:54 -04:00
#define NGX_EVENT_MODULE 0x544E5645 /* "EVNT" */
2003-05-16 11:27:48 -04:00
#define NGX_EVENT_CONF 0x00200000
2003-05-19 12:39:14 -04:00
typedef struct {
int connections;
int timer_queues;
2003-05-21 09:28:21 -04:00
int use;
2003-05-19 12:39:14 -04:00
} ngx_event_conf_t;
typedef struct {
ngx_str_t *name;
void *(*create_conf)(ngx_pool_t *p);
char *(*init_conf)(ngx_pool_t *p, void *conf);
ngx_event_actions_t actions;
} ngx_event_module_t;
extern ngx_module_t ngx_events_module;
2003-07-01 11:00:03 -04:00
extern ngx_module_t ngx_event_core_module;
2003-05-19 12:39:14 -04:00
#define ngx_event_get_conf(module) \
2003-05-27 08:18:54 -04:00
(*(ngx_get_conf(ngx_events_module))) [module.ctx_index];
2003-05-16 11:27:48 -04:00
2003-05-13 12:02:32 -04:00
void ngx_event_accept(ngx_event_t *ev);
2003-06-11 11:28:34 -04:00
#if (WIN32)
void ngx_event_acceptex(ngx_event_t *ev);
int ngx_event_post_acceptex(ngx_listening_t *ls, int n);
#endif
/* ***************************** */
2003-05-13 12:02:32 -04:00
2003-02-06 14:21:13 -03:00
ssize_t ngx_event_recv_core(ngx_connection_t *c, char *buf, size_t size);
int ngx_event_close_connection(ngx_event_t *ev);
2003-05-19 12:39:14 -04:00
int ngx_pre_thread(ngx_array_t *ls, ngx_pool_t *pool, ngx_log_t *log);
2003-07-02 10:41:17 -04:00
void ngx_worker(ngx_cycle_t *cycle);
2003-06-11 11:28:34 -04:00
/* ***************************** */
2003-05-19 12:39:14 -04:00
#include <ngx_event_timer.h>
2003-06-11 11:28:34 -04:00
#if (WIN32)
#include <ngx_iocp_module.h>
#endif
/* ***************************** */
2003-05-19 12:39:14 -04:00
#endif /* _NGX_EVENT_H_INCLUDED_ */