[zeromq-dev] How should sockets be destroyed?
Olaf Mandel
o.mandel at menlosystems.com
Mon Feb 24 17:06:47 CET 2014
Am 24.02.2014 15:50, schrieb Diego Duclos:
> You'd probably need to add two sleeps: 1 after creation to wait for the
> socket to be properly created. And another after the destruction to wait
> for the socket to be properly destroyed.
>
Hi Diego,
I now tried with this loop with two sleeps:
for(i=0; i<10000; ++i) {
socket = zmq_socket(context, ZMQ_REP);
Sleep(100);
rc = zmq_setsockopt(socket, ZMQ_LINGER, &l, sizeof(l));
rc = zmq_connect(socket, "inproc://demo");
rc = zmq_close(socket);
Sleep(100);
}
After some minutes this fails at the same point for the same reason:
zmq_socket() returns 0 for socket number 1023 with an errno of EMFILE.
BTW: I tried removing zmq_connect() and the sleep, so using a loop of
only zmq_socket(), zmq_close() and I no longer get the error.
Please note that I don't bind anything to the inproc address in this
example: the connection never gets established. The same pattern emerges
if I first bind a socket to the address and then run the
conenct-disconnect loop: abort after the number of sockets gets exhausted.
> Most importantly though: Why do you need to do this ? It seems like quite
> the antipattern in ZMQ development ?
>
-Snipp-
Actually: no. This is straight from the guide, "Lazy Pirate Pattern": if
there is an error that requires two sends on a REQ socket, close the old
socket and use a new socket. Just in the guide, they give up after a few
tries. My code didn't give up so eventually ran into this problem
(actually, for TCP I usually crash my PC). The loop is just in the test
case.
Best regards,
Olaf Mandel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20140224/70641782/attachment.sig>
More information about the zeromq-dev
mailing list