X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=src%2FIOHandler%2FIOTimer.c;h=77648316a51718aa09eaabf4e9f3605a6550db92;hb=f40d2e60142d1cb141c46e63ed847b0d821ca920;hp=ec90d39304566da4e4abf31e6a6f742a40d63395;hpb=9e6045c7b6d7afc774eeb59fa5f5c4e02fe1f037;p=NextIRCd.git diff --git a/src/IOHandler/IOTimer.c b/src/IOHandler/IOTimer.c index ec90d39..7764831 100644 --- a/src/IOHandler/IOTimer.c +++ b/src/IOHandler/IOTimer.c @@ -32,10 +32,10 @@ struct _IOTimerDescriptor *iotimer_sorted_descriptors; struct IOTimerDescriptor *iotimer_create(struct timeval *timeout) { struct IOTimerDescriptor *descriptor = calloc(1, sizeof(*descriptor)); - if(!descriptor) { - iolog_trigger(IOLOG_ERROR, "could not allocate memory for IOTimerDescriptor in %s:%d", __FILE__, __LINE__); - return NULL; - } + if(!descriptor) { + iolog_trigger(IOLOG_ERROR, "could not allocate memory for IOTimerDescriptor in %s:%d", __FILE__, __LINE__); + return NULL; + } struct _IOTimerDescriptor *timer = _create_timer(timeout); if(!timer) { free(descriptor); @@ -80,6 +80,20 @@ void iotimer_set_autoreload(struct IOTimerDescriptor *descriptor, struct timeval } } +void iotimer_set_timeout(struct IOTimerDescriptor *descriptor, struct timeval *timeout) { + struct _IOTimerDescriptor *timer = descriptor->iotimer; + if(timer == NULL) { + iolog_trigger(IOLOG_WARNING, "called iotimer_set_timeout for destroyed IOTimerDescriptor in %s:%d", __FILE__, __LINE__); + return; + } + if(!timeout) { + iolog_trigger(IOLOG_WARNING, "called iotimer_set_timeout without timeout given in %s:%d", __FILE__, __LINE__); + return; + } + timer->timeout = *timeout; + _rearrange_timer(timer); +} + void iotimer_set_callback(struct IOTimerDescriptor *descriptor, iotimer_callback *callback) { descriptor->callback = callback; } @@ -103,10 +117,10 @@ void _init_timers() { struct _IOTimerDescriptor *_create_timer(struct timeval *timeout) { struct _IOTimerDescriptor *timer = calloc(1, sizeof(*timer)); - if(!timer) { - iolog_trigger(IOLOG_ERROR, "could not allocate memory for _IOTimerDescriptor in %s:%d", __FILE__, __LINE__); - return NULL; - } + if(!timer) { + iolog_trigger(IOLOG_ERROR, "could not allocate memory for _IOTimerDescriptor in %s:%d", __FILE__, __LINE__); + return NULL; + } if(timeout) { timer->timeout = *timeout; _rearrange_timer(timer);