[zeromq-dev] How should sockets be destroyed?

Laurent Alebarde l.alebarde at free.fr
Mon Feb 24 18:04:31 CET 2014


By default, you are allowed 1024 sockets per context. After having 
created the context, you shall increase the quantity of sockets allowed:

         rc = zmq_ctx_set (ctx, ZMQ_MAX_SOCKETS, 10000);
         assert (rc == 0);


Le 24/02/2014 17:06, Olaf Mandel a écrit :
> 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
>
>
>
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20140224/1141ba62/attachment.htm>


More information about the zeromq-dev mailing list