On Thu, Jun 02, 2011 at 09:59:11PM -0500, Brandon Black <[email protected]>
wrote:
> It works, as long as you maintain the list in timer order, which is
> O(1) if all the timeout intervals are the same. When a connection
> enters its "connected" state where you want to start the idle timer,
> you simply add it to the tail of the list. When a connection ends,
> you remove it from the list. When a connection has an I/O event to
> reset the idle timer, you move it to the bottom of the list.
For an added speed up, if the timeout is likely to trigger much less often
than there is an activity, one can combine methods #2 and #4, i.e. leave the
timeout in the list and let it expire, but then just check whether there was
any activity "recently".
> The details can be tricky to implement and debug. IMHO as the docs
> state, it's only worth it if you have a *ton* of identical timeouts.
> It would be neat if someone wrote a generic implementation in C that
> worked with arbitrary user-defined connection datatypes while keeping
> list management pointers inside them.
It was one of the possible features for libev, some kind of
ev_timeoutgroup or so, but we decided back then that it is probably not
worth it, mainly because documenting that beast and teaching users when to
use it and when not was seen as being too hard.
--
The choice of a Deliantra, the free code+content MORPG
-----==- _GNU_ http://www.deliantra.net
----==-- _ generation
---==---(_)__ __ ____ __ Marc Lehmann
--==---/ / _ \/ // /\ \/ / [email protected]
-=====/_/_//_/\_,_/ /_/\_\
_______________________________________________
libev mailing list
[email protected]
http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev