WebSocket++ 0.8.3-dev
C++ websocket client/server library
Loading...
Searching...
No Matches
connection.hpp
1/*
2 * Copyright (c) 2015, Peter Thorson. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
11 * * Neither the name of the WebSocket++ Project nor the
12 * names of its contributors may be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY
19 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 */
27
28#ifndef WEBSOCKETPP_TRANSPORT_ASIO_CON_HPP
29#define WEBSOCKETPP_TRANSPORT_ASIO_CON_HPP
30
31#include <websocketpp/transport/asio/base.hpp>
32
33#include <websocketpp/transport/base/connection.hpp>
34
35#include <websocketpp/logger/levels.hpp>
36#include <websocketpp/http/constants.hpp>
37
38#include <websocketpp/base64/base64.hpp>
39#include <websocketpp/error.hpp>
40#include <websocketpp/uri.hpp>
41
42#include <websocketpp/common/asio.hpp>
43#include <websocketpp/common/chrono.hpp>
44#include <websocketpp/common/cpp11.hpp>
45#include <websocketpp/common/memory.hpp>
46#include <websocketpp/common/functional.hpp>
47#include <websocketpp/common/connection_hdl.hpp>
48
49#include <istream>
50#include <sstream>
51#include <string>
52#include <vector>
53
54namespace websocketpp {
55namespace transport {
56namespace asio {
57
58typedef lib::function<void(connection_hdl)> tcp_init_handler;
59
60/// Asio based connection transport component
61/**
62 * transport::asio::connection implements a connection transport component using
63 * Asio that works with the transport::asio::endpoint endpoint transport
64 * component.
65 */
66template <typename config>
67class connection : public config::socket_type::socket_con_type {
68public:
69 /// Type of this connection transport component
70 typedef connection<config> type;
71 /// Type of a shared pointer to this connection transport component
72 typedef lib::shared_ptr<type> ptr;
73
74 /// Type of the socket connection component
75 typedef typename config::socket_type::socket_con_type socket_con_type;
76 /// Type of a shared pointer to the socket connection component
78 /// Type of this transport's access logging policy
79 typedef typename config::alog_type alog_type;
80 /// Type of this transport's error logging policy
81 typedef typename config::elog_type elog_type;
82
83 typedef typename config::request_type request_type;
84 typedef typename request_type::ptr request_ptr;
85 typedef typename config::response_type response_type;
86 typedef typename response_type::ptr response_ptr;
87
88 /// Type of a pointer to the Asio io_context being used
89 typedef lib::asio::io_context * io_context_ptr;
90 /// Type of a pointer to the Asio io_context::strand being used
91 typedef lib::shared_ptr<lib::asio::io_context::strand> strand_ptr;
92 /// Type of a pointer to the Asio timer class
93 typedef lib::shared_ptr<lib::asio::steady_timer> timer_ptr;
94
95 // connection is friends with its associated endpoint to allow the endpoint
96 // to call private/protected utility methods that we don't want to expose
97 // to the public api.
98 friend class endpoint<config>;
99
100 // generate and manage our own io_context
101 explicit connection(bool is_server, const lib::shared_ptr<alog_type> & alog, const lib::shared_ptr<elog_type> & elog)
102 : m_is_server(is_server)
103 , m_alog(alog)
104 , m_elog(elog)
105 {
106 m_alog->write(log::alevel::devel,"asio con transport constructor");
107 }
108
109 /// Get a shared pointer to this component
111 return lib::static_pointer_cast<type>(socket_con_type::get_shared());
112 }
113
114 bool is_secure() const {
115 return socket_con_type::is_secure();
116 }
117
118 /// Set uri hook
119 /**
120 * Called by the endpoint as a connection is being established to provide
121 * the uri being connected to to the transport layer.
122 *
123 * This transport policy doesn't use the uri except to forward it to the
124 * socket layer.
125 *
126 * @since 0.6.0
127 *
128 * @param u The uri to set
129 */
130 void set_uri(uri_ptr u) {
131 socket_con_type::set_uri(u);
132 }
133
134 /// Sets the tcp pre init handler
135 /**
136 * The tcp pre init handler is called after the raw tcp connection has been
137 * established but before any additional wrappers (proxy connects, TLS
138 * handshakes, etc) have been performed.
139 *
140 * @since 0.3.0
141 *
142 * @param h The handler to call on tcp pre init.
143 */
144 void set_tcp_pre_init_handler(tcp_init_handler h) {
145 m_tcp_pre_init_handler = h;
146 }
147
148 /// Sets the tcp pre init handler (deprecated)
149 /**
150 * The tcp pre init handler is called after the raw tcp connection has been
151 * established but before any additional wrappers (proxy connects, TLS
152 * handshakes, etc) have been performed.
153 *
154 * @deprecated Use set_tcp_pre_init_handler instead
155 *
156 * @param h The handler to call on tcp pre init.
157 */
158 void set_tcp_init_handler(tcp_init_handler h) {
160 }
161
162 /// Sets the tcp post init handler
163 /**
164 * The tcp post init handler is called after the tcp connection has been
165 * established and all additional wrappers (proxy connects, TLS handshakes,
166 * etc have been performed. This is fired before any bytes are read or any
167 * WebSocket specific handshake logic has been performed.
168 *
169 * @since 0.3.0
170 *
171 * @param h The handler to call on tcp post init.
172 */
173 void set_tcp_post_init_handler(tcp_init_handler h) {
174 m_tcp_post_init_handler = h;
175 }
176
177 /// Set the proxy to connect through (exception free)
178 /**
179 * The URI passed should be a complete URI including scheme. For example:
180 * http://proxy.example.com:8080/
181 *
182 * The proxy must be set up as an explicit (CONNECT) proxy allowed to
183 * connect to the port you specify. Traffic to the proxy is not encrypted.
184 *
185 * @param uri The full URI of the proxy to connect to.
186 *
187 * @param ec A status value
188 */
189 void set_proxy(std::string const & uri, lib::error_code & ec) {
190 // TODO: return errors for illegal URIs here?
191 // TODO: should https urls be illegal for the moment?
192 m_proxy = uri;
193 m_proxy_data = lib::make_shared<proxy_data>();
194 ec = lib::error_code();
195 }
196
197#ifndef _WEBSOCKETPP_NO_EXCEPTIONS_
198 /// Set the proxy to connect through (exception)
199 void set_proxy(std::string const & uri) {
200 lib::error_code ec;
201 set_proxy(uri,ec);
202 if (ec) { throw exception(ec); }
203 }
204#endif // _WEBSOCKETPP_NO_EXCEPTIONS_
205
206 /// Set the basic auth credentials to use (exception free)
207 /**
208 * The URI passed should be a complete URI including scheme. For example:
209 * http://proxy.example.com:8080/
210 *
211 * The proxy must be set up as an explicit proxy
212 *
213 * @param username The username to send
214 *
215 * @param password The password to send
216 *
217 * @param ec A status value
218 */
219 void set_proxy_basic_auth(std::string const & username, std::string const &
220 password, lib::error_code & ec)
221 {
222 if (!m_proxy_data) {
223 ec = make_error_code(websocketpp::error::invalid_state);
224 return;
225 }
226
227 // TODO: username can't contain ':'
228 std::string val = "Basic "+base64_encode(username + ":" + password);
229 m_proxy_data->req.replace_header("Proxy-Authorization",val);
230 ec = lib::error_code();
231 }
232
233#ifndef _WEBSOCKETPP_NO_EXCEPTIONS_
234 /// Set the basic auth credentials to use (exception)
235 void set_proxy_basic_auth(std::string const & username, std::string const &
236 password)
237 {
238 lib::error_code ec;
239 set_proxy_basic_auth(username,password,ec);
240 if (ec) { throw exception(ec); }
241 }
242#endif // _WEBSOCKETPP_NO_EXCEPTIONS_
243
244 /// Set the proxy timeout duration (exception free)
245 /**
246 * Duration is in milliseconds. Default value is based on the transport
247 * config
248 *
249 * @param duration The number of milliseconds to wait before aborting the
250 * proxy connection.
251 *
252 * @param ec A status value
253 */
254 void set_proxy_timeout(long duration, lib::error_code & ec) {
255 if (!m_proxy_data) {
256 ec = make_error_code(websocketpp::error::invalid_state);
257 return;
258 }
259
260 m_proxy_data->timeout_proxy = duration;
261 ec = lib::error_code();
262 }
263
264#ifndef _WEBSOCKETPP_NO_EXCEPTIONS_
265 /// Set the proxy timeout duration (exception)
266 void set_proxy_timeout(long duration) {
267 lib::error_code ec;
268 set_proxy_timeout(duration,ec);
269 if (ec) { throw exception(ec); }
270 }
271#endif // _WEBSOCKETPP_NO_EXCEPTIONS_
272
273 std::string const & get_proxy() const {
274 return m_proxy;
275 }
276
277 /// Get the remote endpoint address
278 /**
279 * The iostream transport has no information about the ultimate remote
280 * endpoint. It will return the string "iostream transport". To indicate
281 * this.
282 *
283 * TODO: allow user settable remote endpoint addresses if this seems useful
284 *
285 * @return A string identifying the address of the remote endpoint
286 */
287 std::string get_remote_endpoint() const {
288 lib::error_code ec;
289
290 std::string ret = socket_con_type::get_remote_endpoint(ec);
291
292 if (ec) {
293 m_elog->write(log::elevel::info,ret);
294 return "Unknown";
295 } else {
296 return ret;
297 }
298 }
299
300 /// Get the connection handle
302 return m_connection_hdl;
303 }
304
305 /// Call back a function after a period of time.
306 /**
307 * Sets a timer that calls back a function after the specified period of
308 * milliseconds. Returns a handle that can be used to cancel the timer.
309 * A cancelled timer will return the error code error::operation_aborted
310 * A timer that expired will return no error.
311 *
312 * @param duration Length of time to wait in milliseconds
313 *
314 * @param callback The function to call back when the timer has expired
315 *
316 * @return A handle that can be used to cancel the timer if it is no longer
317 * needed.
318 */
319 timer_ptr set_timer(long duration, timer_handler callback) {
320 timer_ptr new_timer(
321 new lib::asio::steady_timer(
322 *m_io_context,
323 lib::asio::milliseconds(duration))
324 );
325
326 if (config::enable_multithreading) {
327 new_timer->async_wait(lib::asio::bind_executor(*m_strand, lib::bind(
329 new_timer,
330 callback,
331 lib::placeholders::_1
332 )));
333 } else {
334 new_timer->async_wait(lib::bind(
336 new_timer,
337 callback,
338 lib::placeholders::_1
339 ));
340 }
341
342 return new_timer;
343 }
344
345 /// Timer callback
346 /**
347 * The timer pointer is included to ensure the timer isn't destroyed until
348 * after it has expired.
349 *
350 * TODO: candidate for protected status
351 *
352 * @param post_timer Pointer to the timer in question
353 * @param callback The function to call back
354 * @param ec The status code
355 */
357 lib::asio::error_code const & ec)
358 {
359 if (ec) {
360 if (ec == lib::asio::error::operation_aborted) {
361 callback(make_error_code(transport::error::operation_aborted));
362 } else {
363 log_err(log::elevel::info,"asio handle_timer",ec);
365 }
366 } else {
367 callback(lib::error_code());
368 }
369 }
370
371 /// Get a pointer to this connection's strand
373 return m_strand;
374 }
375
376 /// Get the internal transport error code for a closed/failed connection
377 /**
378 * Retrieves a machine readable detailed error code indicating the reason
379 * that the connection was closed or failed. Valid only after the close or
380 * fail handler is called.
381 *
382 * Primarily used if you are using mismatched asio / system_error
383 * implementations such as `boost::asio` with `std::system_error`. In these
384 * cases the transport error type is different than the library error type
385 * and some WebSocket++ functions that return transport errors via the
386 * library error code type will be coerced into a catch all `pass_through`
387 * or `tls_error` error. This method will return the original machine
388 * readable transport error in the native type.
389 *
390 * @since 0.7.0
391 *
392 * @return Error code indicating the reason the connection was closed or
393 * failed
394 */
395 lib::asio::error_code get_transport_ec() const {
396 return m_tec;
397 }
398
399 /// Initialize transport for reading
400 /**
401 * init_asio is called once immediately after construction to initialize
402 * Asio components to the io_context
403 *
404 * The transport initialization sequence consists of the following steps:
405 * - Pre-init: the underlying socket is initialized to the point where
406 * bytes may be written. No bytes are actually written in this stage
407 * - Proxy negotiation: if a proxy is set, a request is made to it to start
408 * a tunnel to the final destination. This stage ends when the proxy is
409 * ready to forward the
410 * next byte to the remote endpoint.
411 * - Post-init: Perform any i/o with the remote endpoint, such as setting up
412 * tunnels for encryption. This stage ends when the connection is ready to
413 * read or write the WebSocket handshakes. At this point the original
414 * callback function is called.
415 */
416protected:
417 void init(init_handler callback) {
418 if (m_alog->static_test(log::alevel::devel)) {
419 m_alog->write(log::alevel::devel,"asio connection init");
420 }
421
422 // TODO: pre-init timeout. Right now no implemented socket policies
423 // actually have an asyncronous pre-init
424
425 socket_con_type::pre_init(
426 lib::bind(
427 &type::handle_pre_init,
429 callback,
430 lib::placeholders::_1
431 )
432 );
433 }
434
435 /// initialize the proxy buffers and http parsers
436 /**
437 *
438 * @param authority The address of the server we want the proxy to tunnel to
439 * in the format of a URI authority (host:port)
440 *
441 * @return Status code indicating what errors occurred, if any
442 */
443 lib::error_code proxy_init(std::string const & authority) {
444 if (!m_proxy_data) {
445 return websocketpp::error::make_error_code(
447 }
448 m_proxy_data->req.set_version("HTTP/1.1");
449 m_proxy_data->req.set_method("CONNECT");
450
451 m_proxy_data->req.set_uri(authority);
452 m_proxy_data->req.replace_header("Host",authority);
453
454 return lib::error_code();
455 }
456
457 /// Finish constructing the transport
458 /**
459 * init_asio is called once immediately after construction to initialize
460 * Asio components to the io_context.
461 *
462 * @param io_context A pointer to the io_context to register with this
463 * connection
464 *
465 * @return Status code for the success or failure of the initialization
466 */
467 lib::error_code init_asio (io_context_ptr io_context) {
468 m_io_context = io_context;
469
470 if (config::enable_multithreading) {
471 m_strand.reset(new lib::asio::io_context::strand(*io_context));
472 }
473
474 lib::error_code ec = socket_con_type::init_asio(io_context, m_strand,
475 m_is_server);
476
477 return ec;
478 }
479
480 void handle_pre_init(init_handler callback, lib::error_code const & ec) {
481 if (m_alog->static_test(log::alevel::devel)) {
482 m_alog->write(log::alevel::devel,"asio connection handle pre_init");
483 }
484
485 if (m_tcp_pre_init_handler) {
486 m_tcp_pre_init_handler(m_connection_hdl);
487 }
488
489 if (ec) {
490 callback(ec);
491 }
492
493 // If we have a proxy set issue a proxy connect, otherwise skip to
494 // post_init
495 if (!m_proxy.empty()) {
496 proxy_write(callback);
497 } else {
498 post_init(callback);
499 }
500 }
501
502 void post_init(init_handler callback) {
503 if (m_alog->static_test(log::alevel::devel)) {
504 m_alog->write(log::alevel::devel,"asio connection post_init");
505 }
506
507 timer_ptr post_timer;
508
509 if (config::timeout_socket_post_init > 0) {
510 post_timer = set_timer(
511 config::timeout_socket_post_init,
512 lib::bind(
513 &type::handle_post_init_timeout,
514 get_shared(),
515 post_timer,
516 callback,
517 lib::placeholders::_1
518 )
519 );
520 }
521
522 socket_con_type::post_init(
523 lib::bind(
526 post_timer,
527 callback,
528 lib::placeholders::_1
529 )
530 );
531 }
532
533 /// Post init timeout callback
534 /**
535 * The timer pointer is included to ensure the timer isn't destroyed until
536 * after it has expired.
537 *
538 * @param post_timer Pointer to the timer in question
539 * @param callback The function to call back
540 * @param ec The status code
541 */
543 lib::error_code const & ec)
544 {
545 lib::error_code ret_ec;
546
547 if (ec) {
549 m_alog->write(log::alevel::devel,
550 "asio post init timer cancelled");
551 return;
552 }
553
554 log_err(log::elevel::devel,"asio handle_post_init_timeout",ec);
555 ret_ec = ec;
556 } else {
557 if (socket_con_type::get_ec()) {
558 ret_ec = socket_con_type::get_ec();
559 } else {
560 ret_ec = make_error_code(transport::error::timeout);
561 }
562 }
563
564 m_alog->write(log::alevel::devel, "Asio transport post-init timed out");
566 callback(ret_ec);
567 }
568
569 /// Post init timeout callback
570 /**
571 * The timer pointer is included to ensure the timer isn't destroyed until
572 * after it has expired.
573 *
574 * @param post_timer Pointer to the timer in question
575 * @param callback The function to call back
576 * @param ec The status code
577 */
578 void handle_post_init(timer_ptr post_timer, init_handler callback,
579 lib::error_code const & ec)
580 {
582 (post_timer && lib::asio::is_neg(post_timer->expiry() - timer_ptr::element_type::clock_type::now())))
583 {
584 m_alog->write(log::alevel::devel,"post_init cancelled");
585 return;
586 }
587
588 if (post_timer) {
589 post_timer->cancel();
590 }
591
592 if (m_alog->static_test(log::alevel::devel)) {
593 m_alog->write(log::alevel::devel,"asio connection handle_post_init");
594 }
595
596 if (m_tcp_post_init_handler) {
597 m_tcp_post_init_handler(m_connection_hdl);
598 }
599
600 callback(ec);
601 }
602
603 void proxy_write(init_handler callback) {
604 if (m_alog->static_test(log::alevel::devel)) {
605 m_alog->write(log::alevel::devel,"asio connection proxy_write");
606 }
607
608 if (!m_proxy_data) {
609 m_elog->write(log::elevel::library,
610 "assertion failed: !m_proxy_data in asio::connection::proxy_write");
612 return;
613 }
614
615 m_proxy_data->write_buf = m_proxy_data->req.raw();
616
617 m_bufs.push_back(lib::asio::buffer(m_proxy_data->write_buf.data(),
618 m_proxy_data->write_buf.size()));
619
620 m_alog->write(log::alevel::devel,m_proxy_data->write_buf);
621
622 // Set a timer so we don't wait forever for the proxy to respond
623 m_proxy_data->timer = this->set_timer(
624 m_proxy_data->timeout_proxy,
625 lib::bind(
626 &type::handle_proxy_timeout,
628 callback,
629 lib::placeholders::_1
630 )
631 );
632
633 // Send proxy request
634 if (config::enable_multithreading) {
635 lib::asio::async_write(
636 socket_con_type::get_next_layer(),
637 m_bufs,
638 lib::asio::bind_executor(*m_strand, lib::bind(
639 &type::handle_proxy_write, get_shared(),
640 callback,
641 lib::placeholders::_1
642 ))
643 );
644 } else {
645 lib::asio::async_write(
646 socket_con_type::get_next_layer(),
647 m_bufs,
648 lib::bind(
649 &type::handle_proxy_write, get_shared(),
650 callback,
651 lib::placeholders::_1
652 )
653 );
654 }
655 }
656
657 void handle_proxy_timeout(init_handler callback, lib::error_code const & ec)
658 {
660 m_alog->write(log::alevel::devel,
661 "asio handle_proxy_write timer cancelled");
662 return;
663 } else if (ec) {
664 log_err(log::elevel::devel,"asio handle_proxy_write",ec);
665 callback(ec);
666 } else {
667 m_alog->write(log::alevel::devel,
668 "asio handle_proxy_write timer expired");
670 callback(make_error_code(transport::error::timeout));
671 }
672 }
673
674 void handle_proxy_write(init_handler callback,
675 lib::asio::error_code const & ec)
676 {
677 if (m_alog->static_test(log::alevel::devel)) {
678 m_alog->write(log::alevel::devel,
679 "asio connection handle_proxy_write");
680 }
681
682 m_bufs.clear();
683
684 // Timer expired or the operation was aborted for some reason.
685 // Whatever aborted it will be issuing the callback so we are safe to
686 // return
687 if (ec == lib::asio::error::operation_aborted ||
688 lib::asio::is_neg(m_proxy_data->timer->expiry() - timer_ptr::element_type::clock_type::now()))
689 {
690 m_elog->write(log::elevel::devel,"write operation aborted");
691 return;
692 }
693
694 if (ec) {
695 log_err(log::elevel::info,"asio handle_proxy_write",ec);
696 m_proxy_data->timer->cancel();
698 return;
699 }
700
701 proxy_read(callback);
702 }
703
704 void proxy_read(init_handler callback) {
705 if (m_alog->static_test(log::alevel::devel)) {
706 m_alog->write(log::alevel::devel,"asio connection proxy_read");
707 }
708
709 if (!m_proxy_data) {
710 m_elog->write(log::elevel::library,
711 "assertion failed: !m_proxy_data in asio::connection::proxy_read");
713 return;
714 }
715
716 if (config::enable_multithreading) {
717 lib::asio::async_read_until(
718 socket_con_type::get_next_layer(),
719 m_proxy_data->read_buf,
720 "\r\n\r\n",
721 lib::asio::bind_executor(*m_strand, lib::bind(
722 &type::handle_proxy_read, get_shared(),
723 callback,
724 lib::placeholders::_1, lib::placeholders::_2
725 ))
726 );
727 } else {
728 lib::asio::async_read_until(
729 socket_con_type::get_next_layer(),
730 m_proxy_data->read_buf,
731 "\r\n\r\n",
732 lib::bind(
733 &type::handle_proxy_read, get_shared(),
734 callback,
735 lib::placeholders::_1, lib::placeholders::_2
736 )
737 );
738 }
739 }
740
741 /// Proxy read callback
742 /**
743 * @param init_handler The function to call back
744 * @param ec The status code
745 * @param bytes_transferred The number of bytes read
746 */
748 lib::asio::error_code const & ec, size_t)
749 {
750 if (m_alog->static_test(log::alevel::devel)) {
751 m_alog->write(log::alevel::devel,
752 "asio connection handle_proxy_read");
753 }
754
755 // Timer expired or the operation was aborted for some reason.
756 // Whatever aborted it will be issuing the callback so we are safe to
757 // return
758 if (ec == lib::asio::error::operation_aborted ||
759 lib::asio::is_neg(m_proxy_data->timer->expiry() - timer_ptr::element_type::clock_type::now()))
760 {
761 m_elog->write(log::elevel::devel,"read operation aborted");
762 return;
763 }
764
765 // At this point there is no need to wait for the timer anymore
766 m_proxy_data->timer->cancel();
767
768 if (ec) {
769 m_elog->write(log::elevel::info,
770 "asio handle_proxy_read error: "+ec.message());
772 } else {
773 if (!m_proxy_data) {
774 m_elog->write(log::elevel::library,
775 "assertion failed: !m_proxy_data in asio::connection::handle_proxy_read");
777 return;
778 }
779
780 // todo: switch this to using non-istream based consume
781 std::istream input(&m_proxy_data->read_buf);
782
783 lib::error_code istream_ec;
784 m_proxy_data->res.consume(input, istream_ec);
785 if (istream_ec) {
786 // there was an error while reading from the proxy
787 m_elog->write(log::elevel::info,
788 "An HTTP handling error occurred while reading a response from the proxy server: "+istream_ec.message());
789 // todo: do we need to translate this error?
790 callback(istream_ec);
791 return;
792 }
793
794 if (!m_proxy_data->res.headers_ready()) {
795 // we read until the headers were done in theory but apparently
796 // they aren't. Internal endpoint error.
798 return;
799 }
800
801 m_alog->write(log::alevel::devel,m_proxy_data->res.raw());
802
803 if (m_proxy_data->res.get_status_code() != http::status_code::ok) {
804 // got an error response back
805 // TODO: expose this error in a programmatically accessible way?
806 // if so, see below for an option on how to do this.
807 std::stringstream s;
808 s << "Proxy connection error: "
809 << m_proxy_data->res.get_status_code()
810 << " ("
811 << m_proxy_data->res.get_status_msg()
812 << ")";
813 m_elog->write(log::elevel::info,s.str());
815 return;
816 }
817
818 // we have successfully established a connection to the proxy, now
819 // we can continue and the proxy will transparently forward the
820 // WebSocket connection.
821
822 // TODO: decide if we want an on_proxy callback that would allow
823 // access to the proxy response.
824
825 // free the proxy buffers and req/res objects as they aren't needed
826 // anymore
827 m_proxy_data.reset();
828
829 // Continue with post proxy initialization
830 post_init(callback);
831 }
832 }
833
834 /// read at least num_bytes bytes into buf and then call handler.
835 void async_read_at_least(size_t num_bytes, char *buf, size_t len,
836 read_handler handler)
837 {
838 if (m_alog->static_test(log::alevel::devel)) {
839 std::stringstream s;
840 s << "asio async_read_at_least: " << num_bytes;
841 m_alog->write(log::alevel::devel,s.str());
842 }
843
844 // TODO: safety vs speed ?
845 // maybe move into an if devel block
846 /*if (num_bytes > len) {
847 m_elog->write(log::elevel::devel,
848 "asio async_read_at_least error::invalid_num_bytes");
849 handler(make_error_code(transport::error::invalid_num_bytes),
850 size_t(0));
851 return;
852 }*/
853
854 if (config::enable_multithreading) {
855 lib::asio::async_read(
856 socket_con_type::get_socket(),
857 lib::asio::buffer(buf,len),
858 lib::asio::transfer_at_least(num_bytes),
859 lib::asio::bind_executor(*m_strand, make_custom_alloc_handler(
860 m_read_handler_allocator,
861 lib::bind(
862 &type::handle_async_read, get_shared(),
863 handler,
864 lib::placeholders::_1, lib::placeholders::_2
865 )
866 ))
867 );
868 } else {
869 lib::asio::async_read(
870 socket_con_type::get_socket(),
871 lib::asio::buffer(buf,len),
872 lib::asio::transfer_at_least(num_bytes),
873 make_custom_alloc_handler(
874 m_read_handler_allocator,
875 lib::bind(
876 &type::handle_async_read, get_shared(),
877 handler,
878 lib::placeholders::_1, lib::placeholders::_2
879 )
880 )
881 );
882 }
883
884 }
885
886 void handle_async_read(read_handler handler, lib::asio::error_code const & ec,
887 size_t bytes_transferred)
888 {
889 m_alog->write(log::alevel::devel, "asio con handle_async_read");
890
891 // translate asio error codes into more lib::error_codes
892 lib::error_code tec;
893 if (ec == lib::asio::error::eof) {
894 tec = make_error_code(transport::error::eof);
895 } else if (ec) {
896 // We don't know much more about the error at this point. As our
897 // socket/security policy if it knows more:
898 tec = socket_con_type::translate_ec(ec);
899 m_tec = ec;
900
901 if (tec == transport::error::tls_error ||
903 {
904 // These are aggregate/catch all errors. Log some human readable
905 // information to the info channel to give library users some
906 // more details about why the upstream method may have failed.
907 log_err(log::elevel::info,"asio async_read_at_least",ec);
908 }
909 }
910 if (handler) {
911 handler(tec,bytes_transferred);
912 } else {
913 // This can happen in cases where the connection is terminated while
914 // the transport is waiting on a read.
915 m_alog->write(log::alevel::devel,
916 "handle_async_read called with null read handler");
917 }
918 }
919
920 /// Initiate a potentially asyncronous write of the given buffer
921 void async_write(const char* buf, size_t len, write_handler handler) {
922 m_bufs.push_back(lib::asio::buffer(buf,len));
923
924 if (config::enable_multithreading) {
925 lib::asio::async_write(
926 socket_con_type::get_socket(),
927 m_bufs,
928 lib::asio::bind_executor(*m_strand, make_custom_alloc_handler(
929 m_write_handler_allocator,
930 lib::bind(
931 &type::handle_async_write, get_shared(),
932 handler,
933 lib::placeholders::_1, lib::placeholders::_2
934 )
935 ))
936 );
937 } else {
938 lib::asio::async_write(
939 socket_con_type::get_socket(),
940 m_bufs,
941 make_custom_alloc_handler(
942 m_write_handler_allocator,
943 lib::bind(
944 &type::handle_async_write, get_shared(),
945 handler,
946 lib::placeholders::_1, lib::placeholders::_2
947 )
948 )
949 );
950 }
951 }
952
953 /// Initiate a potentially asyncronous write of the given buffers
954 void async_write(std::vector<buffer> const & bufs, write_handler handler) {
955 std::vector<buffer>::const_iterator it;
956
957 // todo: check if this underlying socket supports efficient scatter/gather io
958 // if not, coalesce buffers before we send to the underlying transport.
959
960 for (it = bufs.begin(); it != bufs.end(); ++it) {
961 m_bufs.push_back(lib::asio::buffer((*it).buf,(*it).len));
962 }
963
964 if (config::enable_multithreading) {
965 lib::asio::async_write(
966 socket_con_type::get_socket(),
967 m_bufs,
968 lib::asio::bind_executor(*m_strand, make_custom_alloc_handler(
969 m_write_handler_allocator,
970 lib::bind(
971 &type::handle_async_write, get_shared(),
972 handler,
973 lib::placeholders::_1, lib::placeholders::_2
974 )
975 ))
976 );
977 } else {
978 lib::asio::async_write(
979 socket_con_type::get_socket(),
980 m_bufs,
981 make_custom_alloc_handler(
982 m_write_handler_allocator,
983 lib::bind(
984 &type::handle_async_write, get_shared(),
985 handler,
986 lib::placeholders::_1, lib::placeholders::_2
987 )
988 )
989 );
990 }
991 }
992
993 /// Async write callback
994 /**
995 * @param ec The status code
996 * @param bytes_transferred The number of bytes read
997 */
998 void handle_async_write(write_handler handler, lib::asio::error_code const & ec, size_t) {
999 m_bufs.clear();
1000 lib::error_code tec;
1001 if (ec) {
1002 log_err(log::elevel::info,"asio async_write",ec);
1003 tec = make_error_code(transport::error::pass_through);
1004 }
1005 if (handler) {
1006 handler(tec);
1007 } else {
1008 // This can happen in cases where the connection is terminated while
1009 // the transport is waiting on a read.
1010 m_alog->write(log::alevel::devel,
1011 "handle_async_write called with null write handler");
1012 }
1013 }
1014
1015 /// Set Connection Handle
1016 /**
1017 * See common/connection_hdl.hpp for information
1018 *
1019 * @param hdl A connection_hdl that the transport will use to refer
1020 * to itself
1021 */
1023 m_connection_hdl = hdl;
1024 socket_con_type::set_handle(hdl);
1025 }
1026
1027 /// Trigger the on_interrupt handler
1028 /**
1029 * This needs to be thread safe
1030 */
1031 lib::error_code interrupt(interrupt_handler handler) {
1032 if (config::enable_multithreading) {
1033 lib::asio::post(m_io_context->get_executor(), lib::asio::bind_executor(*m_strand, handler));
1034 } else {
1035 lib::asio::post(m_io_context->get_executor(), handler);
1036 }
1037 return lib::error_code();
1038 }
1039
1040 lib::error_code dispatch(dispatch_handler handler) {
1041 if (config::enable_multithreading) {
1042 lib::asio::post(m_io_context->get_executor(), lib::asio::bind_executor(*m_strand, handler));
1043 } else {
1044 lib::asio::post(m_io_context->get_executor(), handler);
1045 }
1046 return lib::error_code();
1047 }
1048
1049 /*void handle_interrupt(interrupt_handler handler) {
1050 handler();
1051 }*/
1052
1053 /// close and clean up the underlying socket
1055 if (m_alog->static_test(log::alevel::devel)) {
1056 m_alog->write(log::alevel::devel,"asio connection async_shutdown");
1057 }
1058
1059 timer_ptr shutdown_timer;
1060 shutdown_timer = set_timer(
1061 config::timeout_socket_shutdown,
1062 lib::bind(
1063 &type::handle_async_shutdown_timeout,
1064 get_shared(),
1065 shutdown_timer,
1066 callback,
1067 lib::placeholders::_1
1068 )
1069 );
1070
1071 socket_con_type::async_shutdown(
1072 lib::bind(
1073 &type::handle_async_shutdown,
1075 shutdown_timer,
1076 callback,
1077 lib::placeholders::_1
1078 )
1079 );
1080 }
1081
1082 /// Async shutdown timeout handler
1083 /**
1084 * @param shutdown_timer A pointer to the timer to keep it in scope
1085 * @param callback The function to call back
1086 * @param ec The status code
1087 */
1089 lib::error_code const & ec)
1090 {
1091 lib::error_code ret_ec;
1092
1093 if (ec) {
1095 m_alog->write(log::alevel::devel,
1096 "asio socket shutdown timer cancelled");
1097 return;
1098 }
1099
1100 log_err(log::elevel::devel,"asio handle_async_shutdown_timeout",ec);
1101 ret_ec = ec;
1102 } else {
1103 ret_ec = make_error_code(transport::error::timeout);
1104 }
1105
1106 m_alog->write(log::alevel::devel,
1107 "Asio transport socket shutdown timed out");
1109 callback(ret_ec);
1110 }
1111
1112 void handle_async_shutdown(timer_ptr shutdown_timer, shutdown_handler
1113 callback, lib::asio::error_code const & ec)
1114 {
1115 if (ec == lib::asio::error::operation_aborted ||
1116 lib::asio::is_neg(shutdown_timer->expiry() - timer_ptr::element_type::clock_type::now()))
1117 {
1118 m_alog->write(log::alevel::devel,"async_shutdown cancelled");
1119 return;
1120 }
1121
1122 shutdown_timer->cancel();
1123
1124 lib::error_code tec;
1125 if (ec) {
1126 if (ec == lib::asio::error::not_connected) {
1127 // The socket was already closed when we tried to close it. This
1128 // happens periodically (usually if a read or write fails
1129 // earlier and if it is a real error will be caught at another
1130 // level of the stack.
1131 } else {
1132 // We don't know anything more about this error, give our
1133 // socket/security policy a crack at it.
1134 tec = socket_con_type::translate_ec(ec);
1135 m_tec = ec;
1136
1137 // all other errors are effectively pass through errors of
1138 // some sort so print some detail on the info channel for
1139 // library users to look up if needed.
1140 log_err(log::elevel::info,"asio async_shutdown",ec);
1141 }
1142 } else {
1143 if (m_alog->static_test(log::alevel::devel)) {
1144 m_alog->write(log::alevel::devel,
1145 "asio con handle_async_shutdown");
1146 }
1147 }
1148 callback(tec);
1149 }
1150
1151 /// Cancel the underlying socket and log any errors
1153 lib::asio::error_code cec = socket_con_type::cancel_socket();
1154 if (cec) {
1155 if (cec == lib::asio::error::operation_not_supported) {
1156 // cancel not supported on this OS, ignore and log at dev level
1157 m_alog->write(log::alevel::devel, "socket cancel not supported");
1158 } else {
1159 log_err(log::elevel::warn, "socket cancel failed", cec);
1160 }
1161 }
1162 }
1163
1164private:
1165 /// Convenience method for logging the code and message for an error_code
1166 template <typename error_type>
1167 void log_err(log::level l, const char * msg, const error_type & ec) {
1168 std::stringstream s;
1169 s << msg << " error: " << ec << " (" << ec.message() << ")";
1170 m_elog->write(l,s.str());
1171 }
1172
1173 // static settings
1174 const bool m_is_server;
1175 lib::shared_ptr<alog_type> m_alog;
1176 lib::shared_ptr<elog_type> m_elog;
1177
1178 struct proxy_data {
1179 proxy_data() : timeout_proxy(config::timeout_proxy) {}
1180
1181 request_type req;
1182 response_type res;
1183 std::string write_buf;
1184 lib::asio::streambuf read_buf;
1185 long timeout_proxy;
1186 timer_ptr timer;
1187 };
1188
1189 std::string m_proxy;
1190 lib::shared_ptr<proxy_data> m_proxy_data;
1191
1192 // transport resources
1193 io_context_ptr m_io_context;
1194 strand_ptr m_strand;
1195 connection_hdl m_connection_hdl;
1196
1197 std::vector<lib::asio::const_buffer> m_bufs;
1198
1199 /// Detailed internal error code
1200 lib::asio::error_code m_tec;
1201
1202 // Handlers
1203 tcp_init_handler m_tcp_pre_init_handler;
1204 tcp_init_handler m_tcp_post_init_handler;
1205
1206 handler_allocator m_read_handler_allocator;
1207 handler_allocator m_write_handler_allocator;
1208};
1209
1210
1211} // namespace asio
1212} // namespace transport
1213} // namespace websocketpp
1214
1215#endif // WEBSOCKETPP_TRANSPORT_ASIO_CON_HPP
#define _WEBSOCKETPP_CPP11_FUNCTIONAL_
#define _WEBSOCKETPP_CPP11_THREAD_
#define _WEBSOCKETPP_CPP11_MEMORY_
#define _WEBSOCKETPP_CPP11_SYSTEM_ERROR_
Concurrency policy that uses std::mutex / boost::mutex.
Definition basic.hpp:37
Stub for user supplied base class.
Stub for user supplied base class.
Stub class for use when disabling permessage_deflate extension.
Definition disabled.hpp:53
err_str_pair negotiate(http::attribute_list const &)
Negotiate extension.
Definition disabled.hpp:65
std::string generate_offer() const
Generate extension offer.
Definition disabled.hpp:99
lib::error_code init(bool)
Initialize state.
Definition disabled.hpp:76
HTTP parser error category.
An exception type specific to HTTP errors.
header_list const & get_headers() const
Return a list of all HTTP headers.
Definition parser.hpp:211
std::string const & get_body() const
Get HTTP body.
Definition parser.hpp:515
bool body_ready() const
Check if the parser is done parsing the body.
Definition parser.hpp:618
void set_max_body_size(size_t value)
Set body size limit.
Definition parser.hpp:555
bool prepare_body(lib::error_code &ec)
Prepare the parser to begin parsing body data.
Definition parser.hpp:143
std::string raw_headers() const
Generate and return the HTTP headers as a string.
Definition parser.hpp:215
size_t process_body(char const *buf, size_t len, lib::error_code &ec)
Process body data.
Definition parser.hpp:172
std::string const & get_version() const
Get the HTTP version string.
Definition parser.hpp:410
size_t get_max_body_size() const
Get body size limit.
Definition parser.hpp:542
lib::error_code process_header(std::string::iterator begin, std::string::iterator end)
Process a header line.
Definition parser.hpp:191
Stores, parses, and manipulates HTTP requests.
Definition request.hpp:50
std::string raw() const
Returns the full raw request (including the body).
Definition request.hpp:195
std::string const & get_uri() const
Return the requested URI.
Definition request.hpp:123
std::string const & get_method() const
Return the request method.
Definition request.hpp:107
bool ready() const
Returns whether or not the request is ready for reading.
Definition request.hpp:85
size_t consume(char const *buf, size_t len, lib::error_code &ec)
Process bytes in the input buffer.
Definition request.hpp:41
std::string raw_head() const
Returns the raw request headers only (similar to an HTTP HEAD request).
Definition request.hpp:205
Stores, parses, and manipulates HTTP responses.
Definition response.hpp:57
std::string raw() const
Returns the full raw response.
Definition response.hpp:246
size_t consume(char const *buf, size_t len, lib::error_code &ec)
Process bytes in the input buffer.
Definition response.hpp:42
bool headers_ready() const
Returns true if the response headers are fully parsed.
Definition response.hpp:149
size_t consume(std::istream &s, lib::error_code &ec)
Process bytes in the input buffer (istream version).
Definition response.hpp:189
lib::error_code set_status(status_code::value code)
Set response status code and message.
Definition response.hpp:259
bool ready() const
Returns true if the response is ready.
Definition response.hpp:144
const std::string & get_status_msg() const
Return the response status message.
Definition response.hpp:190
status_code::value get_status_code() const
Return the response status code.
Definition response.hpp:185
Basic logger that outputs to an ostream.
Definition basic.hpp:59
void write(level channel, char const *msg)
Write a cstring message to the given channel.
Definition basic.hpp:151
basic(basic< concurrency, names > const &other)
Copy constructor.
Definition basic.hpp:87
~basic()
Destructor.
Definition basic.hpp:84
bool recycle(message *)
Recycle a message.
Definition alloc.hpp:80
message_ptr get_message(frame::opcode::value op, size_t size)
Get a message buffer with specified size and opcode.
Definition alloc.hpp:66
message_ptr get_message()
Get an empty message buffer.
Definition alloc.hpp:55
con_msg_man_ptr get_manager() const
Get a pointer to a connection message manager.
Definition alloc.hpp:96
Represents a buffer for a single WebSocket message.
Definition message.hpp:84
message(const con_msg_man_ptr manager, frame::opcode::value op, size_t size=128)
Construct a message and fill in some values.
Definition message.hpp:107
std::string & get_raw_payload()
Get a non-const reference to the payload string.
Definition message.hpp:254
bool recycle()
Recycle the message.
Definition message.hpp:316
bool get_compressed() const
Return whether or not the message is flagged as compressed.
Definition message.hpp:143
bool get_terminal() const
Get whether or not the message is terminal.
Definition message.hpp:169
std::string const & get_header() const
Return the prepared frame header.
Definition message.hpp:224
void set_payload(void const *payload, size_t len)
Set payload data.
Definition message.hpp:275
bool get_fin() const
Read the fin bit.
Definition message.hpp:195
void append_payload(void const *payload, size_t len)
Append payload data.
Definition message.hpp:298
void set_opcode(frame::opcode::value op)
Set the opcode.
Definition message.hpp:215
void set_prepared(bool value)
Set or clear the flag that indicates that the message has been prepared.
Definition message.hpp:135
frame::opcode::value get_opcode() const
Return the message opcode.
Definition message.hpp:210
void set_terminal(bool value)
Set the terminal flag.
Definition message.hpp:181
bool get_prepared() const
Return whether or not the message has been prepared for sending.
Definition message.hpp:125
void set_compressed(bool value)
Set or clear the compression flag.
Definition message.hpp:156
message(const con_msg_man_ptr manager)
Construct an empty message.
Definition message.hpp:96
void set_fin(bool value)
Set the fin bit.
Definition message.hpp:205
std::string const & get_payload() const
Get a reference to the payload string.
Definition message.hpp:246
Thread safe stub "random" integer generator.
Definition none.hpp:46
int_type operator()()
advances the engine's state and returns the generated value
Definition none.hpp:51
Server endpoint role based on the given config.
Basic ASIO endpoint socket component.
Definition none.hpp:318
Asio based connection transport component.
void set_proxy_timeout(long duration)
Set the proxy timeout duration (exception).
void set_tcp_post_init_handler(tcp_init_handler h)
Sets the tcp post init handler.
void set_proxy_timeout(long duration, lib::error_code &ec)
Set the proxy timeout duration (exception free).
config::elog_type elog_type
Type of this transport's error logging policy.
strand_ptr get_strand()
Get a pointer to this connection's strand.
void async_read_at_least(size_t num_bytes, char *buf, size_t len, read_handler handler)
read at least num_bytes bytes into buf and then call handler.
socket_con_type::ptr socket_con_ptr
Type of a shared pointer to the socket connection component.
lib::error_code interrupt(interrupt_handler handler)
Trigger the on_interrupt handler.
lib::shared_ptr< lib::asio::io_context::strand > strand_ptr
Type of a pointer to the Asio io_context::strand being used.
config::alog_type alog_type
Type of this transport's access logging policy.
lib::asio::io_context * io_context_ptr
Type of a pointer to the Asio io_context being used.
void handle_async_write(write_handler handler, lib::asio::error_code const &ec, size_t)
Async write callback.
void handle_timer(timer_ptr, timer_handler callback, lib::asio::error_code const &ec)
Timer callback.
void handle_post_init(timer_ptr post_timer, init_handler callback, lib::error_code const &ec)
Post init timeout callback.
lib::error_code init_asio(io_context_ptr io_context)
Finish constructing the transport.
void async_shutdown(shutdown_handler callback)
close and clean up the underlying socket
lib::asio::error_code get_transport_ec() const
Get the internal transport error code for a closed/failed connection.
config::socket_type::socket_con_type socket_con_type
Type of the socket connection component.
void handle_post_init_timeout(timer_ptr, init_handler callback, lib::error_code const &ec)
Post init timeout callback.
connection< config > type
Type of this connection transport component.
void handle_async_shutdown_timeout(timer_ptr, init_handler callback, lib::error_code const &ec)
Async shutdown timeout handler.
lib::shared_ptr< lib::asio::steady_timer > timer_ptr
Type of a pointer to the Asio timer class.
void async_write(const char *buf, size_t len, write_handler handler)
Initiate a potentially asyncronous write of the given buffer.
void async_write(std::vector< buffer > const &bufs, write_handler handler)
Initiate a potentially asyncronous write of the given buffers.
lib::shared_ptr< type > ptr
Type of a shared pointer to this connection transport component.
timer_ptr set_timer(long duration, timer_handler callback)
Call back a function after a period of time.
void set_tcp_init_handler(tcp_init_handler h)
Sets the tcp pre init handler (deprecated).
void handle_proxy_read(init_handler callback, lib::asio::error_code const &ec, size_t)
Proxy read callback.
void set_uri(uri_ptr u)
Set uri hook.
std::string get_remote_endpoint() const
Get the remote endpoint address.
ptr get_shared()
Get a shared pointer to this component.
void cancel_socket_checked()
Cancel the underlying socket and log any errors.
void set_handle(connection_hdl hdl)
Set Connection Handle.
void set_tcp_pre_init_handler(tcp_init_handler h)
Sets the tcp pre init handler.
void init(init_handler callback)
Initialize transport for reading.
connection_hdl get_handle() const
Get the connection handle.
Asio based endpoint transport component.
Definition endpoint.hpp:54
lib::shared_ptr< lib::asio::executor_work_guard< lib::asio::io_context::executor_type > > work_guard_ptr
Type of a shared pointer to an io_context work object.
Definition endpoint.hpp:89
std::size_t run_one()
wraps the run_one method of the internal io_context object
Definition endpoint.hpp:671
socket_type::socket_con_type socket_con_type
Type of the socket connection component.
Definition endpoint.hpp:69
void stop_listening(lib::error_code &ec)
Stop listening (exception free).
Definition endpoint.hpp:546
config::socket_type socket_type
Type of the socket policy.
Definition endpoint.hpp:62
lib::shared_ptr< lib::asio::steady_timer > timer_ptr
Type of timer handle.
Definition endpoint.hpp:87
void async_connect(transport_con_ptr tcon, uri_ptr u, connect_handler cb)
Initiate a new connection.
Definition endpoint.hpp:874
void init_asio()
Initialize asio transport with internal io_context.
Definition endpoint.hpp:252
config::elog_type elog_type
Type of the error logging policy.
Definition endpoint.hpp:64
void init_logging(const lib::shared_ptr< alog_type > &a, const lib::shared_ptr< elog_type > &e)
Initialize logging.
Definition endpoint.hpp:848
lib::asio::io_context * io_context_ptr
Type of a pointer to the ASIO io_context being used.
Definition endpoint.hpp:81
bool is_secure() const
Return whether or not the endpoint produces secure connections.
Definition endpoint.hpp:172
lib::asio::ip::tcp::endpoint get_local_endpoint(lib::asio::error_code &ec)
Get local TCP endpoint.
Definition endpoint.hpp:399
void set_reuse_addr(bool value)
Sets whether to use the SO_REUSEADDR flag when opening listening sockets.
Definition endpoint.hpp:367
void set_tcp_init_handler(tcp_init_handler h)
Sets the tcp pre init handler (deprecated).
Definition endpoint.hpp:306
void handle_timer(timer_ptr, timer_handler callback, lib::asio::error_code const &ec)
Timer handler.
Definition endpoint.hpp:768
void start_perpetual()
Marks the endpoint as perpetual, stopping it from exiting when empty.
Definition endpoint.hpp:712
void stop()
wraps the stop method of the internal io_context object
Definition endpoint.hpp:676
std::size_t run()
wraps the run method of the internal io_context object
Definition endpoint.hpp:663
void set_tcp_post_init_handler(tcp_init_handler h)
Sets the tcp post init handler.
Definition endpoint.hpp:321
void set_listen_backlog(int backlog)
Sets the maximum length of the queue of pending connections.
Definition endpoint.hpp:346
bool stopped() const
wraps the stopped method of the internal io_context object
Definition endpoint.hpp:696
timer_ptr set_timer(long duration, timer_handler callback)
Call back a function after a period of time.
Definition endpoint.hpp:740
socket_con_type::ptr socket_con_ptr
Type of a shared pointer to the socket connection component.
Definition endpoint.hpp:71
lib::error_code init(transport_con_ptr tcon)
Initialize a connection.
asio::connection< config > transport_con_type
Definition endpoint.hpp:75
void init_asio(lib::error_code &ec)
Initialize asio transport with internal io_context (exception free).
Definition endpoint.hpp:229
void async_accept(transport_con_ptr tcon, accept_handler callback)
Accept the next connection attempt and assign it to con.
Definition endpoint.hpp:831
void listen(uint16_t port)
Set up endpoint for listening on a port.
Definition endpoint.hpp:607
endpoint< config > type
Type of this endpoint transport component.
Definition endpoint.hpp:57
void init_asio(io_context_ptr ptr, lib::error_code &ec)
initialize asio transport with external io_context (exception free)
Definition endpoint.hpp:185
config::concurrency_type concurrency_type
Type of the concurrency policy.
Definition endpoint.hpp:60
std::size_t poll()
wraps the poll method of the internal io_context object
Definition endpoint.hpp:681
void stop_perpetual()
Clears the endpoint's perpetual flag, allowing it to exit when empty.
Definition endpoint.hpp:724
void init_asio(io_context_ptr ptr)
initialize asio transport with external io_context
Definition endpoint.hpp:213
lib::shared_ptr< lib::asio::ip::tcp::acceptor > acceptor_ptr
Type of a shared pointer to the acceptor being used.
Definition endpoint.hpp:83
void listen(lib::asio::ip::tcp::endpoint const &ep)
Set up endpoint for listening manually.
Definition endpoint.hpp:569
lib::asio::io_context & get_io_context()
Retrieve a reference to the endpoint's io_context.
Definition endpoint.hpp:382
void handle_resolve_timeout(timer_ptr, connect_handler callback, lib::error_code const &ec)
DNS resolution timeout handler.
Definition endpoint.hpp:969
void listen(lib::asio::ip::tcp::endpoint const &ep, lib::error_code &ec)
Set up endpoint for listening manually (exception free).
Definition endpoint.hpp:416
transport_con_type::ptr transport_con_ptr
Definition endpoint.hpp:78
void reset()
wraps the restart method of the internal io_context object
Definition endpoint.hpp:691
void set_tcp_pre_bind_handler(tcp_pre_bind_handler h)
Sets the tcp pre bind handler.
Definition endpoint.hpp:278
config::alog_type alog_type
Type of the access logging policy.
Definition endpoint.hpp:66
void listen(InternetProtocol const &internet_protocol, uint16_t port)
Set up endpoint for listening with protocol and port.
Definition endpoint.hpp:589
void set_tcp_pre_init_handler(tcp_init_handler h)
Sets the tcp pre init handler.
Definition endpoint.hpp:292
void handle_connect_timeout(transport_con_ptr tcon, timer_ptr, connect_handler callback, lib::error_code const &ec)
Asio connect timeout handler.
void async_accept(transport_con_ptr tcon, accept_handler callback, lib::error_code &ec)
Accept the next connection attempt and assign it to con (exception free).
Definition endpoint.hpp:791
std::size_t poll_one()
wraps the poll_one method of the internal io_context object
Definition endpoint.hpp:686
void listen(InternetProtocol const &internet_protocol, uint16_t port, lib::error_code &ec)
Set up endpoint for listening with protocol and port (exception free).
Definition endpoint.hpp:471
void listen(uint16_t port, lib::error_code &ec)
Set up endpoint for listening on a port (exception free).
Definition endpoint.hpp:490
bool is_listening() const
Check if the endpoint is listening.
Definition endpoint.hpp:658
void stop_listening()
Stop listening.
Definition endpoint.hpp:647
lib::shared_ptr< lib::asio::ip::tcp::resolver > resolver_ptr
Type of a shared pointer to the resolver being used.
Definition endpoint.hpp:85
lib::function< lib::error_code(acceptor_ptr)> tcp_pre_bind_handler
Type of socket pre-bind handler.
Definition endpoint.hpp:92
lib::shared_ptr< type > ptr
Type of a shared pointer to this connection transport component.
connection_hdl get_handle() const
Get the connection handle.
config::alog_type alog_type
Type of this transport's access logging policy.
lib::error_code dispatch(dispatch_handler handler)
Call given handler back within the transport's event system (if present).
void async_shutdown(transport::shutdown_handler handler)
Perform cleanup on socket shutdown_handler.
void set_write_handler(write_handler h)
Sets the write handler.
void set_secure(bool value)
Set whether or not this connection is secure.
void set_shutdown_handler(shutdown_handler h)
Sets the shutdown handler.
connection< config > type
Type of this connection transport component.
config::elog_type elog_type
Type of this transport's error logging policy.
void fatal_error()
Signal transport error.
size_t read_some(char const *buf, size_t len)
Manual input supply (read some).
size_t read_all(char const *buf, size_t len)
Manual input supply (read all).
void async_write(char const *buf, size_t len, transport::write_handler handler)
Asyncronous Transport Write.
size_t readsome(char const *buf, size_t len)
Manual input supply (DEPRECATED).
config::concurrency_type concurrency_type
transport concurrency policy
void init(init_handler handler)
Initialize the connection transport.
timer_ptr set_timer(long, timer_handler)
Call back a function after a period of time.
friend std::istream & operator>>(std::istream &in, type &t)
Overloaded stream input operator.
void set_vector_write_handler(vector_write_handler h)
Sets the vectored write handler.
bool is_secure() const
Tests whether or not the underlying transport is secure.
std::string get_remote_endpoint() const
Get human readable remote endpoint address.
void set_handle(connection_hdl hdl)
Set Connection Handle.
void register_ostream(std::ostream *o)
Register a std::ostream with the transport for writing output.
void async_read_at_least(size_t num_bytes, char *buf, size_t len, read_handler handler)
Initiate an async_read for at least num_bytes bytes into buf.
void async_write(std::vector< buffer > const &bufs, transport::write_handler handler)
Asyncronous Transport Write (scatter-gather).
ptr get_shared()
Get a shared pointer to this component.
iostream::connection< config > transport_con_type
Definition endpoint.hpp:62
config::elog_type elog_type
Type of this endpoint's error logging policy.
Definition endpoint.hpp:56
void set_write_handler(write_handler h)
Sets the write handler.
Definition endpoint.hpp:134
void set_shutdown_handler(shutdown_handler h)
Sets the shutdown handler.
Definition endpoint.hpp:154
bool is_secure() const
Tests whether or not the underlying transport is secure.
Definition endpoint.hpp:116
lib::shared_ptr< type > ptr
Type of a pointer to this endpoint transport component.
Definition endpoint.hpp:51
transport_con_type::ptr transport_con_ptr
Definition endpoint.hpp:65
void async_connect(transport_con_ptr, uri_ptr, connect_handler cb)
Initiate a new connection.
Definition endpoint.hpp:183
lib::error_code init(transport_con_ptr tcon)
Initialize a connection.
Definition endpoint.hpp:197
void init_logging(lib::shared_ptr< alog_type > a, lib::shared_ptr< elog_type > e)
Initialize logging.
Definition endpoint.hpp:171
endpoint type
Type of this endpoint transport component.
Definition endpoint.hpp:49
void register_ostream(std::ostream *o)
Register a default output stream.
Definition endpoint.hpp:80
config::concurrency_type concurrency_type
Type of this endpoint's concurrency policy.
Definition endpoint.hpp:54
void set_secure(bool value)
Set whether or not endpoint can create secure connections.
Definition endpoint.hpp:102
config::alog_type alog_type
Type of this endpoint's access logging policy.
Definition endpoint.hpp:58
iostream transport error category
Definition base.hpp:85
std::string get_query() const
Return the query portion.
Definition uri.hpp:732
bool is_ipv6_literal() const
Definition uri.hpp:651
#define _WEBSOCKETPP_CONSTEXPR_TOKEN_
Definition cpp11.hpp:134
#define _WEBSOCKETPP_NOEXCEPT_TOKEN_
Definition cpp11.hpp:115
#define __has_extension
Definition cpp11.hpp:40
#define __has_feature(x)
Definition cpp11.hpp:37
Concurrency handling support.
Definition basic.hpp:34
Library level error codes.
Definition error.hpp:44
@ general
Catch-all library error.
Definition error.hpp:47
@ unrequested_subprotocol
Selected subprotocol was not requested by the client.
Definition error.hpp:102
@ invalid_port
Invalid port in URI.
Definition error.hpp:120
@ client_only
Attempted to use a client specific feature on a server endpoint.
Definition error.hpp:105
@ http_connection_ended
HTTP connection ended.
Definition error.hpp:111
@ operation_canceled
The requested operation was canceled.
Definition error.hpp:127
@ no_outgoing_buffers
The endpoint is out of outgoing message buffers.
Definition error.hpp:68
@ http_parse_error
HTTP parse error.
Definition error.hpp:143
@ reserved_close_code
Close code is in a reserved range.
Definition error.hpp:80
@ con_creation_failed
Connection creation attempted failed.
Definition error.hpp:99
@ no_incoming_buffers
The endpoint is out of incoming message buffers.
Definition error.hpp:71
@ invalid_state
The connection was in the wrong state for this operation.
Definition error.hpp:74
@ extension_neg_failed
Extension negotiation failed.
Definition error.hpp:146
@ rejected
Connection rejected.
Definition error.hpp:130
@ unsupported_version
Unsupported WebSocket protocol version.
Definition error.hpp:140
@ invalid_utf8
Invalid UTF-8.
Definition error.hpp:86
@ invalid_close_code
Close code is invalid.
Definition error.hpp:83
@ server_only
Attempted to use a server specific feature on a client endpoint.
Definition error.hpp:108
@ endpoint_not_secure
Attempted to open a secure connection with an insecure endpoint.
Definition error.hpp:57
@ close_handshake_timeout
WebSocket close handshake timed out.
Definition error.hpp:117
@ invalid_subprotocol
Invalid subprotocol.
Definition error.hpp:89
@ bad_close_code
Unable to parse close code.
Definition error.hpp:77
@ open_handshake_timeout
WebSocket opening handshake timed out.
Definition error.hpp:114
@ invalid_version
Invalid WebSocket protocol version.
Definition error.hpp:137
@ transport_error
General transport error, consult more specific transport error code.
Definition error.hpp:149
@ send_queue_full
send attempted when endpoint write queue was full
Definition error.hpp:50
@ test
Unit testing utility error code.
Definition error.hpp:96
@ invalid_uri
An invalid uri was supplied.
Definition error.hpp:65
Implementation of RFC 7692, the permessage-deflate WebSocket extension.
Definition disabled.hpp:44
Constants related to frame and payload limits.
Definition frame.hpp:145
static uint8_t const close_reason_size
Maximum size of close frame reason.
Definition frame.hpp:169
static uint64_t const payload_size_jumbo
Maximum size of a jumbo WebSocket payload (basic payload = 127).
Definition frame.hpp:162
static unsigned int const max_extended_header_length
Maximum length of the variable portion of the WebSocket header.
Definition frame.hpp:153
static unsigned int const max_header_length
Maximum length of a WebSocket header.
Definition frame.hpp:150
static uint16_t const payload_size_extended
Maximum size of an extended WebSocket payload (basic payload = 126).
Definition frame.hpp:159
static uint8_t const payload_size_basic
Maximum size of a basic WebSocket payload.
Definition frame.hpp:156
static unsigned int const basic_header_length
Minimum length of a WebSocket frame header.
Definition frame.hpp:147
Constants and utility functions related to WebSocket opcodes.
Definition frame.hpp:76
bool invalid(value v)
Check if an opcode is invalid.
Definition frame.hpp:130
bool reserved(value v)
Check if an opcode is reserved.
Definition frame.hpp:118
bool is_control(value v)
Check if an opcode is for a control frame.
Definition frame.hpp:139
Data structures and utility functions for manipulating WebSocket frames.
Definition frame.hpp:45
unsigned int get_masking_key_offset(basic_header const &)
Calculate the offset location of the masking key within the extended header.
Definition frame.hpp:469
void set_rsv2(basic_header &h, bool value)
Set the frame's RSV2 bit.
Definition frame.hpp:366
static unsigned int const MAX_HEADER_LENGTH
Maximum length of a WebSocket header.
Definition frame.hpp:50
opcode::value get_opcode(basic_header const &h)
Extract opcode from basic header.
Definition frame.hpp:393
void set_rsv3(basic_header &h, bool value)
Set the frame's RSV3 bit.
Definition frame.hpp:384
uint64_t get_payload_size(basic_header const &, extended_header const &)
Extract the full payload size field from a WebSocket header.
Definition frame.hpp:573
uint8_t get_basic_size(basic_header const &)
Extracts the raw payload length specified in the basic header.
Definition frame.hpp:431
size_t byte_mask_circ(uint8_t *input, uint8_t *output, size_t length, size_t prepared_key)
Circular byte aligned mask/unmask.
Definition frame.hpp:830
void byte_mask(input_iter b, input_iter e, output_iter o, masking_key_type const &key, size_t key_offset=0)
Byte by byte mask/unmask.
Definition frame.hpp:645
static unsigned int const MAX_EXTENDED_HEADER_LENGTH
Maximum length of the variable portion of the WebSocket header.
Definition frame.hpp:52
bool get_rsv3(basic_header const &h)
check whether the frame's RSV3 bit is set
Definition frame.hpp:375
bool get_masked(basic_header const &h)
check whether the frame is masked
Definition frame.hpp:402
bool get_rsv2(basic_header const &h)
check whether the frame's RSV2 bit is set
Definition frame.hpp:357
void byte_mask(iter_type b, iter_type e, masking_key_type const &key, size_t key_offset=0)
Byte by byte mask/unmask (in place).
Definition frame.hpp:675
uint16_t get_extended_size(extended_header const &)
Extract the extended size field from an extended header.
Definition frame.hpp:540
size_t byte_mask_circ(uint8_t *data, size_t length, size_t prepared_key)
Circular byte aligned mask/unmask (in place).
Definition frame.hpp:857
bool get_fin(basic_header const &h)
Check whether the frame's FIN bit is set.
Definition frame.hpp:321
size_t circshift_prepared_key(size_t prepared_key, size_t offset)
circularly shifts the supplied prepared masking key by offset bytes
Definition frame.hpp:612
bool get_rsv1(basic_header const &h)
check whether the frame's RSV1 bit is set
Definition frame.hpp:339
void set_masked(basic_header &h, bool value)
Set the frame's MASK bit.
Definition frame.hpp:411
size_t word_mask_circ(uint8_t *input, uint8_t *output, size_t length, size_t prepared_key)
Circular word aligned mask/unmask.
Definition frame.hpp:768
void word_mask_exact(uint8_t *data, size_t length, masking_key_type const &key)
Exact word aligned mask/unmask (in place).
Definition frame.hpp:731
void set_rsv1(basic_header &h, bool value)
Set the frame's RSV1 bit.
Definition frame.hpp:348
size_t get_header_len(basic_header const &)
Calculates the full length of the header based on the first bytes.
Definition frame.hpp:445
void set_fin(basic_header &h, bool value)
Set the frame's FIN bit.
Definition frame.hpp:330
uint64_t get_jumbo_size(extended_header const &)
Extract the jumbo size field from an extended header.
Definition frame.hpp:555
void word_mask_exact(uint8_t *input, uint8_t *output, size_t length, masking_key_type const &key)
Exact word aligned mask/unmask.
Definition frame.hpp:702
std::string prepare_header(const basic_header &h, const extended_header &e)
Generate a properly sized contiguous string that encodes a full frame header.
Definition frame.hpp:489
masking_key_type get_masking_key(basic_header const &, extended_header const &)
Extract the masking key from a frame header.
Definition frame.hpp:516
static unsigned int const BASIC_HEADER_LENGTH
Minimum length of a WebSocket frame header.
Definition frame.hpp:48
size_t word_mask_circ(uint8_t *data, size_t length, size_t prepared_key)
Circular word aligned mask/unmask (in place).
Definition frame.hpp:805
size_t prepare_masking_key(masking_key_type const &key)
Extract a masking key into a value the size of a machine word.
Definition frame.hpp:595
HTTP parser errors.
status_code::value get_status_code(error::value value)
Get the HTTP status code associated with the error.
lib::error_category const & get_category()
Get a reference to a static copy of the asio transport error category.
@ unknown_transfer_encoding
The transfer encoding is unknown.
@ istream_bad
An istream read command returned with the bad flag set.
@ invalid_format
The specified data contains illegal characters for the context.
@ body_too_large
The body value is larger than the configured maximum size.
@ incomplete_request
The request was missing some required values.
@ unsupported_transfer_encoding
The transfer encoding is not supported.
@ incomplete_status_line
The response status line was missing some required values.
@ missing_header_separator
A header line was missing a separator.
@ invalid_header_name
The header name specified contains illegal characters.
@ request_header_fields_too_large
The request headers are larger than the configured maximum size.
lib::error_code make_error_code(error::value e)
Create an error code with the given value and the asio transport category.
std::string get_string(value code)
Given a status code value, return the default status message.
value
Known values for HTTP Status codes.
HTTP handling support.
Definition request.hpp:37
size_t const max_body_size
Default Maximum size in bytes for HTTP message bodies.
Definition constants.hpp:71
static char const header_separator[]
Literal value of the HTTP header separator.
Definition constants.hpp:62
std::vector< std::pair< std::string, attribute_list > > parameter_list
The type of an HTTP parameter list.
Definition constants.hpp:56
size_t const istream_buffer
Number of bytes to use for temporary istream read buffers.
Definition constants.hpp:74
bool is_not_token_char(unsigned char c)
Is the character a non-token.
size_t const max_header_size
Maximum size in bytes before rejecting an HTTP header as too big.
Definition constants.hpp:68
static char const header_delimiter[]
Literal value of the HTTP header delimiter.
Definition constants.hpp:59
bool is_whitespace_char(unsigned char c)
Is the character whitespace.
static char const header_token[]
invalid HTTP token characters
Definition constants.hpp:81
bool is_not_whitespace_char(unsigned char c)
Is the character non-whitespace.
std::map< std::string, std::string > attribute_list
The type of an HTTP attribute list.
Definition constants.hpp:48
bool is_token_char(unsigned char c)
Is the character a token.
static std::string const empty_header
Literal value of an empty header.
Definition constants.hpp:65
Stub RNG policy that always returns 0.
Definition none.hpp:35
Random number generation policies.
Asio transport errors.
Definition base.hpp:161
lib::error_code make_error_code(error::value e)
Create an error code with the given value and the asio transport category.
Definition base.hpp:217
@ proxy_invalid
Invalid Proxy URI.
Definition base.hpp:177
@ pass_through
there was an error in the underlying transport library
Definition base.hpp:171
@ proxy_failed
The connection to the requested proxy server failed.
Definition base.hpp:174
@ invalid_host_service
Invalid host or service.
Definition base.hpp:180
Transport policy that uses asio.
Definition endpoint.hpp:46
Generic transport related errors.
@ pass_through
underlying transport pass through
@ operation_not_supported
Operation not supported.
@ operation_aborted
Operation aborted.
@ invalid_num_bytes
async_read_at_least call requested more bytes than buffer can store
@ action_after_shutdown
read or write after shutdown
@ tls_short_read
TLS short read.
@ double_read
async_read called while another async_read was in progress
iostream transport errors
Definition base.hpp:64
@ invalid_num_bytes
async_read_at_least call requested more bytes than buffer can store
Definition base.hpp:71
@ double_read
async_read called while another async_read was in progress
Definition base.hpp:74
lib::error_code make_error_code(error::value e)
Get an error code with the given value and the iostream transport category.
Definition base.hpp:118
lib::error_category const & get_category()
Get a reference to a static copy of the iostream transport error category.
Definition base.hpp:112
Transport policy that uses STL iostream for I/O and does not support timers.
Definition endpoint.hpp:43
lib::function< lib::error_code(connection_hdl, std::vector< transport::buffer > const &bufs)> vector_write_handler
Definition base.hpp:57
lib::function< lib::error_code(connection_hdl)> shutdown_handler
Definition base.hpp:61
lib::function< lib::error_code(connection_hdl, char const *, size_t)> write_handler
The type and signature of the callback used by iostream transport to write.
Definition base.hpp:48
Transport policies provide network connectivity and timers.
Definition endpoint.hpp:45
lib::function< void(lib::error_code const &, size_t)> read_handler
The type and signature of the callback passed to the read method.
lib::function< void()> dispatch_handler
The type and signature of the callback passed to the dispatch method.
lib::function< void()> interrupt_handler
The type and signature of the callback passed to the interrupt method.
lib::function< void(lib::error_code const &)> accept_handler
The type and signature of the callback passed to the accept method.
Definition endpoint.hpp:80
lib::function< void(lib::error_code const &)> timer_handler
The type and signature of the callback passed to the read method.
lib::function< void(lib::error_code const &)> connect_handler
The type and signature of the callback passed to the connect method.
Definition endpoint.hpp:83
lib::function< void(lib::error_code const &)> write_handler
The type and signature of the callback passed to the write method.
lib::function< void(lib::error_code const &)> init_handler
The type and signature of the callback passed to the init hook.
lib::function< void(lib::error_code const &)> shutdown_handler
The type and signature of the callback passed to the shutdown method.
A group of helper methods for parsing and validating URIs against RFC 3986.
Definition uri.hpp:52
bool digit(char c)
RFC3986 digit character test.
Definition uri.hpp:184
bool gen_delim(char c)
RFC3986 generic delimiter character test.
Definition uri.hpp:78
bool digit(std::string::const_iterator it)
RFC3986 digit character test (iterator version).
Definition uri.hpp:195
bool ipv4_literal(std::string::const_iterator start, std::string::const_iterator end)
Tests a range for a valid IPv4 literal.
Definition uri.hpp:250
bool sub_delim(char c)
RFC3986 subcomponent delimiter character test.
Definition uri.hpp:100
bool reg_name(std::string::const_iterator start, std::string::const_iterator end)
Tests a range for validity for a registry name.
Definition uri.hpp:373
bool pct_encoded(std::string::const_iterator it)
RFC3986 per cent encoded character test.
Definition uri.hpp:211
bool scheme(char c)
RFC3986 scheme character test.
Definition uri.hpp:165
bool unreserved(char c)
RFC3986 unreserved character test.
Definition uri.hpp:61
bool reg_name(char c)
Tests a character for validity for a registry name.
Definition uri.hpp:361
bool hex4(std::string::const_iterator start, std::string::const_iterator end)
Tests a range for a valid IPv6 hex quad.
Definition uri.hpp:279
bool dec_octet(std::string::const_iterator start, std::string::const_iterator end)
Tests a range for a valid IPv4 decimal octet.
Definition uri.hpp:223
bool ipv6_literal(std::string::const_iterator start, std::string::const_iterator end)
Tests a range for a valid IPv6 literal.
Definition uri.hpp:299
bool hexdigit(char c)
RFC3986 hex digit character test.
Definition uri.hpp:128
Generic non-websocket specific utility functions and data structures.
Definition utilities.hpp:39
std::string to_hex(uint8_t const *input, size_t length)
Convert byte array (uint8_t) to ascii printed string of hex digits.
T::const_iterator ci_find_substr(T const &haystack, T const &needle, std::locale const &loc=std::locale())
Find substring (case insensitive).
T::const_iterator ci_find_substr(T const &haystack, typename T::value_type const *needle, typename T::size_type size, std::locale const &loc=std::locale())
Find substring (case insensitive).
std::string to_hex(char const *input, size_t length)
Convert char array to ascii printed string of hex digits.
Namespace for the WebSocket++ project.
static uint16_t const uri_default_secure_port
Default port for wss://.
Definition uri.hpp:47
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
static uint16_t const uri_default_port
Default port for ws://.
Definition uri.hpp:45
lib::shared_ptr< uri > uri_ptr
Pointer to a URI.
Definition uri.hpp:791
std::pair< lib::error_code, std::string > err_str_pair
Combination error code / string type for returning two values.
Definition error.hpp:41
#define TYP_BIGE
Definition network.hpp:53
#define TYP_SMLE
Definition network.hpp:52
#define TYP_INIT
Definition network.hpp:51
Server config with asio transport and TLS disabled.
static const long timeout_socket_shutdown
Length of time to wait for socket shutdown.
Definition core.hpp:137
static const long timeout_connect
Length of time to wait for TCP connect.
Definition core.hpp:134
static const long timeout_dns_resolve
Length of time to wait for dns resolution.
Definition core.hpp:131
static const long timeout_proxy
Length of time to wait before a proxy handshake is aborted.
Definition core.hpp:121
static const long timeout_socket_pre_init
Default timer values (in ms).
Definition core.hpp:118
static const long timeout_socket_post_init
Length of time to wait for socket post-initialization.
Definition core.hpp:128
Server config with iostream transport.
Definition core.hpp:68
websocketpp::random::none::int_generator< uint32_t > rng_type
RNG policies.
Definition core.hpp:93
static const websocketpp::log::level elog_level
Default static error logging channels.
Definition core.hpp:176
websocketpp::transport::iostream::endpoint< transport_config > transport_type
Transport Endpoint Component.
Definition core.hpp:142
static const size_t max_http_body_size
Default maximum http body size.
Definition core.hpp:252
static const long timeout_open_handshake
Default timer values (in ms).
Definition core.hpp:152
static const size_t max_message_size
Default maximum message size.
Definition core.hpp:240
static const bool drop_on_protocol_error
Drop connections immediately on protocol error.
Definition core.hpp:213
static const long timeout_close_handshake
Length of time before a closing handshake is aborted.
Definition core.hpp:154
static const websocketpp::log::level alog_level
Default static access logging channels.
Definition core.hpp:189
websocketpp::log::basic< concurrency_type, websocketpp::log::elevel > elog_type
Logging policies.
Definition core.hpp:88
static const long timeout_pong
Length of time to wait for a pong after a ping.
Definition core.hpp:156
static const bool silent_close
Suppresses the return of detailed connection close information.
Definition core.hpp:228
static bool const enable_multithreading
Definition core.hpp:98
static const size_t connection_read_buffer_size
Size of the per-connection read buffer.
Definition core.hpp:204
static const bool enable_extensions
Global flag for enabling/disabling extensions.
Definition core.hpp:255
static const int client_version
WebSocket Protocol version to use as a client.
Definition core.hpp:164
The constant size component of a WebSocket frame header.
Definition frame.hpp:189
The variable size component of a WebSocket frame header.
Definition frame.hpp:235
Package of log levels for logging access events.
Definition levels.hpp:112
static char const * channel_name(level channel)
Get the textual name of a channel given a channel id.
Definition levels.hpp:164
static level const fail
One line for each failed WebSocket connection with details.
Definition levels.hpp:147
static level const none
Special aggregate value representing "no levels".
Definition levels.hpp:114
static level const debug_handshake
Extra information about opening handshakes.
Definition levels.hpp:137
static level const devel
Development messages (warning: very chatty).
Definition levels.hpp:141
static level const all
Special aggregate value representing "all levels".
Definition levels.hpp:152
static level const debug_close
Extra information about closing handshakes.
Definition levels.hpp:139
static level const frame_payload
One line per frame, includes the full message payload (warning: chatty).
Definition levels.hpp:129
static level const connect
Information about new connections.
Definition levels.hpp:121
static level const app
Special channel for application specific logs. Not used by the library.
Definition levels.hpp:143
static level const frame_header
One line per frame, includes the full frame header.
Definition levels.hpp:127
static level const message_payload
Reserved.
Definition levels.hpp:133
static level const endpoint
Reserved.
Definition levels.hpp:135
static level const message_header
Reserved.
Definition levels.hpp:131
static level const control
One line per control frame.
Definition levels.hpp:125
static level const disconnect
One line for each closed connection. Includes closing codes and reasons.
Definition levels.hpp:123
static level const access_core
Definition levels.hpp:150
static level const http
Access related to HTTP requests.
Definition levels.hpp:145
Package of values for hinting at the nature of a given logger.
Definition levels.hpp:46
static value const none
No information.
Definition levels.hpp:51
static value const access
Access log.
Definition levels.hpp:53
static value const error
Error log.
Definition levels.hpp:55
uint32_t value
Type of a channel type hint value.
Definition levels.hpp:48
Package of log levels for logging errors.
Definition levels.hpp:59
static level const devel
Low level debugging information (warning: very chatty).
Definition levels.hpp:63
static char const * channel_name(level channel)
Get the textual name of a channel given a channel id.
Definition levels.hpp:91
static level const library
Definition levels.hpp:66
static level const info
Definition levels.hpp:69
static level const all
Special aggregate value representing "all levels".
Definition levels.hpp:80
static level const fatal
Definition levels.hpp:78
static level const none
Special aggregate value representing "no levels".
Definition levels.hpp:61
static level const rerror
Definition levels.hpp:75
static level const warn
Definition levels.hpp:72
A simple utility buffer class.
Helper less than functor for case insensitive find.
Definition utilities.hpp:75
Helper functor for case insensitive find.
Definition utilities.hpp:49
bool operator()(charT ch1, charT ch2)
Perform a case insensitive comparison.
Definition utilities.hpp:63
my_equal(std::locale const &loc)
Construct the functor with the given locale.
Definition utilities.hpp:54
#define _WEBSOCKETPP_ERROR_CODE_ENUM_NS_END_
#define _WEBSOCKETPP_ERROR_CODE_ENUM_NS_START_
Two byte conversion union.
Definition frame.hpp:55
Four byte conversion union.
Definition frame.hpp:61
Eight byte conversion union.
Definition frame.hpp:67