Skip to content

Commit

Permalink
Correct a regression introduced in 0.8.0 that prevented socket option…
Browse files Browse the repository at this point in the history
…s 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 zaphoyd#530 fixes zaphoyd#812
  • Loading branch information
Peter Thorson authored and TwentyPast4 committed Aug 18, 2022
1 parent ec9d3bc commit 3d272c2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion docs/handlers.dox
Expand Up @@ -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<lib::asio::ip::tcp::acceptor>)` | 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 |
| ------------------------------------- | --------------------------------------------------------------------- | ---------------------------- |
Expand Down
13 changes: 7 additions & 6 deletions websocketpp/transport/asio/security/none.hpp
Expand Up @@ -156,7 +156,8 @@ class connection : public lib::enable_shared_from_this<connection> {
/// 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
Expand All @@ -170,10 +171,6 @@ class connection : public lib::enable_shared_from_this<connection> {

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();
Expand All @@ -194,7 +191,7 @@ class connection : public lib::enable_shared_from_this<connection> {

/// 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.
Expand All @@ -207,6 +204,10 @@ class connection : public lib::enable_shared_from_this<connection> {
return;
}

if (m_socket_init_handler) {
m_socket_init_handler(m_hdl, *m_socket);
}

m_state = READING;

callback(lib::error_code());
Expand Down
7 changes: 3 additions & 4 deletions websocketpp/transport/asio/security/tls.hpp
Expand Up @@ -195,10 +195,6 @@ class connection : public lib::enable_shared_from_this<connection> {
}
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;
Expand Down Expand Up @@ -247,6 +243,9 @@ class connection : public lib::enable_shared_from_this<connection> {
}
}
#endif
if (m_socket_init_handler) {
m_socket_init_handler(m_hdl, get_socket());
}

callback(lib::error_code());
}
Expand Down

0 comments on commit 3d272c2

Please sign in to comment.