Skip to content

Commit a4494d5

Browse files
author
Peter Thorson
committed
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
1 parent afcf09d commit a4494d5

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ HEAD
4545
later compilers. Thank you Matus Kysel for the patch & tests. #792
4646
- Reliability: Add a few defensive assertions to guard against corrupted
4747
HTTP message reads. Thank you Oleh Derevenko for reporting. #899
48+
- Fix Regression: Correct a regression introduced in 0.8.0 that broke
49+
functionality for setting accepted socket options like TCP_NODELAY.
50+
#530 #812
4851
- Bug: Fix null pointer deference in proxy error handling code. Thank you
4952
abitmore for reporting and stkaufer for a patch. #820 #825
5053
- Documentation: Added language to explicitly clarify that the library

docs/handlers.dox

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,24 @@ Close is not called for failed connections.
108108
Endpoint Handlers
109109
-----------------
110110

111-
## Acceptance Loop End Handler
111+
### Socket Init Handler
112+
113+
| Event | Signature | Availability |
114+
| -------------- | ----------------------------------------------------------------------------- | -------------------- |
115+
| Listen Prebind | `lib::error_code tcp_pre_bind(lib::shared_ptr<lib::asio::ip::tcp::acceptor>)` | 0.8.0 Asio Transport |
116+
117+
This hook is triggered during the call to `endpoint::listen` after the acceptor
118+
is initialized and open but before bind or listen are called. It provides an
119+
opportunity to make application specific configuation to the acceptor, most
120+
commonly setting socket options on the listening socket, such as SO_REUSEPORT
121+
or IPV6_ONLY.
122+
123+
The return value of the callback will be used to determine whether to proceed
124+
with listening. Return an empty/0 error code to proceed, or another error code
125+
to fail. In the fail case, the error code will be reported back to the caller
126+
of `endpoint::listen`.
127+
128+
### Acceptance Loop End Handler
112129

113130
| Event | Signature | Availability |
114131
| ------------------------------------- | --------------------------------------------------------------------- | ---------------------------- |

websocketpp/transport/asio/security/none.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ class connection : public lib::enable_shared_from_this<connection> {
156156
/// Perform one time initializations
157157
/**
158158
* init_asio is called once immediately after construction to initialize
159-
* Asio components to the io_service
159+
* Asio components to the io_service. At this stage the connection is
160+
* speculative, the server may not have actually received a new connection.
160161
*
161162
* @param service A pointer to the endpoint's io_service
162163
* @param strand A shared pointer to the connection's asio strand
@@ -170,10 +171,6 @@ class connection : public lib::enable_shared_from_this<connection> {
170171

171172
m_socket.reset(new lib::asio::ip::tcp::socket(*service));
172173

173-
if (m_socket_init_handler) {
174-
m_socket_init_handler(m_hdl, *m_socket);
175-
}
176-
177174
m_state = READY;
178175

179176
return lib::error_code();
@@ -194,7 +191,7 @@ class connection : public lib::enable_shared_from_this<connection> {
194191

195192
/// Pre-initialize security policy
196193
/**
197-
* Called by the transport after a new connection is created to initialize
194+
* Called by the transport after a new connection is accepted to initialize
198195
* the socket component of the connection. This method is not allowed to
199196
* write any bytes to the wire. This initialization happens before any
200197
* proxies or other intermediate wrappers are negotiated.
@@ -207,6 +204,10 @@ class connection : public lib::enable_shared_from_this<connection> {
207204
return;
208205
}
209206

207+
if (m_socket_init_handler) {
208+
m_socket_init_handler(m_hdl, *m_socket);
209+
}
210+
210211
m_state = READING;
211212

212213
callback(lib::error_code());

websocketpp/transport/asio/security/tls.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,6 @@ class connection : public lib::enable_shared_from_this<connection> {
195195
}
196196
m_socket.reset(new socket_type(*service, *m_context));
197197

198-
if (m_socket_init_handler) {
199-
m_socket_init_handler(m_hdl, get_socket());
200-
}
201-
202198
m_io_service = service;
203199
m_strand = strand;
204200
m_is_server = is_server;
@@ -247,6 +243,9 @@ class connection : public lib::enable_shared_from_this<connection> {
247243
}
248244
}
249245
#endif
246+
if (m_socket_init_handler) {
247+
m_socket_init_handler(m_hdl, get_socket());
248+
}
250249

251250
callback(lib::error_code());
252251
}

0 commit comments

Comments
 (0)