jeromq icon indicating copy to clipboard operation
jeromq copied to clipboard

Improve ZSocket / "hidden context" API

Open daveyarwood opened this issue 8 years ago • 0 comments

The purpose of ZSocket is to allow users to create and use sockets without having to worry about managing their own contexts. ZSockets have a "hidden" ManagedContext, which are used to create the sockets internally.

One problem is that there is no public API allowing the user to shut down the managed context at will. The nice thing about ZContext is that when you destroy one, it automatically frees resources, e.g. closing all sockets created via that context. There is a shutdown hook that ensures that the ManagedContext is destroyed when SIGINT is received, which is great, but we should also give callers the ability to shut it down at will. I am imagining a hypothetical ZMQ.shutdown method which destroys the managed context, in the process closing any sockets, polling selectors, and any other resources that should be closed.

The overall goal here is that ManagedContext should behave exactly like ZContext (the current state of the art of ZMQ contexts in JeroMQ), but without needing to touch ZContext at all from calling code. Users should be able to use ZSockets and ZPollers directly and the context (along with all of its resources) should be managed appropriately in the background.

daveyarwood avatar Jan 19 '17 21:01 daveyarwood