X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=src%2FIOEngine.h;h=4e43a6af05d51da17aa069d0886f29fe1925f397;hb=e18ef9b450a0704ff5c55545f70e3f1ec215a5e6;hp=e331ce8457323a1f6957299ef2221f70d3ffb851;hpb=59659c9123e0b56c34f5fa9281566f574365deb5;p=IOMultiplexer.git diff --git a/src/IOEngine.h b/src/IOEngine.h index e331ce8..4e43a6a 100644 --- a/src/IOEngine.h +++ b/src/IOEngine.h @@ -18,23 +18,74 @@ #define _IOEngine_h #include "IOHandler.h" -struct IODescriptor; -enum IOType; -enum IOStatus; -enum IOEventType; +#ifdef HAVE_PTHREAD_H +#include +#ifdef PTHREAD_MUTEX_RECURSIVE_NP +#define PTHREAD_MUTEX_RECURSIVE_VAL PTHREAD_MUTEX_RECURSIVE_NP +#else +#define PTHREAD_MUTEX_RECURSIVE_VAL PTHREAD_MUTEX_RECURSIVE +#endif +#define IOTHREAD_MUTEX_INIT(var) { \ + pthread_mutexattr_t mutex_attr; \ + pthread_mutexattr_init(&mutex_attr);\ + pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE_VAL);\ + pthread_mutex_init(&var, &mutex_attr); \ +} +#define IOSYNCHRONIZE(var) pthread_mutex_lock(&var) +#define IODESYNCHRONIZE(var) pthread_mutex_unlock(&var) +#else +#define IOTHREAD_MUTEX_INIT(var) +#define IOSYNCHRONIZE(var) +#define IODESYNCHRONIZE(var) +#endif #define timeval_is_bigger(x,y) ((x->tv_sec > y->tv_sec) || (x->tv_sec == y->tv_sec && x->tv_usec > y->tv_usec)) #define timeval_is_smaler(x,y) ((x->tv_sec < y->tv_sec) || (x->tv_sec == y->tv_sec && x->tv_usec < y->tv_usec)) -extern struct IODescriptor *first_descriptor; -extern struct IODescriptor *timer_priority; + +struct IODescriptor; +struct IOLowlevelDescriptor; + +extern struct IOLowlevelDescriptor *first_descriptor; +extern struct IOLowlevelDescriptor *timer_priority; +extern struct IOLowlevelDescriptor *lowlevel_descriptor; + +#define IOLOWLEVEL_CALLBACK(NAME) void NAME(struct IOLowlevelDescriptor *iold, int can_read) +typedef IOLOWLEVEL_CALLBACK(iolowlevel_callback); + +#define IOFLAGS_WANT_READ 0x01 +#define IOFLAGS_WANT_WRITE 0x02 +#define IOFLAGS_HAVE_IOFD 0x04 +#define IOFLAGS_HAVE_TIMEOUT 0x08 + +#define IOFDFLAGS_HAVE_IOLD 0x01 +#define IOFDFLAGS_FREE_LOCK 0x02 +#define IOFDFLAGS_WANT_FREE 0x04 +#define IOFDFLAGS_SSL_ACTIVE 0x08 +#define IOFDFLAGS_SSL_SERVER_HS 0x10 +#define IOFDFLAGS_SSL_HS_READ 0x20 +#define IOFDFLAGS_SSL_HS_WRITE 0x40 + +struct IOLowlevelDescriptor { + int fd; + unsigned int flags; + struct timeval timeout; + union { + struct IODescriptor *iofd; + iolowlevel_callback *callback; + } data; + struct IOLowlevelDescriptor *next, *prev; +}; + +#define IOLOWLEVEL_GET_IOFD(iold) ((iold->flags & IOFLAGS_HAVE_IOFD) ? iold->data.iofd : NULL) +#define IODESCRIPTOR_GET_IOLD(iofd) ((iofd->flags & IOFDFLAGS_HAVE_IOLD) ? iofd->fd.iold : NULL) struct IOEngine { const char *name; int (*init)(void); - void (*add)(struct IODescriptor *iofd); - void (*remove)(struct IODescriptor *iofd); - void (*update)(struct IODescriptor *iofd); + void (*add)(struct IOLowlevelDescriptor *iofd); + void (*remove)(struct IOLowlevelDescriptor *iofd); + void (*update)(struct IOLowlevelDescriptor *iofd); void (*loop)(struct timeval *timeout); void (*cleanup)(void); }; @@ -47,4 +98,8 @@ char *iohandler_iotype_name(enum IOType type); char *iohandler_iostatus_name(enum IOStatus status); char *iohandler_ioeventtype_name(enum IOEventType type); +struct IOLowlevelDescriptor *iohandler_lowlevel_add(int fd, int want_read, int want_write, iolowlevel_callback *callback); +void iohandler_lowlevel_update(struct IOLowlevelDescriptor *iolow, int want_read, int want_write); +void iohandler_lowlevel_del(struct IOLowlevelDescriptor *iolow); + #endif