+struct IODescriptor *iohandler_constant_timer(int msec, iohandler_callback *callback) {
+ struct IODescriptor *descriptor;
+ struct timeval timeout;
+ gettimeofday(&timeout, NULL);
+ timeout.tv_usec += (msec % 1000) * 1000;
+ timeout.tv_sec += (msec / 1000);
+ if(timeout.tv_usec > 1000000) {
+ timeout.tv_sec += (timeout.tv_usec / 1000000);
+ timeout.tv_usec %= 1000000;
+ }
+ descriptor = iohandler_add(-1, IOTYPE_TIMER, &timeout, callback);
+ if(!descriptor) {
+ iohandler_log(IOLOG_ERROR, "could not allocate memory for IODescriptor in %s:%d", __FILE__, __LINE__);
+ return NULL;
+ }
+ descriptor->constant_timeout = msec;
+ iohandler_log(IOLOG_DEBUG, "added timer descriptor (sec: %d; usec: %d)", timeout.tv_sec, timeout.tv_usec);
+ return descriptor;
+}
+