TCP_NODELAY for TLS

374 views
Skip to first unread message

jimbo...@gmail.com

unread,
Apr 11, 2014, 9:58:35 AM4/11/14
to webso...@googlegroups.com
Peter,

I can't thank you enough for the performance and clarity of your library!


However, I'm getting these errors:

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> >&)>}’

How can I do this properly?

Thank you so much in advance and for such an amazing library!

jimbo...@gmail.com

unread,
Apr 11, 2014, 10:33:23 PM4/11/14
to webso...@googlegroups.com

Peter Thorson

unread,
Apr 12, 2014, 9:47:35 AM4/12/14
to jimbo...@gmail.com, webso...@googlegroups.com
The socket_init_handler is a low level hook designed to allow full access to the underlying socket after it is initialized but before it is used. The signature of the socket_init_handler depends on what transport policy in use. While very similar in most ways, asio/plain and asio/tls are actually distinct transport policies and do have some differences.

One of those differences is that the underlying socket typed used in the asio/tls policy is an ssl stream wrapping a socket rather than just the raw socket. As such, the signature of the socket_init_handler for the asio/tls transport is different than that of asio/plain. The signature for the handler on an endpoint using asio/tls transport is:

typedef lib::function<void(connection_hdl,boost::asio::ssl::stream<boost::asio::ip::tcp::socket>&)> socket_init_handler;

This can be found in the documentation at:
http://doxygen.websocketpp.org/namespacewebsocketpp_1_1transport_1_1asio_1_1tls__socket.html

A corresponding socket init handler that sets TCP_NODELAY for might look like:

```
void on_socket_init(websocketpp::connection_hdl hdl, boost::asio::ssl::stream<boost::asio::ip::tcp::socket> & s) {
    boost::asio::ip::tcp::no_delay option(true);
    s.lowest_layer().set_option(option);
}

endpoint.set_socket_init_handler(&on_socket_init);
```

--
You received this message because you are subscribed to the Google Groups "WebSocket++" group.
To unsubscribe from this group and stop receiving emails from it, send an email to websocketpp...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jimbo...@gmail.com

unread,
Apr 12, 2014, 10:10:46 AM4/12/14
to webso...@googlegroups.com, jimbo...@gmail.com
Amazing, absolute amazing!

Thank you so much zaphoyd!  My server is now unbelievably fast!
Reply all
Reply to author
Forward
0 new messages