+ if (!engine) {
+ if(engine_select.init())
+ engine = &engine_select;
+ else {
+ iohandler_log(IOLOG_FATAL, "found no useable IO engine");
+ return;
+ }
+ }
+ iohandler_log(IOLOG_DEBUG, "using %s IO engine", engine->name);
+}
+
+static void iohandler_append(struct IODescriptor *descriptor) {
+ struct timeval *timeout = ((descriptor->timeout.tv_sec || descriptor->timeout.tv_usec) ? &descriptor->timeout : NULL);
+ if(timeout) {
+ struct IODescriptor *iofd;
+ int set_priority = 1;
+ descriptor->timeout = *timeout;
+ if(timer_priority)
+ iofd = timer_priority;
+ else
+ iofd = first_descriptor;
+ if(iofd) {
+ for(;;iofd = iofd->next) {
+ if(timeval_is_smaler(timeout, (&iofd->timeout))) {
+ descriptor->prev = iofd->prev;
+ descriptor->next = iofd;
+ iofd->prev = descriptor;
+ if(iofd->prev)
+ iofd->prev->next = descriptor;
+ if(set_priority)
+ timer_priority = descriptor;
+ break;
+ }
+ if(iofd == timer_priority)
+ set_priority = 0;
+ if(iofd->next == NULL) {
+ descriptor->next = NULL;
+ descriptor->prev = iofd;
+ iofd->next = descriptor;
+ if(set_priority)
+ timer_priority = descriptor;
+ break;
+ }
+ }
+ } else {
+ descriptor->prev = NULL;
+ descriptor->next = NULL;
+ first_descriptor = descriptor;
+ timer_priority = descriptor;
+ }
+
+ } else {
+ descriptor->prev = NULL;
+ descriptor->next = first_descriptor;
+ if(first_descriptor)
+ first_descriptor->prev = descriptor;
+ first_descriptor = descriptor;