In order to add timed tasks, such as keepalives to maintain connections with peers, I thought I might add timeouts; XPCOM provides nsITimer, and through nsIAppShellService access to the well known setInterval/setTimeout functions via the hidden DOM window.
However, I disliked the idea of running 30 or so timeouts for each torrent, instead I thought I'd re-use the existing event queue by introducing a new method called 'addDelayedEvent(event, delay)' which adds events to an ordered-by-event-time queue. The idea being, at each step this queue is checked, and any items at the front of the queue that should have fired will be added to the normal event queue.
So, now we handle timed events not by many extra timeouts, but by adding to a new ordered queue which feeds into the normal event queue. Somewhat satisfying.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment