On 07/16/2015 09:18 PM, Dmitri Toubelis wrote: > I use libuv for a small communication component that maintains set of > persistent HTTPS connection between several nodes (mesh network). It > works fine, however when I'm shutting down the component down I want to > do a graceful connection shutdown for each connection. The way I > implemented now is that I have a hash table of all connections and then > iterate through the table and shut down every connection. This works > alright as well, however it is real pain to troubleshoot this mix of > asynchronous and functional code. What I was thinking is to have some > sort of mechanism for custom events that for every connection I could > register a listener that would be waiting for a specific event and then > call a callback function. Then I could emit this event on the loop and > each connection would shutdown itself. The Idea is that I do not have to > maintain list of external references to each connection but they still > can be reached trough the event loop. So, my question is if there is a > sensible way to do it with libuv or if I should involve any other > library? Thanks. >
There is no support for this in libuv, and with the details you gave I'm afraid it's probably quite application specific. There is however a way to get hold of all handles in a loop: uv_walk: http://docs.libuv.org/en/v1.x/loop.html?highlight=uv_walk#c.uv_walk That way you can iterate through all the handles and do something with them, but you'll still need to keep some state for them, if you need to remember stuff. You could use the data pointer for that: http://docs.libuv.org/en/v1.x/handle.html#c.uv_handle_t.data Regards, -- Saúl Ibarra Corretgé bettercallsaghul.com -- You received this message because you are subscribed to the Google Groups "libuv" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/libuv. For more options, visit https://groups.google.com/d/optout.
signature.asc
Description: OpenPGP digital signature
