static int timeout_compare(const timeout_t *a, const timeout_t *b) {
struct timeval diff;
timersub(&a->tv, &b->tv, &diff);
- return diff.tv_sec ?: diff.tv_usec ?: a < b ? -1 : a > b ? 1 : 0;
+ if(diff.tv_sec < 0)
+ return -1;
+ if(diff.tv_sec > 0)
+ return 1;
+ if(diff.tv_usec < 0)
+ return -1;
+ if(diff.tv_usec > 0)
+ return 1;
+ if(a < b)
+ return -1;
+ if(a > b)
+ return 1;
+ return 0;
}
static int signal_compare(const signal_t *a, const signal_t *b) {
io_set(io, flags);
- splay_insert_node(&io_tree, &io->node);
+ if(!splay_insert_node(&io_tree, &io->node))
+ abort();
}
void io_set(io_t *io, int flags) {
}
void timeout_add(timeout_t *timeout, timeout_cb_t cb, void *data, struct timeval *tv) {
- if(timeout->cb)
- return;
-
timeout->cb = cb;
timeout->data = data;
timeout->node.data = timeout;
}
void timeout_set(timeout_t *timeout, struct timeval *tv) {
- if(timeout->tv.tv_sec)
+ if(timerisset(&timeout->tv))
splay_unlink_node(&timeout_tree, &timeout->node);
if(!now.tv_sec)
timeradd(&now, tv, &timeout->tv);
- splay_insert_node(&timeout_tree, &timeout->node);
+ if(!splay_insert_node(&timeout_tree, &timeout->node))
+ abort();
}
void timeout_del(timeout_t *timeout) {
return;
splay_unlink_node(&timeout_tree, &timeout->node);
- timeout->cb = NULL;
+ timeout->cb = 0;
+ timeout->tv = (struct timeval){0, 0};
}
#ifndef HAVE_MINGW
signal(sig->signum, signal_handler);
- splay_insert_node(&signal_tree, &sig->node);
+ if(!splay_insert_node(&signal_tree, &sig->node))
+ abort();
}
void signal_del(signal_t *sig) {