From 3d272c2b8777fbcb87ef9bd55ee70af519f5db23 Mon Sep 17 00:00:00 2001 From: Peter Thorson Date: Fri, 7 Aug 2020 15:20:33 -0500 Subject: [PATCH] Correct a regression introduced in 0.8.0 that prevented socket options like TCP_NODELAY from being set. Improve documentation about how pre_init differs from init_asio. Improve documentation for the TCP pre-bind handler that is the actual solution to the issue this regression related to. references #530 fixes #812 --- changelog.md | 5 +++++ docs/handlers.dox | 19 ++++++++++++++++++- websocketpp/transport/asio/security/none.hpp | 13 +++++++------ websocketpp/transport/asio/security/tls.hpp | 7 +++---- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/changelog.md b/changelog.md index 91db9a02c..3216b159c 100644 --- a/changelog.md +++ b/changelog.md @@ -45,6 +45,11 @@ HEAD later compilers. Thank you Matus Kysel for the patch & tests. #792 - Reliability: Add a few defensive assertions to guard against corrupted HTTP message reads. Thank you Oleh Derevenko for reporting. #899 +- Fix Regression: Correct a regression introduced in 0.8.0 that broke + functionality for setting accepted socket options like TCP_NODELAY. + #530 #812 +- Bug: Fix null pointer deference in proxy error handling code. Thank you + abitmore for reporting and stkaufer for a patch. #820 #825 - Documentation: Added language to explicitly clarify that the library license is in fact the 3-Clause BSD license. #906 - Travis/CI: Updated Travis config to use newer version of ubuntu, and use diff --git a/docs/handlers.dox b/docs/handlers.dox index 6794e91f8..c32988501 100644 --- a/docs/handlers.dox +++ b/docs/handlers.dox @@ -108,7 +108,24 @@ Close is not called for failed connections. Endpoint Handlers ----------------- -## Acceptance Loop End Handler +### Socket Init Handler + +| Event | Signature | Availability | +| -------------- | ----------------------------------------------------------------------------- | -------------------- | +| Listen Prebind | `lib::error_code tcp_pre_bind(lib::shared_ptr)` | 0.8.0 Asio Transport | + +This hook is triggered during the call to `endpoint::listen` after the acceptor +is initialized and open but before bind or listen are called. It provides an +opportunity to make application specific configuation to the acceptor, most +commonly setting socket options on the listening socket, such as SO_REUSEPORT +or IPV6_ONLY. + +The return value of the callback will be used to determine whether to proceed +with listening. Return an empty/0 error code to proceed, or another error code +to fail. In the fail case, the error code will be reported back to the caller +of `endpoint::listen`. + +### Acceptance Loop End Handler | Event | Signature | Availability | | ------------------------------------- | --------------------------------------------------------------------- | ---------------------------- | diff --git a/websocketpp/transport/asio/security/none.hpp b/websocketpp/transport/asio/security/none.hpp index 6c7d35241..c679378ed 100644 --- a/websocketpp/transport/asio/security/none.hpp +++ b/websocketpp/transport/asio/security/none.hpp @@ -156,7 +156,8 @@ class connection : public lib::enable_shared_from_this { /// Perform one time initializations /** * init_asio is called once immediately after construction to initialize - * Asio components to the io_service + * Asio components to the io_service. At this stage the connection is + * speculative, the server may not have actually received a new connection. * * @param service A pointer to the endpoint's io_service * @param strand A shared pointer to the connection's asio strand @@ -170,10 +171,6 @@ class connection : public lib::enable_shared_from_this { m_socket.reset(new lib::asio::ip::tcp::socket(*service)); - if (m_socket_init_handler) { - m_socket_init_handler(m_hdl, *m_socket); - } - m_state = READY; return lib::error_code(); @@ -194,7 +191,7 @@ class connection : public lib::enable_shared_from_this { /// Pre-initialize security policy /** - * Called by the transport after a new connection is created to initialize + * Called by the transport after a new connection is accepted to initialize * the socket component of the connection. This method is not allowed to * write any bytes to the wire. This initialization happens before any * proxies or other intermediate wrappers are negotiated. @@ -207,6 +204,10 @@ class connection : public lib::enable_shared_from_this { return; } + if (m_socket_init_handler) { + m_socket_init_handler(m_hdl, *m_socket); + } + m_state = READING; callback(lib::error_code()); diff --git a/websocketpp/transport/asio/security/tls.hpp b/websocketpp/transport/asio/security/tls.hpp index 04ac37903..f17f57727 100644 --- a/websocketpp/transport/asio/security/tls.hpp +++ b/websocketpp/transport/asio/security/tls.hpp @@ -195,10 +195,6 @@ class connection : public lib::enable_shared_from_this { } m_socket.reset(new socket_type(*service, *m_context)); - if (m_socket_init_handler) { - m_socket_init_handler(m_hdl, get_socket()); - } - m_io_service = service; m_strand = strand; m_is_server = is_server; @@ -247,6 +243,9 @@ class connection : public lib::enable_shared_from_this { } } #endif + if (m_socket_init_handler) { + m_socket_init_handler(m_hdl, get_socket()); + } callback(lib::error_code()); }