zeromq / libzmq

ZeroMQ core engine in C++, implements ZMTP/3.1
https://www.zeromq.org
Mozilla Public License 2.0
9.53k stars 2.34k forks source link

When using ZMQ_SUB ,ZMQ_ TCP_ KEEPALIVE_ IDLE does not work #4567

Closed ml232528 closed 1 year ago

ml232528 commented 1 year ago

Please use this template for reporting suspected bugs or requests for help.

Issue description

One end uses ZMQ_PUB to send data, and the other end uses ZMQSUB to receive data,ZMQ TCP KEEPALIVE IDLE does not work in ZMQSUB mode. ZMQPUB is ok.

Environment

Minimal test code / Steps to reproduce the issue

zmqSubscriber_ = zmq_socket(, ZMQ_SUB); zmq_socketmonitor(zmqSubscriber, , ZMQ_EVENT_ALL); zmqconnect(zmqSubscriber, ); zmqsetsockopt(zmqSubscriber, ZMQ_SUBSCRIBE, ); int r = 1; zmqsetsockopt(zmqSubscriber, ZMQ_CONFLATE, &r, sizeof(r)); r = 5; zmqsetsockopt(zmqSubscriber, ZMQ_TCP_KEEPALIVE_IDLE, &r, sizeof(r)); zmqsetsockopt(zmqSubscriber, ZMQ_TCP_KEEPALIVE_CNT, &r, sizeof(r)); r = 1; zmqsetsockopt(zmqSubscriber, ZMQ_TCP_KEEPALIVE_INTVL, &r, sizeof(r)); zmqsetsockopt(zmqSubscriber, ZMQ_TCP_KEEPALIVE, &r, sizeof(r));

What's the actual result? (include assertion message & call stack if applicable)

By tracking the source code,the setsockopt function stores the correct value. int zmq::optionst::setsockopt (int option, const void *optval_, sizet optvallen) :options.cpp

But in the tune_socket function, it becomes -1。 bool zmq::tcp_connecter_t::tune_socket (const fdt fd) :tcp_connecter.cpp

What's the expected result?

I hope the KEEPALIVE mechanism can work。

ml232528 commented 1 year ago

resolved: Set KEEPALIVE before connect.