nginx-quic/src/event/ngx_event.h

244 lines
6.4 KiB
C
Raw Normal View History

#ifndef _NGX_EVENT_H_INCLUDED_
#define _NGX_EVENT_H_INCLUDED_
#include <ngx_config.h>
#include <ngx_types.h>
2002-09-02 10:48:24 -04:00
#include <ngx_time.h>
2002-08-20 10:48:28 -04:00
#include <ngx_socket.h>
#include <ngx_log.h>
2002-08-20 10:48:28 -04:00
#include <ngx_alloc.h>
#include <ngx_array.h>
2003-01-23 15:47:54 -03:00
2002-12-15 03:25:09 -03:00
#define NGX_INVALID_INDEX 0x80000000
typedef struct ngx_event_s ngx_event_t;
struct ngx_event_s {
void *data;
int (*event_handler)(ngx_event_t *ev);
int (*close_handler)(ngx_event_t *ev);
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; /* */
int (*timer_handler)(ngx_event_t *ev);
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 */
/* flags - int are probably faster on write then bits ??? */
2002-12-06 13:32:33 -03:00
2002-09-02 10:48:24 -04:00
unsigned oneshot:1;
2002-12-06 13:32:33 -03:00
unsigned listening:1;
unsigned write:1;
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;
2002-09-02 10:48:24 -04:00
unsigned process:1;
unsigned read_discarded:1;
unsigned unexpected_eof:1;
#if (HAVE_DEFERRED_ACCEPT)
2002-08-26 11:18:19 -04:00
unsigned deferred_accept: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
#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
};
typedef enum {
NGX_SELECT_EVENT = 0,
#if (HAVE_POLL)
NGX_POLL_EVENT,
#endif
2002-12-24 14:30:59 -03:00
#if (HAVE_DEVPOLL)
NGX_DEVPOLL_EVENT,
#endif
#if (HAVE_KQUEUE)
NGX_KQUEUE_EVENT,
#endif
} ngx_event_type_e ;
typedef struct {
int (*add)(ngx_event_t *ev, int event, u_int flags);
2002-12-15 03:25:09 -03:00
int (*del)(ngx_event_t *ev, int event, u_int flags);
2002-09-02 10:48:24 -04:00
void (*timer)(ngx_event_t *ev, ngx_msec_t timer);
int (*process)(ngx_log_t *log);
int (*read)(ngx_event_t *ev, char *buf, size_t size);
2002-08-15 13:20:26 -04:00
/*
int (*write)(ngx_event_t *ev, char *buf, size_t size);
*/
} ngx_event_actions_t;
2002-08-15 13:20:26 -04:00
2003-01-26 18:08:14 -03:00
/* Event filter requires to read/write the whole data -
select, poll, /dev/poll, kqueue. */
#define NGX_HAVE_LEVEL_EVENT 1
2003-01-30 04:28:09 -03:00
/* Event filter is deleted after notification - select, poll, kqueue.
Using /dev/poll, epoll it can be implemented with additional syscall */
2003-01-26 18:08:14 -03:00
#define NGX_HAVE_ONESHOT_EVENT 2
2003-01-30 04:28:09 -03:00
/* Event filter notifies only changes and initial level - kqueue */
2003-01-26 18:08:14 -03:00
#define NGX_HAVE_CLEAR_EVENT 4
2003-01-30 04:28:09 -03:00
/* Event filter notifies only changes (edgesi) but not initial level - epoll */
#define NGX_HAVE_EDGE_EVENT 8
/* No need to add or delete event filters - overlapped, aio_read, aioread */
#define NGX_HAVE_AIO_EVENT 16
2003-01-26 18:08:14 -03:00
2003-01-28 12:56:37 -03:00
/* Event filter is deleted before closing file. Has no meaning
for select, poll, epoll.
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-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
2002-08-26 11:18:19 -04:00
#define NGX_LEVEL_EVENT 0
#define NGX_ONESHOT_EVENT EV_ONESHOT
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
#if (HAVE_CLEAR_EVENT)
#define NGX_CLEAR_EVENT EV_CLEAR
2002-09-02 10:48:24 -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 */
#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-01-23 15:47:54 -03:00
#if 0
2002-09-02 10:48:24 -04:00
#define ngx_add_timer ngx_event_actions.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
#endif
2003-01-23 15:47:54 -03:00
#define ngx_del_timer ngx_event_del_timer
2003-01-23 15:47:54 -03:00
#if 0
2002-12-24 14:30:59 -03:00
ngx_inline static void ngx_del_timer(ngx_event_t *ev)
2002-08-29 12:59:54 -04:00
{
2002-12-24 14:30:59 -03:00
#if (NGX_DEBUG_EVENT)
/* STUB - we can not cast (ngx_connection_t *) here */
2002-12-24 04:09:57 -03:00
ngx_log_debug(ev->log, "del timer: %d" _ *(int *)(ev->data));
#endif
if (ev->timer_prev) {
2002-08-29 12:59:54 -04:00
ev->timer_prev->timer_next = ev->timer_next;
2002-12-24 04:09:57 -03:00
}
2002-08-29 12:59:54 -04:00
if (ev->timer_next) {
2002-12-24 04:09:57 -03:00
ev->timer_next->timer_delta += ev->timer_delta;
2002-08-29 12:59:54 -04:00
ev->timer_next->timer_prev = ev->timer_prev;
ev->timer_next = NULL;
}
2002-12-24 04:09:57 -03:00
if (ev->timer_prev) {
2002-08-29 12:59:54 -04:00
ev->timer_prev = NULL;
2002-12-24 04:09:57 -03:00
}
2002-08-29 12:59:54 -04:00
}
2003-01-23 15:47:54 -03:00
#endif
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
2002-08-20 10:48:28 -04:00
void ngx_pre_thread(ngx_array_t *ls, ngx_pool_t *pool, ngx_log_t *log);
void ngx_worker(ngx_log_t *log);
#endif /* _NGX_EVENT_H_INCLUDED_ */