I'm using C++ binding for ZMQ (cppzmq) and I'm trying to set the connection timeout of TCP socket using a .setsockopt()
-method like this:
int connectTimeout = 1000;
socket.setsockopt(ZMQ_CONNECT_TIMEOUT, &connectTimeout, sizeof(connectTimeout));
socket.connect(clientConfiguration.uri);
However, I dont see anything (exception thrown?) happening until code reaches actual .send()/.recv()
on the socket. Just to make sure the socket has a chance to throw I put a sleep between .connect()
and .send()
methods.
According to the documentation .zmq_connect()
just enters a READY
-state without making actual connection to the endpoint. So the question is when and how I should experience the connection timeout?
ZeroMQ (also known as ØMQ, 0MQ, or zmq) looks like an embeddable networking library but acts like a concurrency framework. It gives you sockets that carry atomic messages across various transports like in-process, inter-process, TCP, and multicast.
Contexts help manage any sockets that are created as well as the number of threads ZeroMQ uses behind the scenes. Create one when you initialize a process and destroy it as the process is terminated. Contexts can be shared between threads and, in fact, are the only ZeroMQ objects that can safely do this.
The zmq_poll() function provides a mechanism for applications to multiplex input/output events in a level-triggered fashion over a set of sockets. Each member of the array pointed to by the items argument is a zmq_pollitem_t structure. The nitems argument specifies the number of items in the items array.
So the question is when and how I should experience the connection timeout ?
Well, actually never directly as this is just the API-exposed setting of ZeroMQ Context()
-instances' internal Finite-State-Machine modus operandi ( here the .setsockopt()
sets the selected transport-class behind-the-API-curtain ISO-OSI-L3 details ).
Well, there are some other .setsockopt()
details, that ( if put on ) may indirectly sense the impact of the set ZMQ_CONNECT_TIMEOUT
connection timeout. Here again, only indirectly, by a modified FSM-behaviour, i.e. in a way, how the .Context()
-engine instance will happen to respond to such event ( all purely internally, behind the Curtain of API - that's why we methodologically use the API method for separation of concerns, don't we ? ).
For further details ref.:
ZMQ_IMMEDIATE
,ZMQ_RECONNECT_IVL
,ZMQ_RECONNECT_IVL_MAX
.#ASSUME NOTHING
. )
If not familiar with the ZeroMQ instrumentation, one may find useful this 5-seconds read into the main conceptual differences in the [ ZeroMQ hierarchy in less than a five seconds ] Section,
( courtesy Martin Sústrik, co-father of both ZeroMQ + nanomsg. Respect! )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With