[zeromq-dev] Disconnect appears not to respect linger

Ben Gray ben at benjamg.com
Mon Jul 8 09:22:03 CEST 2013


On 7 July 2013 20:03, Martin Hurton <hurtonm at gmail.com> wrote:

> Hi Ben, I wonder if unbind should close any connections at all. The
> man page says it just closes the listener, not connections accepted by
> that listener.
> I think disconnect should respect the linger value.
>
>
That would actually make a lot of sense, in which case the linger aspect
for that can be ignored.

For disconnects it would make sense to detach the pipe in a way that stops
new messages being added but keeps existing data around for at least the
linger period.
The bug raised differs from my test results. I assume you can still receive
the data there because it was already handed over.

In my tests I disconnected before binding the remote end and compared that
to just closing the socket. The data from the closed socket was received as
expected but not the data from the disconnected one.

It's actually quiet hard to make a test with pre-connected sockets unless
you push enough data to hit the high water marks.

---- Test code I used

#include <cstdlib>
#include <cstring>
#include <iostream>

#include <zmq.h>

int main (void)
{
    void *context = zmq_ctx_new();

    void *from1 = zmq_socket( context, ZMQ_PUSH) ;
    zmq_connect( from1, "tcp://localhost:5555" );

    void *from2 = zmq_socket( context, ZMQ_PUSH );
    zmq_connect( from2, "tcp://localhost:5556" );

    std::string message( "hello world" );
    zmq_send( from1, message.data(), message.size(), 0);
    zmq_send( from2, message.data(), message.size(), 0);

    zmq_disconnect( from2, "tcp://localhost:5556" );

    zmq_close(from1);
    zmq_close(from2);

    void *to1 = zmq_socket( context, ZMQ_PULL );
    zmq_bind( to1, "tcp://*:5555" );

    void *to2 = zmq_socket( context, ZMQ_PULL );
    zmq_bind( to2, "tcp://*:5556" );

    zmq_pollitem_t pollitem = { to1, 0, ZMQ_POLLIN, 0 };

    if (0 < zmq_poll( &pollitem, 1, 10000 ))
    {
        char buffer[128];
        memset( &buffer, 0, sizeof(buffer) );
        zmq_recv( to1, &buffer, sizeof(buffer), 0 );
        std::cout << "Got " << buffer << " from connection 1 " << std::endl;
    }

    pollitem.socket = to2;

    if (0 < zmq_poll( &pollitem, 1, 10000 ))
    {
        char buffer[128];
        memset( &buffer, 0, sizeof(buffer) );
        zmq_recv( to2, &buffer, sizeof(buffer), 0 );
        std::cout << "Got " << buffer << " from connection 2 " << std::endl;
    }

    zmq_close(to1);
    zmq_close(to2);

    zmq_ctx_destroy(context);

    return EXIT_SUCCESS;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20130708/b66d4e83/attachment.htm>


More information about the zeromq-dev mailing list