X-Git-Url: http://git.pk910.de/?p=NextIRCd.git;a=blobdiff_plain;f=src%2FIOHandler.c;h=07cd794e9be73afb33dba2eccb065369f4d5e5e1;hp=18e1b7f8e7e1bcbf93aef2b30b9e42637aa615c9;hb=6b235c4b3e0ff537bff312c5f18104e657b02883;hpb=57b28c464a3cd3eee7d91ddf9d9fc83fae1c58f6 diff --git a/src/IOHandler.c b/src/IOHandler.c index 18e1b7f..07cd794 100644 --- a/src/IOHandler.c +++ b/src/IOHandler.c @@ -73,20 +73,30 @@ extern struct IOEngine engine_kevent; extern struct IOEngine engine_epoll; extern struct IOEngine engine_win32; +int iohandler_settings = 0; struct IOEngine *engine = NULL; +void iohandler_set(int setting, int value) { + if(value) + iohandler_settings |= setting; + else + iohandler_settings &= ~setting; +} + static void iohandler_init_engine() { if(engine) return; IOTHREAD_MUTEX_INIT(io_thread_sync); IOTHREAD_MUTEX_INIT(io_poll_sync); //try other engines - if(!engine && engine_kevent.init && engine_kevent.init()) - engine = &engine_kevent; - if(!engine && engine_epoll.init && engine_epoll.init()) - engine = &engine_epoll; - if(!engine && engine_win32.init && engine_win32.init()) - engine = &engine_win32; + if(!(iohandler_settings & IOHANDLER_SETTING_HIGH_PRECISION_TIMER)) { + if(!engine && engine_kevent.init && engine_kevent.init()) + engine = &engine_kevent; + if(!engine && engine_epoll.init && engine_epoll.init()) + engine = &engine_epoll; + if(!engine && engine_win32.init && engine_win32.init()) + engine = &engine_win32; + } if (!engine) { if(engine_select.init()) @@ -185,8 +195,13 @@ struct IODescriptor *iohandler_add(int sockfd, enum IOType type, struct timeval descriptor->type = type; descriptor->state = (type == IOTYPE_STDIN ? IO_CONNECTED : IO_CLOSED); descriptor->callback = callback; - if(timeout) + if(timeout) { descriptor->timeout = *timeout; + if(descriptor->timeout.tv_usec > 1000000) { + descriptor->timeout.tv_usec -= 1000000; + descriptor->timeout.tv_sec++; + } + } if(type != IOTYPE_TIMER) { descriptor->readbuf.buffer = malloc(IO_READ_BUFLEN + 2); descriptor->readbuf.bufpos = 0; @@ -220,9 +235,13 @@ void iohandler_set_timeout(struct IODescriptor *descriptor, struct timeval *time descriptor->next->prev = descriptor->prev; if(descriptor == timer_priority) timer_priority = descriptor->next; - if(timeout) + if(timeout) { descriptor->timeout = *timeout; - else { + if(descriptor->timeout.tv_usec > 1000000) { + descriptor->timeout.tv_usec -= 1000000; + descriptor->timeout.tv_sec++; + } + } else { descriptor->timeout.tv_sec = 0; descriptor->timeout.tv_usec = 0; } @@ -648,14 +667,14 @@ void iohandler_events(struct IODescriptor *iofd, int readable, int writeable) { iohandler_ssl_connect(iofd); return; } - if(iofd->ssl && iofd->ssl_server_hs) - callback_event.type = IOEVENT_CONNECTED; - else { + if(iofd->ssl && iofd->ssl_server_hs) { callback_event.type = IOEVENT_SSLACCEPT; callback_event.iofd = iofd->data; callback_event.data.accept_iofd = iofd; iofd->data = NULL; } + else + callback_event.type = IOEVENT_CONNECTED; iofd->state = IO_CONNECTED; engine->update(iofd); } @@ -810,6 +829,8 @@ char *iohandler_ioeventtype_name(enum IOEventType type) { return "IOEVENT_CLOSED"; case IOEVENT_ACCEPT: return "IOEVENT_ACCEPT"; + case IOEVENT_SSLACCEPT: + return "IOEVENT_SSLACCEPT"; case IOEVENT_TIMEOUT: return "IOEVENT_TIMEOUT"; default: