[nanomsg] Getting rid of nn_init() and nn_term()

  • From: Martin Sustrik <sustrik@xxxxxxxxxx>
  • To: nanomsg@xxxxxxxxxxxxx
  • Date: Mon, 04 Feb 2013 08:35:35 +0100

Hi all,

I would like to do yet one more API change before it's too late and API is cast in stone.

The idea is to remove nn_init() and nn_term() functions altogether. The library would be initialised when first socket is created and terminated when the last socket is closed.

Considerations:

First, nn_close() would have to be synchronous, ie. wait for the pending outbound data to be sent or for linger interval to expire. This is done in current codebase anyway (and it simplifies the code a lot), however, it's not consistent with how 0MQ behaves.

Second, ETERM functionality which is useful for shutting down multi-threaded applications would have to behave a bit differently. My proposal would be to re-purpose the nn_term() function to be an optional way of saying "make any subsequent call to nanomsg library, except for nn_close(), fail with ETERM). If it is not called, it's up to the user to notify all the threads about the shutdown. After all, if there's only one thread in the application, there's no need for such notification anyway.

Thoughts?

Martin

Other related posts: