[zeromq-dev] XREP/XREQ And Inproc . Clean Shutdown

john skaller skaller at users.sourceforge.net
Thu Mar 1 16:51:05 CET 2012

On 01/03/2012, at 9:51 PM, Ian Barber wrote:

> Yep, if LINGER is set to -1 (the default) the system wont  terminate until messages are cleared. 

I'm curious to know how 0MQ shuts down a TCP socket internally.
As far as I can make out there's no reliable and performant way to do it.

Performant means: no API calls may block. A fixed number of threads
have to handle a large number of connections/ connection requests.
[Spawning a thread per connection is not performant because threads
are too resource hungry]

Non-blocking calls are efficient, and allow monitoring for rogues.

There's no way to close a non-blocking socket reliably.
SO_LINGER doesn't work on non-blocking sockets.

A server must actually shutdown the reader, loop or poll for a read
of EOF, then close the socket. Reading EOF on a shutdown receiver
appears to be the only way to ensure delivery of transmitted data.
The timeout in the polling or wait loop prevents  rogue clients from
choking the server with open sockets.

john skaller
skaller at users.sourceforge.net

More information about the zeromq-dev mailing list