zeromq / zmq.rs

A native implementation of ØMQ in Rust
https://crates.io/crates/zeromq
MIT License
1.13k stars 93 forks source link

Tcp keep alive setting function #155

Open testforvln opened 2 years ago

testforvln commented 2 years ago

Hi all, I use this crate on receiving live stock quotes from stock exchanges. When the market daily rests for a while and then restarts trading, I could get no data from the zmq connection established before. It can be fixed by tcp keep alive settings, but I could not find the related function in this crate. Could you help me with it?

poyea commented 2 years ago

Hey there! I believe it isn't available as of v0.3.3 - as part of the option. Correct me with an example if I'm wrong. Ideally, we want to support something like this:

let mut options = SocketOptions::default();
// or a "TCP option"
options.tcp_keepalive(TcpKeepalive {
    keepalive: 1,
    count: 5,
    idle: 1,
    interval: 10,
});

let mut socket = zeromq::ReqSocket::with_options(options);
socket
    .connect("tcp://127.0.0.1:8888")
    .await
    .expect("Failed to connect");
testforvln commented 2 years ago

Yeah, this exmaple of with_options funciton is very helpful. I think it's the ideal way to implement the zmq options settings.