Annotation of embedaddon/lighttpd/src/fdevent.h, revision 1.1.1.3

1.1       misho       1: #ifndef _FDEVENT_H_
                      2: #define _FDEVENT_H_
1.1.1.3 ! misho       3: #include "first.h"
1.1       misho       4: 
                      5: #include "settings.h"
                      6: 
                      7: #if defined HAVE_STDINT_H
                      8: # include <stdint.h>
                      9: #elif defined HAVE_INTTYPES_H
                     10: # include <inttypes.h>
                     11: #endif
                     12: 
                     13: #include <sys/types.h>
                     14: 
                     15: /* select event-system */
                     16: 
                     17: #if defined(HAVE_EPOLL_CTL) && defined(HAVE_SYS_EPOLL_H)
                     18: # define USE_LINUX_EPOLL
1.1.1.3 ! misho      19: struct epoll_event;     /* declaration */
1.1       misho      20: #endif
                     21: 
                     22: /* MacOS 10.3.x has poll.h under /usr/include/, all other unixes
                     23:  * under /usr/include/sys/ */
                     24: #if defined HAVE_POLL && (defined(HAVE_SYS_POLL_H) || defined(HAVE_POLL_H))
                     25: # define USE_POLL
1.1.1.3 ! misho      26: struct pollfd;          /* declaration */
1.1       misho      27: #endif
                     28: 
                     29: #if defined HAVE_SELECT
                     30: # ifdef __WIN32
                     31: #  include <winsock2.h>
                     32: # endif
                     33: # define USE_SELECT
                     34: # ifdef HAVE_SYS_SELECT_H
                     35: #  include <sys/select.h>
                     36: # endif
                     37: #endif
                     38: 
                     39: #if defined HAVE_SYS_DEVPOLL_H && defined(__sun)
                     40: # define USE_SOLARIS_DEVPOLL
1.1.1.3 ! misho      41: struct pollfd;          /* declaration */
1.1       misho      42: #endif
                     43: 
                     44: #if defined HAVE_PORT_H && defined HAVE_PORT_CREATE && defined(__sun)
                     45: # define USE_SOLARIS_PORT
                     46: # include <port.h>
                     47: #endif
                     48: 
                     49: #if defined HAVE_SYS_EVENT_H && defined HAVE_KQUEUE
                     50: # define USE_FREEBSD_KQUEUE
1.1.1.3 ! misho      51: struct kevent;          /* declaration */
1.1       misho      52: #endif
                     53: 
                     54: #if defined HAVE_LIBEV
                     55: # define USE_LIBEV
1.1.1.3 ! misho      56: struct ev_loop;         /* declaration */
1.1       misho      57: #endif
                     58: 
1.1.1.3 ! misho      59: struct server;          /* declaration */
1.1       misho      60: 
                     61: typedef handler_t (*fdevent_handler)(struct server *srv, void *ctx, int revents);
                     62: 
                     63: /* these are the POLL* values from <bits/poll.h> (linux poll)
                     64:  */
                     65: 
                     66: #define FDEVENT_IN     BV(0)
                     67: #define FDEVENT_PRI    BV(1)
                     68: #define FDEVENT_OUT    BV(2)
                     69: #define FDEVENT_ERR    BV(3)
                     70: #define FDEVENT_HUP    BV(4)
                     71: #define FDEVENT_NVAL   BV(5)
                     72: 
1.1.1.3 ! misho      73: #define FDEVENT_STREAM_REQUEST          BV(0)
        !            74: #define FDEVENT_STREAM_REQUEST_BUFMIN   BV(1)
        !            75: #define FDEVENT_STREAM_REQUEST_POLLIN   BV(15)
        !            76: 
        !            77: #define FDEVENT_STREAM_RESPONSE         BV(0)
        !            78: #define FDEVENT_STREAM_RESPONSE_BUFMIN  BV(1)
        !            79: 
1.1       misho      80: typedef enum { FD_EVENT_TYPE_UNSET = -1,
                     81:                FD_EVENT_TYPE_CONNECTION,
                     82:                FD_EVENT_TYPE_FCGI_CONNECTION,
                     83:                FD_EVENT_TYPE_DIRWATCH,
                     84:                FD_EVENT_TYPE_CGI_CONNECTION
                     85: } fd_event_t;
                     86: 
                     87: typedef enum { FDEVENT_HANDLER_UNSET,
                     88:                FDEVENT_HANDLER_SELECT,
                     89:                FDEVENT_HANDLER_POLL,
                     90:                FDEVENT_HANDLER_LINUX_SYSEPOLL,
                     91:                FDEVENT_HANDLER_SOLARIS_DEVPOLL,
                     92:                FDEVENT_HANDLER_SOLARIS_PORT,
                     93:                FDEVENT_HANDLER_FREEBSD_KQUEUE,
                     94:                FDEVENT_HANDLER_LIBEV
                     95: } fdevent_handler_t;
                     96: 
                     97: 
                     98: typedef struct _fdnode {
                     99:        fdevent_handler handler;
                    100:        void *ctx;
                    101:        void *handler_ctx;
                    102:        int fd;
                    103:        int events;
                    104: } fdnode;
                    105: 
                    106: /**
                    107:  * array of unused fd's
                    108:  *
                    109:  */
                    110: 
                    111: typedef struct {
                    112:        int *ptr;
                    113: 
                    114:        size_t used;
                    115:        size_t size;
                    116: } buffer_int;
                    117: 
                    118: /**
                    119:  * fd-event handler for select(), poll() and rt-signals on Linux 2.4
                    120:  *
                    121:  */
                    122: typedef struct fdevents {
                    123:        struct server *srv;
                    124:        fdevent_handler_t type;
                    125: 
                    126:        fdnode **fdarray;
                    127:        size_t maxfds;
                    128: 
                    129: #ifdef USE_LINUX_EPOLL
                    130:        int epoll_fd;
                    131:        struct epoll_event *epoll_events;
                    132: #endif
                    133: #ifdef USE_POLL
                    134:        struct pollfd *pollfds;
                    135: 
                    136:        size_t size;
                    137:        size_t used;
                    138: 
                    139:        buffer_int unused;
                    140: #endif
                    141: #ifdef USE_SELECT
                    142:        fd_set select_read;
                    143:        fd_set select_write;
                    144:        fd_set select_error;
                    145: 
                    146:        fd_set select_set_read;
                    147:        fd_set select_set_write;
                    148:        fd_set select_set_error;
                    149: 
                    150:        int select_max_fd;
                    151: #endif
                    152: #ifdef USE_SOLARIS_DEVPOLL
                    153:        int devpoll_fd;
                    154:        struct pollfd *devpollfds;
                    155: #endif
                    156: #ifdef USE_SOLARIS_PORT
                    157:        port_event_t *port_events;
                    158: #endif
                    159: #ifdef USE_FREEBSD_KQUEUE
                    160:        int kq_fd;
                    161:        struct kevent *kq_results;
                    162: #endif
                    163: #ifdef USE_SOLARIS_PORT
                    164:        int port_fd;
                    165: #endif
                    166: #ifdef USE_LIBEV
                    167:        struct ev_loop *libev_loop;
                    168: #endif
                    169:        int (*reset)(struct fdevents *ev);
                    170:        void (*free)(struct fdevents *ev);
                    171: 
                    172:        int (*event_set)(struct fdevents *ev, int fde_ndx, int fd, int events);
                    173:        int (*event_del)(struct fdevents *ev, int fde_ndx, int fd);
                    174:        int (*event_get_revent)(struct fdevents *ev, size_t ndx);
                    175:        int (*event_get_fd)(struct fdevents *ev, size_t ndx);
                    176: 
                    177:        int (*event_next_fdndx)(struct fdevents *ev, int ndx);
                    178: 
                    179:        int (*poll)(struct fdevents *ev, int timeout_ms);
                    180: 
                    181:        int (*fcntl_set)(struct fdevents *ev, int fd);
                    182: } fdevents;
                    183: 
                    184: fdevents *fdevent_init(struct server *srv, size_t maxfds, fdevent_handler_t type);
                    185: int fdevent_reset(fdevents *ev); /* "init" after fork() */
                    186: void fdevent_free(fdevents *ev);
                    187: 
1.1.1.3 ! misho     188: #define fdevent_event_get_interest(ev, fd) \
        !           189:         ((fd) >= 0 ? (ev)->fdarray[(fd)]->events : 0)
        !           190: void fdevent_event_set(fdevents *ev, int *fde_ndx, int fd, int events); /* events can be FDEVENT_IN, FDEVENT_OUT or FDEVENT_IN | FDEVENT_OUT */
        !           191: void fdevent_event_add(fdevents *ev, int *fde_ndx, int fd, int event); /* events can be FDEVENT_IN or FDEVENT_OUT */
        !           192: void fdevent_event_clr(fdevents *ev, int *fde_ndx, int fd, int event); /* events can be FDEVENT_IN or FDEVENT_OUT */
        !           193: void fdevent_event_del(fdevents *ev, int *fde_ndx, int fd);
1.1       misho     194: int fdevent_event_get_revent(fdevents *ev, size_t ndx);
                    195: int fdevent_event_get_fd(fdevents *ev, size_t ndx);
                    196: fdevent_handler fdevent_get_handler(fdevents *ev, int fd);
                    197: void * fdevent_get_context(fdevents *ev, int fd);
                    198: 
                    199: int fdevent_event_next_fdndx(fdevents *ev, int ndx);
                    200: 
                    201: int fdevent_poll(fdevents *ev, int timeout_ms);
                    202: 
                    203: int fdevent_register(fdevents *ev, int fd, fdevent_handler handler, void *ctx);
                    204: int fdevent_unregister(fdevents *ev, int fd);
                    205: 
1.1.1.2   misho     206: void fd_close_on_exec(int fd);
1.1       misho     207: int fdevent_fcntl_set(fdevents *ev, int fd);
                    208: 
                    209: int fdevent_select_init(fdevents *ev);
                    210: int fdevent_poll_init(fdevents *ev);
                    211: int fdevent_linux_sysepoll_init(fdevents *ev);
                    212: int fdevent_solaris_devpoll_init(fdevents *ev);
                    213: int fdevent_solaris_port_init(fdevents *ev);
                    214: int fdevent_freebsd_kqueue_init(fdevents *ev);
                    215: int fdevent_libev_init(fdevents *ev);
                    216: 
                    217: #endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>