28 #ifndef WEBSOCKETPP_CONNECTION_HPP    29 #define WEBSOCKETPP_CONNECTION_HPP   154 typedef lib::function<void(lib::error_code const & ec, size_t bytes_transferred)> 
read_handler;
   158 #ifdef _WEBSOCKETPP_INITIALIZER_LISTS_ // simplified C++11 version   166     static int const helper[] = {0,7,8,13};
   201 namespace internal_state {
   219 namespace http_state {
   234 template <
typename config>
   243     typedef lib::shared_ptr<type> 
ptr;
   284     typedef typename transport_con_type::timer_ptr 
timer_ptr;
   290     enum terminate_status {
   297     explicit connection(
bool p_is_server, std::string 
const & ua, alog_type& alog,
   298         elog_type& elog, rng_type & rng)
   300       , m_handle_read_frame(lib::bind(
   301             &type::handle_read_frame,
   303             lib::placeholders::_1,
   304             lib::placeholders::_2
   306       , m_write_frame_handler(lib::bind(
   307             &type::handle_write_frame,
   309             lib::placeholders::_1
   312       , m_open_handshake_timeout_dur(
config::timeout_open_handshake)
   313       , m_close_handshake_timeout_dur(
config::timeout_close_handshake)
   314       , m_pong_timeout_dur(
config::timeout_pong)
   315       , m_max_message_size(
config::max_message_size)
   317       , m_internal_state(session::internal_state::
USER_INIT)
   318       , m_msg_manager(new con_msg_manager_type())
   319       , m_send_buffer_size(0)
   320       , m_write_flag(false)
   322       , m_is_server(p_is_server)
   329       , m_http_state(session::http_state::
init)
   337         return lib::static_pointer_cast<type>(transport_con_type::get_shared());
   422         m_pong_timeout_handler = h;
   433         m_interrupt_handler = h;
   464         m_validate_handler = h;
   474         m_message_handler = h;
   502         m_open_handshake_timeout_dur = dur;
   526         m_close_handshake_timeout_dur = dur;
   547         m_pong_timeout_dur = dur;
   560         return m_max_message_size;
   576         m_max_message_size = new_value;
   578             m_processor->set_max_message_size(new_value);
   595         return m_request.get_max_body_size();
   611         m_request.set_max_body_size(new_value);
   629     size_t get_buffered_amount() 
const;
   636         return get_buffered_amount();
   688     lib::error_code send(message_ptr msg);
   703     lib::error_code interrupt();
   706     void handle_interrupt();
   728     lib::error_code pause_reading();
   731     void handle_pause_reading();
   740     lib::error_code resume_reading();
   743     void handle_resume_reading();
   757     void ping(std::string 
const & payload);
   760     void ping(std::string 
const & payload, lib::error_code & ec);
   763     void handle_pong_timeout(std::string payload, lib::error_code 
const & ec);
   775     void pong(std::string 
const & payload);
   778     void pong(std::string 
const & payload, lib::error_code & ec);
   804         lib::error_code & ec);
   817     bool get_secure() 
const;
   826     std::string 
const & get_host() 
const;
   835     std::string 
const & get_resource() 
const;
   844     uint16_t get_port() 
const;
   875     std::string 
const & get_subprotocol() 
const;
   884     std::vector<std::string> 
const & get_requested_subprotocols() 
const;
   899     void add_subprotocol(std::string 
const & request, lib::error_code & ec);
   912     void add_subprotocol(std::string 
const & request);
   927     void select_subprotocol(std::string 
const & 
value, lib::error_code & ec);
   940     void select_subprotocol(std::string 
const & value);
   953     std::string 
const & get_request_header(std::string 
const & key) 
const;
   964     std::string 
const & get_request_body() 
const;
   973     std::string 
const & get_response_header(std::string 
const & key) 
const;
   984         return m_response.get_status_code();
   996         return m_response.get_status_msg();
  1043     void set_body(std::string 
const & value);
  1059     void append_header(std::string 
const & key, std::string 
const & val);
  1074     void replace_header(std::string 
const & key, std::string 
const & val);
  1086     void remove_header(std::string 
const & key);
  1138     lib::error_code defer_http_response();
  1150     void send_http_response(lib::error_code & ec);
  1153     void send_http_response();
  1184         return m_connection_hdl;
  1202     std::string 
const & get_origin() 
const;
  1218         return m_local_close_code;
  1226         return m_local_close_reason;
  1234         return m_remote_close_code;
  1242         return m_remote_close_reason;
  1280         return m_msg_manager->get_message(op, size);
  1291     void read_handshake(
size_t num_bytes);
  1293     void handle_read_handshake(lib::error_code 
const & ec,
  1294         size_t bytes_transferred);
  1295     void handle_read_http_response(lib::error_code 
const & ec,
  1296         size_t bytes_transferred);
  1299     void handle_write_http_response(lib::error_code 
const & ec);
  1300     void handle_send_http_request(lib::error_code 
const & ec);
  1302     void handle_open_handshake_timeout(lib::error_code 
const & ec);
  1303     void handle_close_handshake_timeout(lib::error_code 
const & ec);
  1305     void handle_read_frame(lib::error_code 
const & ec, 
size_t bytes_transferred);
  1309     std::vector<int> 
const & get_supported_versions() 
const;
  1313     void set_termination_handler(termination_handler new_handler);
  1315     void terminate(lib::error_code 
const & ec);
  1316     void handle_terminate(terminate_status tstat, lib::error_code 
const & ec);
  1338     void handle_write_frame(lib::error_code 
const & ec);
  1357         m_connection_hdl = hdl;
  1358         transport_con_type::set_handle(hdl);
  1361     void handle_transport_init(lib::error_code 
const & ec);
  1365     lib::error_code initialize_processor();
  1369     lib::error_code process_handshake_request();
  1374     void write_http_response(lib::error_code 
const & ec);
  1377     void send_http_request();
  1380     void write_http_response_error(lib::error_code 
const & ec);
  1386     void process_control_frame(message_ptr msg);
  1431     processor_ptr get_processor(
int version) 
const;
  1443     void write_push(message_ptr msg);
  1456     message_ptr write_pop();
  1464     void log_open_result();
  1470     void log_close_result();
  1476     void log_fail_result();
  1482     void log_http_result();
  1485     template <
typename error_type>
  1486     void log_err(
log::level l, 
char const * msg, error_type 
const & ec) {
  1487         std::stringstream s;
  1488         s << msg << 
" error: " << ec << 
" (" << ec.message() << 
")";
  1489         m_elog.write(l, s.str());
  1493     read_handler            m_handle_read_frame;
  1494     write_frame_handler     m_write_frame_handler;
  1497     std::string 
const       m_user_agent;
  1503     open_handler            m_open_handler;
  1504     close_handler           m_close_handler;
  1505     fail_handler            m_fail_handler;
  1506     ping_handler            m_ping_handler;
  1507     pong_handler            m_pong_handler;
  1508     pong_timeout_handler    m_pong_timeout_handler;
  1509     interrupt_handler       m_interrupt_handler;
  1510     http_handler            m_http_handler;
  1511     validate_handler        m_validate_handler;
  1512     message_handler         m_message_handler;
  1515     long                    m_open_handshake_timeout_dur;
  1516     long                    m_close_handshake_timeout_dur;
  1517     long                    m_pong_timeout_dur;
  1518     size_t                  m_max_message_size;
  1530     istate_type             m_internal_state;
  1532     mutable mutex_type      m_connection_state_lock;
  1539     mutex_type              m_write_lock;
  1543     size_t                  m_buf_cursor;
  1544     termination_handler     m_termination_handler;
  1545     con_msg_manager_ptr     m_msg_manager;
  1546     timer_ptr               m_handshake_timer;
  1547     timer_ptr               m_ping_timer;
  1551     std::string m_handshake_buffer;
  1562     processor_ptr           m_processor;
  1568     std::queue<message_ptr> m_send_queue;
  1574     size_t m_send_buffer_size;
  1580     std::vector<transport::buffer> m_send_buffer;
  1584     std::vector<message_ptr> m_current_msgs;
  1596     request_type            m_request;
  1597     response_type           m_response;
  1599     std::string             m_subprotocol;
  1603     std::vector<std::string> m_requested_subprotocols;
  1605     bool const              m_is_server;
  1616     std::string             m_local_close_reason;
  1622     std::string             m_remote_close_reason;
  1625     lib::error_code m_ec;
  1638     bool                    m_closed_by_me;
  1641     bool                    m_failed_by_me;
  1644     bool                    m_dropped_by_me;
  1651 #endif // WEBSOCKETPP_CONNECTION_HPP std::string const & get_remote_close_reason() const 
Get the WebSocket close reason sent by the remote endpoint. 
 
void set_open_handshake_timeout(long dur)
Set open handshake timeout. 
 
connection_hdl get_handle() const 
Get Connection Handle. 
 
void set_pong_timeout(long dur)
Set pong timeout. 
 
ptr get_shared()
Get a shared pointer to this component. 
 
uint16_t value
The type of a close code value. 
 
message_ptr get_message(websocketpp::frame::opcode::value op, size_t size) const 
Get a message buffer. 
 
bool terminal(value code)
Determine if the code represents an unrecoverable error. 
 
lib::function< void(connection_hdl)> close_handler
The type and function signature of a close handler. 
 
config::con_msg_manager_type con_msg_manager_type
 
config::request_type request_type
 
lib::function< void(connection_hdl)> open_handler
The type and function signature of an open handler. 
 
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. 
 
std::string const & get_local_close_reason() const 
Get the WebSocket close reason sent by this endpoint. 
 
lib::function< void(ptr)> termination_handler
 
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. 
 
transport_con_type::ptr transport_con_ptr
Type of a shared pointer to the transport component of this connection. 
 
asio::connection< config > transport_con_type
Type of the connection transport component associated with this endpoint transport component...
 
void set_open_handler(open_handler h)
Set open handler. 
 
WebSocket protocol processor abstract base class. 
 
lib::function< bool(connection_hdl, std::string)> ping_handler
The type and function signature of a ping handler. 
 
lib::weak_ptr< type > weak_ptr
Type of a weak pointer to this connection. 
 
lib::function< void(lib::error_code const &ec)> write_frame_handler
 
Represents an individual WebSocket connection. 
 
void set_fail_handler(fail_handler h)
Set fail handler. 
 
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection. 
 
void set_http_handler(http_handler h)
Set http handler. 
 
lib::function< void(lib::error_code const &ec, size_t bytes_transferred)> read_handler
 
void set_close_handler(close_handler h)
Set close handler. 
 
lib::error_code get_ec() const 
Get the internal error code for a closed/failed connection. 
 
lib::function< void(connection_hdl, message_ptr)> message_handler
 
A package of types and methods for manipulating WebSocket close codes. 
 
config::alog_type alog_type
Type of the access logging policy. 
 
processor::processor< config > processor_type
 
Stores, parses, and manipulates HTTP responses. 
 
static level const devel
Development messages (warning: very chatty) 
 
lib::function< bool(connection_hdl)> validate_handler
The type and function signature of a validate handler. 
 
close::status::value get_remote_close_code() const 
Get the WebSocket close code sent by the remote endpoint. 
 
message_type::ptr message_ptr
 
void set_pong_handler(pong_handler h)
Set pong handler. 
 
connection< config > type
Type of this connection. 
 
void set_close_handshake_timeout(long dur)
Set close handshake timeout. 
 
bool is_server() const 
Get whether or not this connection is part of a server or client. 
 
void set_handle(connection_hdl hdl)
Set Connection Handle. 
 
config::concurrency_type concurrency_type
Type of the concurrency component of this connection. 
 
config::rng_type rng_type
Type of RNG. 
 
config::transport_type::transport_con_type transport_con_type
Type of the transport component of this connection. 
 
config::response_type response_type
 
lib::function< void(connection_hdl)> http_handler
The type and function signature of a http handler. 
 
void set_ping_handler(ping_handler h)
Set ping handler. 
 
Thread safe stub "random" integer generator. 
 
std::string const & get_response_msg() const 
Get response HTTP status message. 
 
void set_max_http_body_size(size_t new_value)
Set maximum HTTP message body size. 
 
Namespace for the WebSocket++ project. 
 
void set_max_message_size(size_t new_value)
Set maximum message size. 
 
Represents a buffer for a single WebSocket message. 
 
concurrency_type::mutex_type mutex_type
 
Stub concurrency policy that implements the interface using no-ops. 
 
void close(T *e, websocketpp::connection_hdl hdl)
 
void set_pong_timeout_handler(pong_timeout_handler h)
Set pong timeout handler. 
 
lib::shared_ptr< processor_type > processor_ptr
 
void set_interrupt_handler(interrupt_handler h)
Set interrupt handler. 
 
request_type const & get_request() const 
Get request object. 
 
static int const helper[]
Helper array to get around lack of initializer lists pre C++11. 
 
static const size_t connection_read_buffer_size
 
lib::shared_ptr< uri > uri_ptr
Pointer to a URI. 
 
connection(bool p_is_server, std::string const &ua, alog_type &alog, elog_type &elog, rng_type &rng)
 
websocketpp::connection_base connection_base
User overridable Connection base class. 
 
void set_validate_handler(validate_handler h)
Set validate handler. 
 
session::internal_state::value istate_type
 
lib::shared_ptr< type > ptr
Type of a shared pointer to this connection. 
 
size_t get_max_message_size() const 
Get maximum message size. 
 
void set_message_handler(message_handler h)
Set message handler. 
 
response_type const & get_response() const 
Get response object. 
 
Stores, parses, and manipulates HTTP requests. 
 
static value const abnormal_close
A dummy value to indicate that the connection was closed abnormally. 
 
size_t buffered_amount() const 
Get the size of the outgoing write buffer (in payload bytes) 
 
lib::function< void(connection_hdl, std::string)> pong_handler
The type and function signature of a pong handler. 
 
size_t get_max_http_body_size() const 
Get maximum HTTP message body size. 
 
uint32_t level
Type of a channel package. 
 
concurrency_type::scoped_lock_type scoped_lock_type
 
A connection message manager that allocates a new message for each request. 
 
transport_con_type::timer_ptr timer_ptr
Type of a pointer to a transport timer handle. 
 
config::message_type message_type
 
con_msg_manager_type::ptr con_msg_manager_ptr
 
Stub logger that ignores all input. 
 
lib::function< void(connection_hdl)> fail_handler
The type and function signature of a fail handler. 
 
config::elog_type elog_type
Type of the error logging policy. 
 
http::status_code::value get_response_code() const 
Get response HTTP status code. 
 
static value const blank
A blank value for internal use.