ZMQ::send()会抛出一个异常并杀死 QNX 进程。为什么要这样做以及如何恢复?

问题描述 投票:0回答:1

ZMQ::send() 抛出一个异常并杀死进程。

为什么要这样做,以及如何恢复。

我使用ZeroMQ REQ/REP QNX 6.5.0 版的模式。预计将在QNX 6.5.0版本上采用 catch{} 块没有收到这个异常。

这里是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

这是我的代码片段。

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;
}

c++ exception zeromq qnx-neutrino
1个回答
1
投票

如果按照dbg()的输出,报告的行数(如果使用最新版本)。涉及 模板定义 template<int Opt, class T, bool BoolUnit = false> struct integral_option{} 在ZMQ_CPP11中 #ifdef 块。

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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

如果源码和C++11版都适合并到位工作,增加更多的调试启用代码,以检查死前的内容。create_values 变量,然后再调用实际的 .send()-方法。

几个 assert()-s也将是公平的,就像在

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

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

在这里,我就不敢满足API的定义,所以宁可调用 zmq_setsockopt( socket, ZMQ_LINGER, &linger, sizeof (linger) )

© www.soinside.com 2019 - 2024. All rights reserved.