简体   繁体   English

ZMQ::send() 抛出异常并终止 QNX 进程。 为什么以及如何从中恢复?

[英]ZMQ::send() throws an exception and kills the QNX-process. Why and how to recover from it?

ZMQ::send() throws an exception and kills the process. ZMQ::send()抛出异常并终止进程。

Why and how to recover from it.为什么以及如何从中恢复。

I use the ZeroMQ REQ/REP pattern on QNX-version 6.5.0.我在 QNX 版本 6.5.0 上使用 ZeroMQ REQ/REP模式。 The anticipated catch{} block does not receive this exception.预期的catch{}块没有收到此异常。

Here is the gdb trace:这是 gdb 跟踪:

(gdb) bt
#0  0xb033e4a1 in SignalKill () from /opt/qnx650/target/qnx6/x86/lib/libc.so.3
#1  0xb032d0ee in raise () from /opt/qnx650/target/qnx6/x86/lib/libc.so.3
#2  0xb032b3a8 in abort () from /opt/qnx650/target/qnx6/x86/lib/libc.so.3
#3  0xb835c077 in std::do_abort () from /opt/qnx650/target/qnx6/x86/lib/libcpp.so.4
#4  0xb835c01e in std::terminate () from /opt/qnx650/target/qnx6/x86/lib/libcpp.so.4
#5  0xb8354ff3 in __cxa_throw () from /opt/qnx650/target/qnx6/x86/lib/libcpp.so.4
#6  0x080596bc in zmq::detail::socket_base::send (this=0x8071070, msg_=@0x7b22d38)
    at /home/bindhu/rtcs/libzmq/include/zmq.hpp:1299
#7  0x0805b0a4 in dblog::SendPacketToDBLogger (this=0x8071068, ipc_can_msg=
      {type = 0, timestamp = 1590330536976, can_id = 352260142, data = 2511882692165894191})
    at /home/user/rtcs/canvehicle/dblog.cpp:203
#8  0x080530e3 in send_version_request (type=0 '\0', module=47 '/')
    at /home/user/rtcs/canvehicle/CanVehicle.cc:4736
#9  0x08053f50 in p_thread_kalmar_version (arg=0x0)
    at /home/user/rtcs/canvehicle/CanVehicle.cc:4749
#10 0xb0320390 in ?? () from /opt/qnx650/target/qnx6/x86/lib/libc.so.3

This is snippet of my code.这是我的代码片段。

dblog::dblog() :
    context(1), socket(context, ZMQ_REQ) {
    zmq_setsockopt (socket, ZMQ_LINGER, "", 0);
}
void dblog::Init() {
    socket.connect("tcp://127.0.0.1:5555");
}
zmq::message_t create_values(protoTable.ByteSizeLong() + sizeof(uint16_t));
*((uint16_t*)create_values.data()) = TABLEMSG_ID;  // ID
protoTable.SerializeToArray(create_values.data() + sizeof(uint16_t), protoTable.ByteSizeLong());

zmq::message_t reply;
try {
int returnv = socket.send(create_values,ZMQ_NOBLOCK);
socket.recv(&reply);
}
 catch (int e)
{
std::cout << "SPD exception e : " << e << std::endl;
}

If following the dbg()-output, the reported line ( if using the most recent version ) relates to template definition for template<int Opt, class T, bool BoolUnit = false> struct integral_option{} in the ZMQ_CPP11 #ifdef block:如果遵循 dbg()-输出,则报告的行(如果使用最新版本) ZMQ_CPP11 #ifdef块中template<int Opt, class T, bool BoolUnit = false> struct integral_option{}的模板定义相关:

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ zmq.hpp:1290
#ifdef ZMQ_CPP11

namespace sockopt
{
// There are two types of options,
// integral type with known compiler time size (int, bool, int64_t, uint64_t)
// and arrays with dynamic size (strings, binary data).

// BoolUnit: if true accepts values of type bool (but passed as T into libzmq)
template<int Opt, class T, bool BoolUnit = false> struct integral_option
{
};

...

} // namespace sockopt
#endif // ZMQ_CPP11
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ zmq.hpp:1577

If both the source-code and the C++ Version 11 are fit and in place working, add more debugging enabling code, to inspect pre-mortem content of the create_values variable before the call to the actual .send() -method.如果源代码和 C++ 版本 11 都适合并且可以正常工作,请添加更多调试启用代码,以在调用实际.send()方法之前检查create_values变量的预先分析内容。

A few assert() -s will also be fair, like in一些assert() -s 也将是公平的,例如

assert(   socket.connect() == 0
      && "INF:: a call to .connect()-method failed, better inspect the <errno>"
          );

or或者

assert(   0 == zmq_setsockopt( socket, ZMQ_LINGER, "", 0 )
      && "INF:: a call to zmq_setsockopt() API failed, better inspect the <errno>"
          );

Here, I would dare not to meet the API definition, so would rather call在这里,我不敢满足API定义,所以宁愿调用
zmq_setsockopt( socket, ZMQ_LINGER, &linger, sizeof (linger) )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM