[zeromq-dev] How should sockets be destroyed?

Diego Duclos diego.duclos at palmstonegames.com
Mon Feb 24 15:50:34 CET 2014


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.

Most importantly though: Why do you need to do this ? It seems like quite
the antipattern in ZMQ development ?


On Mon, Feb 24, 2014 at 1:13 PM, Laurent Alebarde <l.alebarde at free.fr>wrote:

>  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 listzeromq-dev at lists.zeromq.orghttp://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>
>
> _______________________________________________
> 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/ef54ee09/attachment.htm>


More information about the zeromq-dev mailing list