rpc异常导致程序崩溃
chenjinle opened this issue · 3 comments
程序异常时报错如下:
#0 0xb6a0ee22 in rest_rpc::rpc_client::call_back(unsigned long long, boost::system::error_code const&, boost::basic_string_view<char, std::char_traits >) () from /mnt/data/hwt_rk3308/lib/libbtl.so
#1 0xb6a139ca in boost::asio::detail::read_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::any_io_executor>, boost::asio::mutable_buffers_1, boost::asio::mutable_buffer const*, boost::asio::detail::transfer_all_t, rest_rpc::rpc_client::read_body(unsigned long long, rest_rpc::request_type, unsigned int)::{lambda(boost::system::error_code, unsigned int)#1}>::operator()(boost::system::error_code, unsigned int, int) () from /mnt/data/hwt_rk3308/lib/libbtl.so
#2 0xb6a14950 in boost::asio::detail::reactive_socket_recv_op<boost::asio::mutable_buffers_1, boost::asio::detail::read_op<boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::any_io_executor>, boost::asio::mutable_buffers_1, boost::asio::mutable_buffer const*, boost::asio::detail::transfer_all_t, rest_rpc::rpc_client::read_body(unsigned long long, rest_rpc::request_type, unsigned int)::{lambda(boost::system::error_code, unsigned int)#1}>, boost::asio::any_io_executor>::do_complete(void*, boost::asio::detail::scheduler_operation*, boost::system::error_code const&, unsigned int) ()
from /mnt/data/hwt_rk3308/lib/libbtl.so
#3 0xb6a0c286 in boost::asio::detail::scheduler::run(boost::system::error_code&) () from /mnt/data/hwt_rk3308/lib/libbtl.so
#4 0xb6a16df8 in std::thread::_State_impl<std::_Bind_simple<rest_rpc::rpc_client::rpc_client()::{lambda()#1} ()> >::_M_run() () from /mnt/data/hwt_rk3308/lib/libbtl.so
#5 0xb69257a0 in ?? () from /usr/lib/libstdc++.so.6
#6 0xb6a385ce in ?? () from /lib/libpthread.so.0
用法是在libbtl库中使用rpc创建客户端提供接口,另外有一个服务端,客户端接口代码如下:
rest_rpc::rpc_client& getBoardRpcClient(const std::string &host, int port) {
static rest_rpc::rpc_client m_rpcBoardClient;
if (m_rpcBoardClient.has_connected()) {
return m_rpcBoardClient;
}
m_rpcBoardClient.enable_auto_heartbeat(); // automatic heartbeat
m_rpcBoardClient.connect(host, port, false, 60); // 60s
return m_rpcBoardClient;
}
int getKeyCodeStatus(const int nKeyCode, KEYVALUE &emKeyValue){
#ifndef __NOREST_RPC
rest_rpc::rpc_client &m_rpcClient = getBoardRpcClient();
int nRetValue = 0;
if (!m_rpcClient.has_connected()) {
printf("Error:%s not connect\r\n", __FUNCTION__);
return -2;
}
auto f = m_rpcClient.async_call<rest_rpc::FUTURE>("getKeyCodeStatus", nKeyCode);
if (f.wait_for(std::chrono::milliseconds(5000)) ==
std::future_status::timeout) {
printf("Error: %s : call timeout, line: %d\n", __FUNCTION__, __LINE__);
return -3;
}
nRetValue = f.get().as<int>();
if(nRetValue < 0){
return -4;
}else{
emKeyValue = (KEYVALUE)nRetValue;
return 0;
}
#else
return 0;
#endif
}
能提供一个完整的测试代码吗,包括服务端和客户端。
这个是客户端和服务端的测试代码