libzmq icon indicating copy to clipboard operation
libzmq copied to clipboard

[Question] ZMQ_SERVER; ending communication with only one client of many.

Open TYoungSL opened this issue 4 years ago • 3 comments

Issue description

In regards to ZMQ_SERVER, if a single client sends a bad frame and I want to end communication with the client, how do I do that without ending communication with all connected clients?

Environment

  • libzmq version (commit hash if unreleased): v4.3.4
  • OS: Windows

TYoungSL avatar Oct 20 '21 16:10 TYoungSL

Seems like we need something like this?


// zmq.cpp
int zmq_drop_peer (void *s_, uint32_t routing_id, bool delay) {
    zmq::server_t *s = static_cast<zmq::server_t *> (s_);
    
    int socket_type;
    size_t socket_type_size = sizeof (socket_type);
    if (s->getsockopt (ZMQ_TYPE, &socket_type, &socket_type_size) != 0) {
        errno = EINVAL;
        return -1;
    }
    
    if (socket_type != ZMQ_PEER && socket_type != ZMQ_SERVER) {
        errno = ENOTSUP;
        return -1;
    }

    return s->drop(routing_id, delay);
}

// server.cpp
int zmq::server_t::drop(uint32_t routing_id, bool delay) {
    out_pipes_t::iterator it = _out_pipes.find (routing_id);
    
    if (it == _out_pipes.end ()) {
        errno = EHOSTUNREACH;
        return -1;
    }

    it->second.pipe->terminate (delay);
    return 0;
}

TYoungSL avatar Oct 20 '21 17:10 TYoungSL

Hello? FYI for anyone interested, the above code seems to work.

TYoungSL avatar Oct 25 '21 13:10 TYoungSL

So this need a patch into the libzmq then? I would be very interested by this

lp35 avatar Sep 06 '22 11:09 lp35