asynchronous cancellation of timer event added via g_timeout_add()



 
i am a newbie to glib, but have started using glib heavily in my latest manet networking project to implement reliable packet transfer over intermittent links.
 
one of the issues i have run into with glib timer events is that there does not seem to be asynchronous event cancellation support. that is, i would like to be able to cancel a running timer following the reception of an event on a file descriptor (in my concrete example, the arrival of an ack packet will make a udp socket fd readable, following which i would want to free associated memory and cancel the timer whose callback function operates on the data to be freed). currently, i work around the lacking async timer cancellation feature by not freeing the memory upon the udp socket fd becoming readable, letting the timer run to its completion, then checking for a flag within the timer's callback function to see if the memory can be freed, and if so, return FALSE from the callback function to cancel the timer.
 
here is my problem with synchronous cancellation: the way the transfer service over intermittent links works is that it needs to create a timer for each packet to be transferred (the code in theh timer callback is designed to check whether the packet needs to be retransmitted in case no ack packet has been received). under heavy load, the number of timers added via g_timeout_add() grows very quickly, and i even see some strange behavior where timer callbacks are occasionally called after the associated timer has been cancelled via return FALSE).
 
now, to circumvent the duplicate timer callback issue, and also simplify my own code in order to avoid having to wait for a timer (or a set of timers as in my case) to expire before i can free a block of memory, i would prefer a way for me to cancel timers asynchronously (i.e. before they expire).
 
my question hence is: is there a glib API call that i may have missed/is undocumented, or is there some other way of creating timers in glib that can be cancelled asynchronously?
 
thanks!
Josef


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]