我正在使用一个库(C++ REST SDK),我可以在其中为特定事件设置处理程序。确切地说,我设置了一个关闭处理程序,当客户端(我)或服务器关闭websocket连接时,它会被调用。处理程序设置如下:
Select *
当我现在关闭连接时,库处理关闭过程,并在完成该过程后,使用其三个参数调用// WebsocketClient is my own custom class
// m_pclClient holds the connection (of type websocket_callback_client)
std::function<void(web::websockets::client::websocket_close_status close_status, const utility::string_t &reason, const std::error_code &error)> handler(std::bind(&WebsocketClient::close_handler, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
this->m_pclClient->set_close_handler(handler);
。
关闭连接时会发生错误。我不确定这是图书馆内的错误还是我的错误。关闭连接时输出handler
:
gdb
参数#0显然存在问题:Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffe1c23700 (LWP 13849)]
0x00000000004e20b7 in std::__invoke_impl<void, void (WebsocketClient::* const&)(web::websockets::client::websocket_close_status, std::string const&, std::error_code const&), WebsocketClient*&, web::websockets::client::websocket_close_status, std::string const&, std::error_code const&>(std::__invoke_memfun_deref, void (WebsocketClient::* const&)(web::websockets::client::websocket_close_status, std::string const&, std::error_code const&), WebsocketClient*&, web::websockets::client::websocket_close_status&&, std::string const&, std::error_code const&) (__f=
@0x80d290: (void (WebsocketClient::*)(WebsocketClient * const, web::websockets::client::websocket_close_status, const std::basic_string<char, std::char_traits<char>, std::allocator<char> > &, const std::error_code &)) 0x4cf120 <WebsocketClient::close_handler(web::websockets::client::websocket_close_status, std::string const&, std::error_code const&)>, __t=@0x80d2a0: 0x8081f8,
__args#0=<unknown type in /path/to/executable, CU 0x1d28f4, DIE 0x21f672>, __args#1="TLS Short Read", __args#2=...) at /usr/include/c++/6/functional:235
235 return ((*std::forward<_Tp>(__t)).*__f)(std::forward<_Args>(__args)...);
。
似乎应该调用处理程序时,第一个参数的类型是未知的。请参阅gdb输出:“__ args#0 =&lt; / path / to / executable中的未知类型”
为什么会发生这种情况以及如何解决?