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


Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
zeromq-dev mailing list
[email protected]
http://lists.zeromq.org/mailman/listinfo/zeromq-dev

Reply via email to