ZMQ 套接字连接超时 [英] ZMQ socket connection timeout

查看:84
本文介绍了ZMQ 套接字连接超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 ZMQ (cppzmq) 使用 C++ 绑定,我正在尝试使用 .setsockopt() 方法设置 TCP 套接字的连接超时,如下所示:

int connectTimeout = 1000;socket.setsockopt(ZMQ_CONNECT_TIMEOUT, &connectTimeout, sizeof(connectTimeout));socket.connect(clientConfiguration.uri);

但是,在代码到达套接字上的实际 .send()/.recv() 之前,我没有看到任何事情(抛出异常?)发生.为了确保套接字有机会抛出,我在 .connect().send() 方法之间放置了一个睡眠.

根据文档 .zmq_connect() 只是进入 READY 状态而不实际连接到端点.所以问题是我应该何时以及如何体验连接超时?

解决方案

所以问题是何时以及如何我应该遇到连接超时?

什么时候?

嗯,实际上从不直接,因为这只是 ZeroMQ Context()-instances 内部 的 API 公开设置Finite-State-Machine 操作方式(这里的 .setsockopt() 将选定的传输类设置在后面-the-API-curtain ISO-OSI-L3 详细信息).

如何(如果有的话)?

好吧,还有一些其他的.setsockopt()细节,(如果穿上)可能会间接感受到ZMQ_CONNECT_TIMEOUT 连接超时.再次,只是间接地,通过修改的 FSM 行为,即在某种程度上,.Context()-引擎实例将如何响应此类事件(全部纯内部,在幕后API - 这就是我们在方法论上使用 API 方法来分离关注点的原因,不是吗?).

更多细节参考:

  • 关于ZMQ_IMMEDIATE的API详细信息,
  • 关于ZMQ_RECONNECT_IVL的API详细信息,
  • 关于ZMQ_RECONNECT_IVL_MAX的API详细信息.
    ( API 版本不断发展,请注意并非所有

    ( 礼貌 Martin Sústrik,ZeroMQ + nanomsg 的共同父亲. 尊重!)

    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?

    解决方案

    So the question is when and how I should experience the connection timeout ?

    When ?

    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 ).

    How( if at all ) ?

    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.:

    • API details about ZMQ_IMMEDIATE,
    • API details about ZMQ_RECONNECT_IVL,
    • API details about ZMQ_RECONNECT_IVL_MAX.
      ( API versions evolve, be aware that not all agents share the same ZeroMQ API version. So best remember the Zen-of-Zero and feel free to re-use the anxient designers' directive #ASSUME NOTHING. )

    A TRAILER BONUS :

    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! )

    这篇关于ZMQ 套接字连接超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆