websocketpp  0.5.1
C++/Boost Asio based websocket client/server library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
connection.hpp
1 /*
2  * Copyright (c) 2014, 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_CONNECTION_HPP
29 #define WEBSOCKETPP_CONNECTION_HPP
30 
31 #include <websocketpp/close.hpp>
32 #include <websocketpp/error.hpp>
33 #include <websocketpp/frame.hpp>
34 
35 #include <websocketpp/logger/levels.hpp>
36 #include <websocketpp/processors/processor.hpp>
37 #include <websocketpp/transport/base/connection.hpp>
38 #include <websocketpp/http/constants.hpp>
39 
40 #include <websocketpp/common/connection_hdl.hpp>
41 #include <websocketpp/common/cpp11.hpp>
42 #include <websocketpp/common/functional.hpp>
43 
44 #include <queue>
45 #include <sstream>
46 #include <string>
47 #include <vector>
48 
49 namespace websocketpp {
50 
52 
59 typedef lib::function<void(connection_hdl)> open_handler;
60 
62 
69 typedef lib::function<void(connection_hdl)> close_handler;
70 
72 
79 typedef lib::function<void(connection_hdl)> fail_handler;
80 
82 
91 typedef lib::function<void(connection_hdl)> interrupt_handler;
92 
94 
101 typedef lib::function<bool(connection_hdl,std::string)> ping_handler;
102 
104 
109 typedef lib::function<void(connection_hdl,std::string)> pong_handler;
110 
112 
116 typedef lib::function<void(connection_hdl,std::string)> pong_timeout_handler;
117 
119 
129 typedef lib::function<bool(connection_hdl)> validate_handler;
130 
132 
151 typedef lib::function<void(connection_hdl)> http_handler;
152 
153 //
154 typedef lib::function<void(lib::error_code const & ec, size_t bytes_transferred)> read_handler;
155 typedef lib::function<void(lib::error_code const & ec)> write_frame_handler;
156 
157 // constants related to the default WebSocket protocol versions available
158 #ifdef _WEBSOCKETPP_INITIALIZER_LISTS_ // simplified C++11 version
159 
164  static std::vector<int> const versions_supported = {0,7,8,13};
165 #else
166  static int const helper[] = {0,7,8,13};
169 
173  static std::vector<int> const versions_supported(helper,helper+4);
174 #endif
175 
176 namespace session {
177 namespace state {
178  // externally visible session state (states based on the RFC)
179  enum value {
180  connecting = 0,
181  open = 1,
182  closing = 2,
183  closed = 3
184  };
185 } // namespace state
186 
187 
188 namespace fail {
189 namespace status {
190  enum value {
191  GOOD = 0, // no failure yet!
192  SYSTEM = 1, // system call returned error, check that code
193  WEBSOCKET = 2, // websocket close codes contain error
194  UNKNOWN = 3, // No failure information is available
195  TIMEOUT_TLS = 4, // TLS handshake timed out
196  TIMEOUT_WS = 5 // WS handshake timed out
197  };
198 } // namespace status
199 } // namespace fail
200 
201 namespace internal_state {
202  // More granular internal states. These are used for multi-threaded
203  // connection synchronization and preventing values that are not yet or no
204  // longer available from being used.
205 
206  enum value {
207  USER_INIT = 0,
208  TRANSPORT_INIT = 1,
209  READ_HTTP_REQUEST = 2,
210  WRITE_HTTP_REQUEST = 3,
211  READ_HTTP_RESPONSE = 4,
212  WRITE_HTTP_RESPONSE = 5,
213  PROCESS_HTTP_REQUEST = 6,
214  PROCESS_CONNECTION = 7
215  };
216 } // namespace internal_state
217 } // namespace session
218 
220 template <typename config>
222  : public config::transport_type::transport_con_type
223  , public config::connection_base
224 {
225 public:
229  typedef lib::shared_ptr<type> ptr;
231  typedef lib::weak_ptr<type> weak_ptr;
232 
234  typedef typename config::concurrency_type concurrency_type;
236  typedef typename config::alog_type alog_type;
238  typedef typename config::elog_type elog_type;
239 
241  typedef typename config::transport_type::transport_con_type
244  typedef typename transport_con_type::ptr transport_con_ptr;
245 
246  typedef lib::function<void(ptr)> termination_handler;
247 
248  typedef typename concurrency_type::scoped_lock_type scoped_lock_type;
249  typedef typename concurrency_type::mutex_type mutex_type;
250 
251  typedef typename config::request_type request_type;
252  typedef typename config::response_type response_type;
253 
254  typedef typename config::message_type message_type;
255  typedef typename message_type::ptr message_ptr;
256 
257  typedef typename config::con_msg_manager_type con_msg_manager_type;
258  typedef typename con_msg_manager_type::ptr con_msg_manager_ptr;
259 
261  typedef typename config::rng_type rng_type;
262 
264  typedef lib::shared_ptr<processor_type> processor_ptr;
265 
266  // Message handler (needs to know message type)
267  typedef lib::function<void(connection_hdl,message_ptr)> message_handler;
268 
270  typedef typename transport_con_type::timer_ptr timer_ptr;
271 
272  // Misc Convenience Types
273  typedef session::internal_state::value istate_type;
274 
275 private:
276  enum terminate_status {
277  failed = 1,
278  closed,
279  unknown
280  };
281 public:
282 
283  explicit connection(bool p_is_server, std::string const & ua, alog_type& alog,
284  elog_type& elog, rng_type & rng)
285  : transport_con_type(p_is_server, alog, elog)
286  , m_handle_read_frame(lib::bind(
287  &type::handle_read_frame,
288  this,
289  lib::placeholders::_1,
290  lib::placeholders::_2
291  ))
292  , m_write_frame_handler(lib::bind(
293  &type::handle_write_frame,
294  this,
295  lib::placeholders::_1
296  ))
297  , m_user_agent(ua)
298  , m_open_handshake_timeout_dur(config::timeout_open_handshake)
299  , m_close_handshake_timeout_dur(config::timeout_close_handshake)
300  , m_pong_timeout_dur(config::timeout_pong)
301  , m_max_message_size(config::max_message_size)
302  , m_state(session::state::connecting)
303  , m_internal_state(session::internal_state::USER_INIT)
304  , m_msg_manager(new con_msg_manager_type())
305  , m_send_buffer_size(0)
306  , m_write_flag(false)
307  , m_read_flag(true)
308  , m_is_server(p_is_server)
309  , m_alog(alog)
310  , m_elog(elog)
311  , m_rng(rng)
312  , m_local_close_code(close::status::abnormal_close)
313  , m_remote_close_code(close::status::abnormal_close)
314  , m_is_http(false)
315  , m_was_clean(false)
316  {
317  m_alog.write(log::alevel::devel,"connection constructor");
318  }
319 
321  ptr get_shared() {
322  return lib::static_pointer_cast<type>(transport_con_type::get_shared());
323  }
324 
326  // Set Handler Callbacks //
328 
330 
336  void set_open_handler(open_handler h) {
337  m_open_handler = h;
338  }
339 
341 
346  void set_close_handler(close_handler h) {
347  m_close_handler = h;
348  }
349 
351 
357  void set_fail_handler(fail_handler h) {
358  m_fail_handler = h;
359  }
360 
362 
372  void set_ping_handler(ping_handler h) {
373  m_ping_handler = h;
374  }
375 
377 
383  void set_pong_handler(pong_handler h) {
384  m_pong_handler = h;
385  }
386 
388 
406  void set_pong_timeout_handler(pong_timeout_handler h) {
407  m_pong_timeout_handler = h;
408  }
409 
411 
417  void set_interrupt_handler(interrupt_handler h) {
418  m_interrupt_handler = h;
419  }
420 
422 
432  void set_http_handler(http_handler h) {
433  m_http_handler = h;
434  }
435 
437 
448  void set_validate_handler(validate_handler h) {
449  m_validate_handler = h;
450  }
451 
453 
458  void set_message_handler(message_handler h) {
459  m_message_handler = h;
460  }
461 
463  // Connection timeouts and other limits //
465 
467 
486  void set_open_handshake_timeout(long dur) {
487  m_open_handshake_timeout_dur = dur;
488  }
489 
491 
511  m_close_handshake_timeout_dur = dur;
512  }
513 
515 
531  void set_pong_timeout(long dur) {
532  m_pong_timeout_dur = dur;
533  }
534 
536 
544  size_t get_max_message_size() const {
545  return m_max_message_size;
546  }
547 
549 
560  void set_max_message_size(size_t new_value) {
561  m_max_message_size = new_value;
562  if (m_processor) {
563  m_processor->set_max_message_size(new_value);
564  }
565  }
566 
568 
579  size_t get_max_http_body_size() const {
580  return m_request.get_max_body_size();
581  }
582 
584 
595  void set_max_http_body_size(size_t new_value) {
596  m_request.set_max_body_size(new_value);
597  }
598 
600  // Uncategorized public methods //
602 
604 
614  size_t get_buffered_amount() const;
615 
617  size_t buffered_amount() const {
618  return get_buffered_amount();
619  }
620 
622  // Action Methods //
624 
626 
637  lib::error_code send(std::string const & payload, frame::opcode::value op =
638  frame::opcode::text);
639 
641 
654  lib::error_code send(void const * payload, size_t len, frame::opcode::value
655  op = frame::opcode::binary);
656 
658 
670  lib::error_code send(message_ptr msg);
671 
673 
685  lib::error_code interrupt();
686 
688  void handle_interrupt();
689 
691 
710  lib::error_code pause_reading();
711 
713  void handle_pause_reading();
714 
716 
722  lib::error_code resume_reading();
723 
725  void handle_resume_reading();
726 
728 
739  void ping(std::string const & payload);
740 
742  void ping(std::string const & payload, lib::error_code & ec);
743 
745  void handle_pong_timeout(std::string payload, lib::error_code const & ec);
746 
748 
757  void pong(std::string const & payload);
758 
760  void pong(std::string const & payload, lib::error_code & ec);
761 
763 
782  void close(close::status::value const code, std::string const & reason);
783 
785  void close(close::status::value const code, std::string const & reason,
786  lib::error_code & ec);
787 
789  // Pass-through access to the uri information //
791 
793 
799  bool get_secure() const;
800 
802 
808  std::string const & get_host() const;
809 
811 
817  std::string const & get_resource() const;
818 
820 
826  uint16_t get_port() const;
827 
829 
835  uri_ptr get_uri() const;
836 
838 
844  void set_uri(uri_ptr uri);
845 
847  // Subprotocol negotiation //
849 
851 
857  std::string const & get_subprotocol() const;
858 
860 
866  std::vector<std::string> const & get_requested_subprotocols() const;
867 
869 
881  void add_subprotocol(std::string const & request, lib::error_code & ec);
882 
884 
894  void add_subprotocol(std::string const & request);
895 
897 
909  void select_subprotocol(std::string const & value, lib::error_code & ec);
910 
912 
922  void select_subprotocol(std::string const & value);
923 
925  // Pass-through access to the request and response objects //
927 
929 
935  std::string const & get_request_header(std::string const & key) const;
936 
938 
946  std::string const & get_request_body() const;
947 
949 
955  std::string const & get_response_header(std::string const & key) const;
956 
958 
971  void set_status(http::status_code::value code);
972 
974 
986  void set_status(http::status_code::value code, std::string const & msg);
987 
989 
1001  void set_body(std::string const & value);
1002 
1004 
1017  void append_header(std::string const & key, std::string const & val);
1018 
1020 
1032  void replace_header(std::string const & key, std::string const & val);
1033 
1035 
1044  void remove_header(std::string const & key);
1045 
1047 
1060  request_type const & get_request() const {
1061  return m_request;
1062  }
1063 
1065  // Pass-through access to the other connection information //
1067 
1069 
1077  return m_connection_hdl;
1078  }
1079 
1081 
1084  bool is_server() const {
1085  return m_is_server;
1086  }
1087 
1089 
1095  std::string const & get_origin() const;
1096 
1098 
1103  session::state::value get_state() const;
1104 
1105 
1107 
1111  return m_local_close_code;
1112  }
1113 
1115 
1118  std::string const & get_local_close_reason() const {
1119  return m_local_close_reason;
1120  }
1121 
1123 
1127  return m_remote_close_code;
1128  }
1129 
1131 
1134  std::string const & get_remote_close_reason() const {
1135  return m_remote_close_reason;
1136  }
1137 
1139 
1147  lib::error_code get_ec() const {
1148  return m_ec;
1149  }
1150 
1152  // The remaining public member functions are for internal/policy use //
1153  // only. Do not call from application code unless you understand what //
1154  // you are doing. //
1156 
1158 
1167  m_connection_hdl = hdl;
1168  transport_con_type::set_handle(hdl);
1169  }
1170 
1172 
1190  message_ptr get_message(websocketpp::frame::opcode::value op, size_t size)
1191  const
1192  {
1193  return m_msg_manager->get_message(op, size);
1194  }
1195 
1196  void start();
1197 
1198  void read_handshake(size_t num_bytes);
1199 
1200  void handle_read_handshake(lib::error_code const & ec,
1201  size_t bytes_transferred);
1202  void handle_read_http_response(lib::error_code const & ec,
1203  size_t bytes_transferred);
1204 
1205  void handle_send_http_response(lib::error_code const & ec);
1206  void handle_send_http_request(lib::error_code const & ec);
1207 
1208  void handle_open_handshake_timeout(lib::error_code const & ec);
1209  void handle_close_handshake_timeout(lib::error_code const & ec);
1210 
1211  void handle_read_frame(lib::error_code const & ec, size_t bytes_transferred);
1212  void read_frame();
1213 
1215  std::vector<int> const & get_supported_versions() const;
1216 
1219  void set_termination_handler(termination_handler new_handler);
1220 
1221  void terminate(lib::error_code const & ec);
1222  void handle_terminate(terminate_status tstat, lib::error_code const & ec);
1223 
1225 
1230  void write_frame();
1231 
1233 
1244  void handle_write_frame(lib::error_code const & ec);
1245 protected:
1246  void handle_transport_init(lib::error_code const & ec);
1247 
1250  lib::error_code initialize_processor();
1251 
1254  lib::error_code process_handshake_request();
1255 private:
1257  void send_http_response(lib::error_code const & ec);
1258 
1260  void send_http_request();
1261 
1263  void send_http_response_error(lib::error_code const & ec);
1264 
1266 
1269  void process_control_frame(message_ptr msg);
1270 
1272 
1282  lib::error_code send_close_ack(close::status::value code =
1283  close::status::blank, std::string const & reason = "");
1284 
1286 
1300  lib::error_code send_close_frame(close::status::value code =
1301  close::status::blank, std::string const & reason = "", bool ack = false,
1302  bool terminal = false);
1303 
1305 
1314  processor_ptr get_processor(int version) const;
1315 
1317 
1326  void write_push(message_ptr msg);
1327 
1329 
1339  message_ptr write_pop();
1340 
1342 
1347  void log_open_result();
1348 
1350 
1353  void log_close_result();
1354 
1356 
1359  void log_fail_result();
1360 
1362 
1365  void log_http_result();
1366 
1368  template <typename error_type>
1369  void log_err(log::level l, char const * msg, error_type const & ec) {
1370  std::stringstream s;
1371  s << msg << " error: " << ec << " (" << ec.message() << ")";
1372  m_elog.write(l, s.str());
1373  }
1374 
1375  // internal handler functions
1376  read_handler m_handle_read_frame;
1377  write_frame_handler m_write_frame_handler;
1378 
1379  // static settings
1380  std::string const m_user_agent;
1381 
1383  connection_hdl m_connection_hdl;
1384 
1386  open_handler m_open_handler;
1387  close_handler m_close_handler;
1388  fail_handler m_fail_handler;
1389  ping_handler m_ping_handler;
1390  pong_handler m_pong_handler;
1391  pong_timeout_handler m_pong_timeout_handler;
1392  interrupt_handler m_interrupt_handler;
1393  http_handler m_http_handler;
1394  validate_handler m_validate_handler;
1395  message_handler m_message_handler;
1396 
1398  long m_open_handshake_timeout_dur;
1399  long m_close_handshake_timeout_dur;
1400  long m_pong_timeout_dur;
1401  size_t m_max_message_size;
1402 
1404 
1407  session::state::value m_state;
1408 
1410 
1413  istate_type m_internal_state;
1414 
1415  mutable mutex_type m_connection_state_lock;
1416 
1418 
1422  mutex_type m_write_lock;
1423 
1424  // connection resources
1425  char m_buf[config::connection_read_buffer_size];
1426  size_t m_buf_cursor;
1427  termination_handler m_termination_handler;
1428  con_msg_manager_ptr m_msg_manager;
1429  timer_ptr m_handshake_timer;
1430  timer_ptr m_ping_timer;
1431 
1434  std::string m_handshake_buffer;
1435 
1437 
1445  processor_ptr m_processor;
1446 
1448 
1451  std::queue<message_ptr> m_send_queue;
1452 
1454 
1457  size_t m_send_buffer_size;
1458 
1460 
1463  std::vector<transport::buffer> m_send_buffer;
1464 
1467  std::vector<message_ptr> m_current_msgs;
1468 
1470 
1473  bool m_write_flag;
1474 
1476  bool m_read_flag;
1477 
1478  // connection data
1479  request_type m_request;
1480  response_type m_response;
1481  uri_ptr m_uri;
1482  std::string m_subprotocol;
1483 
1484  // connection data that might not be necessary to keep around for the life
1485  // of the whole connection.
1486  std::vector<std::string> m_requested_subprotocols;
1487 
1488  bool const m_is_server;
1489  alog_type& m_alog;
1490  elog_type& m_elog;
1491 
1492  rng_type & m_rng;
1493 
1494  // Close state
1496  close::status::value m_local_close_code;
1497 
1499  std::string m_local_close_reason;
1500 
1502  close::status::value m_remote_close_code;
1503 
1505  std::string m_remote_close_reason;
1506 
1508  lib::error_code m_ec;
1509 
1512  bool m_is_http;
1513 
1514  bool m_was_clean;
1515 
1517  bool m_closed_by_me;
1518 
1520  bool m_failed_by_me;
1521 
1523  bool m_dropped_by_me;
1524 };
1525 
1526 } // namespace websocketpp
1527 
1528 #include <websocketpp/impl/connection_impl.hpp>
1529 
1530 #endif // WEBSOCKETPP_CONNECTION_HPP
lib::error_code process_handshake_request()
std::string const & get_remote_close_reason() const
Get the WebSocket close reason sent by the remote endpoint.
void add_subprotocol(std::string const &request, lib::error_code &ec)
Adds the given subprotocol string to the request list (exception free)
void set_open_handshake_timeout(long dur)
Set open handshake timeout.
Definition: connection.hpp:486
void set_termination_handler(termination_handler new_handler)
connection_hdl get_handle() const
Get Connection Handle.
void set_pong_timeout(long dur)
Set pong timeout.
Definition: connection.hpp:531
ptr get_shared()
Get a shared pointer to this component.
Definition: connection.hpp:321
void read_frame()
Issue a new transport read unless reading is paused.
std::vector< std::string > const & get_requested_subprotocols() const
Gets all of the subprotocols requested by the client.
uint16_t value
The type of a close code value.
Definition: close.hpp:49
message_ptr get_message(websocketpp::frame::opcode::value op, size_t size) const
Get a message buffer.
std::string const & get_subprotocol() const
Gets the negotated subprotocol.
bool terminal(value code)
Determine if the code represents an unrecoverable error.
Definition: close.hpp:212
lib::function< void(connection_hdl)> close_handler
The type and function signature of a close handler.
Definition: connection.hpp:69
lib::error_code pause_reading()
Pause reading of new data.
lib::function< void(connection_hdl)> open_handler
The type and function signature of an open handler.
Definition: connection.hpp:59
close::status::value get_local_close_code() const
Get the WebSocket close code sent by this endpoint.
lib::function< void(connection_hdl, std::string)> pong_timeout_handler
The type and function signature of a pong timeout handler.
Definition: connection.hpp:116
std::string const & get_local_close_reason() const
Get the WebSocket close reason sent by this endpoint.
session::state::value get_state() const
Return the connection state.
static std::vector< int > const versions_supported(helper, helper+4)
Container that stores the list of protocol versions supported.
lib::function< void(connection_hdl)> interrupt_handler
The type and function signature of an interrupt handler.
Definition: connection.hpp:91
transport_con_type::ptr transport_con_ptr
Type of a shared pointer to the transport component of this connection.
Definition: connection.hpp:244
void set_open_handler(open_handler h)
Set open handler.
Definition: connection.hpp:336
WebSocket protocol processor abstract base class.
Definition: processor.hpp:160
lib::function< bool(connection_hdl, std::string)> ping_handler
The type and function signature of a ping handler.
Definition: connection.hpp:101
uri_ptr get_uri() const
Gets the connection URI.
void replace_header(std::string const &key, std::string const &val)
Replace a header.
void ping(std::string const &payload)
Send a ping.
lib::weak_ptr< type > weak_ptr
Type of a weak pointer to this connection.
Definition: connection.hpp:231
Represents an individual WebSocket connection.
Definition: connection.hpp:221
void set_fail_handler(fail_handler h)
Set fail handler.
Definition: connection.hpp:357
size_t get_buffered_amount() const
Get the size of the outgoing write buffer (in payload bytes)
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
void set_http_handler(http_handler h)
Set http handler.
Definition: connection.hpp:432
void select_subprotocol(std::string const &value, lib::error_code &ec)
Select a subprotocol to use (exception free)
void set_close_handler(close_handler h)
Set close handler.
Definition: connection.hpp:346
lib::error_code get_ec() const
Get the internal error code for a closed/failed connection.
void pong(std::string const &payload)
Send a pong.
void handle_resume_reading()
Resume reading callback.
config::alog_type alog_type
Type of the access logging policy.
Definition: connection.hpp:236
lib::error_code initialize_processor()
static level const devel
Development messages (warning: very chatty)
Definition: levels.hpp:141
std::string const & get_request_header(std::string const &key) const
Retrieve a request header.
lib::function< bool(connection_hdl)> validate_handler
The type and function signature of a validate handler.
Definition: connection.hpp:129
close::status::value get_remote_close_code() const
Get the WebSocket close code sent by the remote endpoint.
void set_pong_handler(pong_handler h)
Set pong handler.
Definition: connection.hpp:383
connection< config > type
Type of this connection.
Definition: connection.hpp:227
void set_close_handshake_timeout(long dur)
Set close handshake timeout.
Definition: connection.hpp:510
lib::error_code resume_reading()
Resume reading of new data.
bool is_server() const
Get whether or not this connection is part of a server or client.
void close(close::status::value const code, std::string const &reason)
Close the connection.
void set_handle(connection_hdl hdl)
Set Connection Handle.
void set_status(http::status_code::value code)
Set response status code and message.
void handle_pong_timeout(std::string payload, lib::error_code const &ec)
Utility method that gets called back when the ping timer expires.
config::concurrency_type concurrency_type
Type of the concurrency component of this connection.
Definition: connection.hpp:234
config::rng_type rng_type
Type of RNG.
Definition: connection.hpp:261
void append_header(std::string const &key, std::string const &val)
Append a header.
lib::error_code send(std::string const &payload, frame::opcode::value op=frame::opcode::text)
Create a message and then add it to the outgoing send queue.
config::transport_type::transport_con_type transport_con_type
Type of the transport component of this connection.
Definition: connection.hpp:242
lib::function< void(connection_hdl)> http_handler
The type and function signature of a http handler.
Definition: connection.hpp:151
void set_ping_handler(ping_handler h)
Set ping handler.
Definition: connection.hpp:372
void write_frame()
Checks if there are frames in the send queue and if there are sends one.
void handle_write_frame(lib::error_code const &ec)
Process the results of a frame write operation and start the next write.
void set_max_http_body_size(size_t new_value)
Set maximum HTTP message body size.
Definition: connection.hpp:595
Namespace for the WebSocket++ project.
Definition: base64.hpp:41
void set_max_message_size(size_t new_value)
Set maximum message size.
Definition: connection.hpp:560
std::string const & get_origin() const
Return the same origin policy origin value from the opening request.
void set_pong_timeout_handler(pong_timeout_handler h)
Set pong timeout handler.
Definition: connection.hpp:406
std::string const & get_response_header(std::string const &key) const
Retrieve a response header.
uint16_t get_port() const
Returns the port component of the connection URI.
std::string const & get_resource() const
Returns the resource component of the connection URI.
void set_interrupt_handler(interrupt_handler h)
Set interrupt handler.
Definition: connection.hpp:417
request_type const & get_request() const
Get request object.
std::vector< int > const & get_supported_versions() const
Get array of WebSocket protocol versions that this connection supports.
static int const helper[]
Helper array to get around lack of initializer lists pre C++11.
Definition: connection.hpp:167
lib::shared_ptr< uri > uri_ptr
Pointer to a URI.
Definition: uri.hpp:350
void handle_interrupt()
Transport inturrupt callback.
void handle_pause_reading()
Pause reading callback.
void set_validate_handler(validate_handler h)
Set validate handler.
Definition: connection.hpp:448
lib::shared_ptr< type > ptr
Type of a shared pointer to this connection.
Definition: connection.hpp:229
size_t get_max_message_size() const
Get maximum message size.
Definition: connection.hpp:544
void set_message_handler(message_handler h)
Set message handler.
Definition: connection.hpp:458
bool get_secure() const
Returns the secure flag from the connection URI.
static value const abnormal_close
A dummy value to indicate that the connection was closed abnormally.
Definition: close.hpp:104
size_t buffered_amount() const
DEPRECATED: use get_buffered_amount instead.
Definition: connection.hpp:617
lib::function< void(connection_hdl, std::string)> pong_handler
The type and function signature of a pong handler.
Definition: connection.hpp:109
std::string const & get_request_body() const
Retrieve a request body.
void set_uri(uri_ptr uri)
Sets the connection URI.
std::string const & get_host() const
Returns the host component of the connection URI.
size_t get_max_http_body_size() const
Get maximum HTTP message body size.
Definition: connection.hpp:579
lib::error_code interrupt()
Asyncronously invoke handler::on_inturrupt.
transport_con_type::timer_ptr timer_ptr
Type of a pointer to a transport timer handle.
Definition: connection.hpp:270
lib::function< void(connection_hdl)> fail_handler
The type and function signature of a fail handler.
Definition: connection.hpp:79
config::elog_type elog_type
Type of the error logging policy.
Definition: connection.hpp:238
static value const blank
A blank value for internal use.
Definition: close.hpp:52
void remove_header(std::string const &key)
Remove a header.
void set_body(std::string const &value)
Set response body content.