[zeromq-dev] How should sockets be destroyed?

Laurent Alebarde l.alebarde at free.fr
Mon Feb 24 13:13:13 CET 2014


Sorry, I didn't see you was closing the socket. Anyway, Diego's remark 
looks right. So either add a sleep in your loop to enable the lib to 
free the socket, either use an array.

Le 24/02/2014 12:12, Olaf Mandel a écrit :
> Am 24.02.2014 11:43, schrieb Laurent Alebarde:
>> Where is your socket variable declaration ?
> -Snipp-
>> Le 24/02/2014 11:32, Olaf Mandel a écrit :
> -Snipp-
>>> int const l = 0;
>>> int i;
>>> for(i=0; i<10000; ++i) {
>>>       socket = zmq_socket(context, ZMQ_REP);
>>>       rc = zmq_setsockopt(socket, ZMQ_LINGER, &l, sizeof(l)); /* #1 */
>>>       rc = zmq_connect(socket, "inproc://demo");
>>>       rc = zmq_close(socket);
>>> }
>>>
> -Snipp-
>
> Hello Laurent,
>
> the socket is declared outside of the loop. Here is the full code, again
> without assertions and debug output:
>
> #include <zmq.h>
>
> int main(void)
> {
>      int const l = 0;
>
>      void* context;
>      void* socket;
>      int   rc;
>      int   i;
>
>      context = zmq_ctx_new();
>      for(i=0; i<10000; ++i) {
>          socket = zmq_socket(context, ZMQ_REP);
>          rc = zmq_setsockopt(socket, ZMQ_LINGER, &l, sizeof(l));
>          rc = zmq_connect(socket, "inproc://demo");
>          rc = zmq_close(socket);
>      }
>
>      rc = zmq_ctx_destroy(context);
>      return 0;
> }
>
>
>> You shall use one variable per socket, so, use an array.
> After the zmq_close() call, I was expecting it to be ok to reuse the
> socket variable, same like you may reuse a pointer-variable after
> deleting the original contents. And if there really is a need to keep a
> reference to the socket after the zmq_close() call, that would actually
> be my original question: how to properly close a socket to that it is
> really closed?
>
> 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/9d47d38c/attachment.htm>


More information about the zeromq-dev mailing list