我在实现示例代码以为 websocket++ 端点打开 TCP_NODELAY 时遇到问题。
示例按预期编译和工作,testee
并且debug
示例经常按预期编译和工作。
我尝试过on_socket_init
两种方式都设置处理程序,但每次都得到几乎相同的错误。一组这样的错误是:
In constructor ‘broadcast_server::broadcast_server()’:
error: no matching function for call to ‘websocketpp::client<websocketpp::config::asio_tls_client>::set_socket_init_handler(std::_Bind_helper<false, void (*)(std::weak_ptr<void>, boost::asio::basic_stream_socket<boost::asio::ip::tcp>&), const std::_Placeholder<1>&, const std::_Placeholder<2>&>::type)’
m_endpoint.set_socket_init_handler(bind(&on_socket_init,::_1,::_2));
^
note: candidate is:
In file included from websocketpp/config/asio.hpp:33:0,
from websocketpp/transport/asio/security/tls.hpp:373:10: note: void websocketpp::transport::asio::tls_socket::endpoint::set_socket_init_handler(websocketpp::transport::asio::tls_socket::socket_init_handler)
void set_socket_init_handler(socket_init_handler h) {
^
websocketpp/transport/asio/security/tls.hpp:373:10: note: no known conversion for argument 1 from ‘std::_Bind_helper<false, void (*)(std::weak_ptr<void>, boost::asio::basic_stream_socket<boost::asio::ip::tcp>&), const std::_Placeholder<1>&, const std::_Placeholder<2>&>::type {aka std::_Bind<void (*(std::_Placeholder<1>, std::_Placeholder<2>))(std::weak_ptr<void>, boost::asio::basic_stream_socket<boost::asio::ip::tcp>&)>}’ to ‘websocketpp::transport::asio::tls_socket::socket_init_handler {aka std::function<void(std::weak_ptr<void>, boost::asio::ssl::stream<boost::asio::basic_stream_socket<boost::asio::ip::tcp> >&)>}’
error: no matching function for call to ‘websocketpp::server<websocketpp::config::asio_tls>::set_socket_init_handler(std::_Bind_helper<false, void (*)(std::weak_ptr<void>, boost::asio::basic_stream_socket<boost::asio::ip::tcp>&), const std::_Placeholder<1>&, const std::_Placeholder<2>&>::type)’
m_server.set_socket_init_handler(bind(&on_socket_init,::_1,::_2));
^
note: candidate is:
In file included from websocketpp/config/asio.hpp:33:0,
from websocketpp/transport/asio/security/tls.hpp:373:10: note: void websocketpp::transport::asio::tls_socket::endpoint::set_socket_init_handler(websocketpp::transport::asio::tls_socket::socket_init_handler)
void set_socket_init_handler(socket_init_handler h) {
^
websocketpp/transport/asio/security/tls.hpp:373:10: note: no known conversion for argument 1 from ‘std::_Bind_helper<false, void (*)(std::weak_ptr<void>, boost::asio::basic_stream_socket<boost::asio::ip::tcp>&), const std::_Placeholder<1>&, const std::_Placeholder<2>&>::type {aka std::_Bind<void (*(std::_Placeholder<1>, std::_Placeholder<2>))(std::weak_ptr<void>, boost::asio::basic_stream_socket<boost::asio::ip::tcp>&)>}’ to ‘websocketpp::transport::asio::tls_socket::socket_init_handler {aka std::function<void(std::weak_ptr<void>, boost::asio::ssl::stream<boost::asio::basic_stream_socket<boost::asio::ip::tcp> >&)>}’
我看过另一个帖子,另一个开发人员声称它正在运行,因为我不完全理解这种语法
m_endpoint.set_socket_init_handler(bind(&type::on_socket_init,this,::_1));
我不确定如何开始诊断这个问题。
如何解决上述错误?
注意我正在实施 TLS。
需要的代码
我最感兴趣的是合并这个函数的内容:
void on_socket_init(websocketpp::connection_hdl hdl, boost::asio::ip::tcp::socket & s) {
boost::asio::ip::tcp::no_delay option(true);
s.set_option(option);
}
有没有办法修改源,以便默认进行此设置?