使用ZMQ接收消息时,ZMQ总是出错的可能性。
我的开发环境:
zmq version: 4.1.4
server: centos7.0, 8cpu 2.0GHZ
代码如下:
{
zmq::context_t context(1);
zmq::socket_t socket(context, ZMQ_PULL);
socket.bind(m_config.m_strIPAndPort);
zmq::pollitem_t pollItems[]= {{socket,0,ZMQ_POLLIN,0}};
int MAX_POLLITEM_NUM = 1;
while ( !m_bStopThread )
{
try
{
zmq::poll(pollItems, MAX_POLLITEM_NUM, -1);
if( pollItems[0].revents & ZMQ_POLLIN )
{
zmq::message_t zmqMsg;
bool bRes = socket.recv(&zmqMsg);
if ( bRes )
{
pushMsg((const char *)zmqMsg.data(), zmqMsg.size());
}
}
}
catch (exception & e)
{
const char * pszError = e.what();
string strErrMsg = "Error : receive cmd from client exception : " + string(pszError);
qInfo(strErrMsg.c_str());
}
}
}
GDB的堆栈信息:
#0 0x00007fe3366c7277 in raise () from /lib64/libc.so.6
#1 0x00007fe3366c8968 in abort () from /lib64/libc.so.6
#2 0x00007fe337ffabb9 in zmq::zmq_abort (
errmsg_=errmsg_@entry=0x7fe33803b71f "check ()") at src/err.cpp:87
#3 0x00007fe3380030eb in zmq::msg_t::size (this=0x7fe320002d00)
at src/msg.cpp:361
#4 0x00007fe3380308f2 in zmq::v2_encoder_t::message_ready (
this=0x7fe2e8008ce0) at src/v2_encoder.cpp:54
#5 0x00007fe338021cc1 in zmq::stream_engine_t::out_event
(this=0x7fe320002ce0)
at src/stream_engine.cpp:386
#6 0x00007fe338015a76 in zmq::session_base_t::read_activated (
this=0x7fe3200031b0, pipe_=0x7fe2e8008ac0) at src/session_base.cpp:288
#7 0x00007fe337ffbb14 in zmq::io_thread_t::in_event (this=0x1d17100)
at src/io_thread.cpp:85
#8 0x00007fe337ffa36e in zmq::epoll_t::loop (this=0x1d176b0)
at src/epoll.cpp:188
#9 0x00007fe33802b96d in thread_routine (arg_=0x1d17730) at
src/thread.cpp:109
#10 0x00007fe337284e25 in start_thread () from /lib64/libpthread.so.0
#11 0x00007fe33678fbad in clone () from /lib64/libc.so.6
在另一台具有更高cpu(例如3.2G)频率的服务器上运行它时,它可以正常工作。
我该怎么办?
感谢您的回答。