Websocket++编程2-函数解释

add_subprotocol() [1/2]

template<typename config >

void websocketpp::connection< config >::add_subprotocol(std::string const & request)

Adds the given subprotocol string to the request list (exception)

Adds a subprotocol to the list to send with the opening handshake. This may be called multiple times to request more than one. If the server supports one of these, it may choose one. If so, it will return it in it's handshake reponse and the value will be available via get_subprotocol(). Subprotocol requests should be added in order of preference.

Parameters

[in]requestThe subprotocol to request

Definition at line 478 of file connection_impl.hpp.

◆ add_subprotocol() [2/2]

template<typename config >

void websocketpp::connection< config >::add_subprotocol(std::string const & request,
lib::error_code & ec 
)

Adds the given subprotocol string to the request list (exception free)

Adds a subprotocol to the list to send with the opening handshake. This may be called multiple times to request more than one. If the server supports one of these, it may choose one. If so, it will return it in it's handshake reponse and the value will be available via get_subprotocol(). Subprotocol requests should be added in order of preference.

Parameters

[in]requestThe subprotocol to request
[out]ecA status code describing the outcome of the operation

Definition at line 458 of file connection_impl.hpp.

◆ append_header() [1/2]

template<typename config >

void websocketpp::connection< config >::append_header(std::string const & key,
std::string const & val 
)

Append a header (exception)

Set the value of a header in the handshake HTTP request or response. If a header with this name already exists the value will be appended to the existing header to form a comma separated list of values. Use connection::replace_header to overwrite existing values.

When can this member function be called?

Parameters

[in]keyName of the header to set
[in]valValue to add

Exceptions

websocketpp::exception

See also

connection::replace_header

websocketpp::http::parser::parser::append_header

append_header(std::string const &, std::string const &, lib::error_code &) (exception free version)

Definition at line 633 of file connection_impl.hpp.

◆ append_header() [2/2]

template<typename config >

void websocketpp::connection< config >::append_header(std::string const & key,
std::string const & val,
lib::error_code & ec 
)

Append a header (exception free)

Set the value of a header in the handshake HTTP request or response. If a header with this name already exists the value will be appended to the existing header to form a comma separated list of values. Use connection::replace_header to overwrite existing values.

When can this member function be called?

Since

0.9.0

Parameters

[in]keyName of the header to set
[in]valValue to add
[out]ecA status code describing the outcome of the operation

See also

connection::replace_header

websocketpp::http::parser::parser::append_header

append_header(std::string const &, std::string const &) (exception version)

Definition at line 612 of file connection_impl.hpp.

◆ buffered_amount()

template<typename config >

size_t websocketpp::connection< config >::buffered_amount()const
inline

Get the size of the outgoing write buffer (in payload bytes)

Deprecated:

use get_buffered_amount instead

Definition at line 635 of file connection.hpp.

◆ close()

template<typename config >

void websocketpp::connection< config >::close(close::status::value const code,
std::string const & reason 
)

Close the connection.

Initiates the close handshake process.

If close returns successfully the connection will be in the closing state and no additional messages may be sent. All messages sent prior to calling close will be written out before the connection is closed.

If no reason is specified none will be sent. If no code is specified then no code will be sent.

The handler's on_close callback will be called once the close handshake is complete.

Reasons will be automatically truncated to the maximum length (123 bytes) if necessary.

Parameters

codeThe close code to send
reasonThe close reason to send

Definition at line 326 of file connection_impl.hpp.

◆ defer_http_response()

template<typename config >

lib::error_code websocketpp::connection< config >::defer_http_response

Defer HTTP Response until later (Exception free)

Defer HTTP Response until later.

Used in the http handler to defer the HTTP response for this connection until later. Handshake timers will be canceled and the connection will be left open until send_http_response or an equivalent is called.

Warning: deferred connections won't time out and as a result can tie up resources.

Since

0.6.0

Returns

A status code, zero on success, non-zero otherwise

Used in the http handler to defer the HTTP response for this connection until later. Handshake timers will be canceled and the connection will be left open until send_http_response or an equivalent is called.

Warning: deferred connections won't time out and as a result can tie up resources.

Returns

A status code, zero on success, non-zero otherwise

Definition at line 717 of file connection_impl.hpp.

◆ get_buffered_amount()

template<typename config >

size_t websocketpp::connection< config >::get_buffered_amount

Get the size of the outgoing write buffer (in payload bytes)

Retrieves the number of bytes in the outgoing write buffer that have not already been dispatched to the transport layer. This represents the bytes that are presently cancelable without uncleanly ending the websocket connection

This method invokes the m_write_lock mutex

Returns

The current number of bytes in the outgoing send buffer.

Definition at line 71 of file connection_impl.hpp.

◆ get_ec()

template<typename config >

lib::error_code websocketpp::connection< config >::get_ec()const
inline

Get the internal error code for a closed/failed connection.

Retrieves a machine readable detailed error code indicating the reason that the connection was closed or failed. Valid only after the close or fail handler is called.

Returns

Error code indicating the reason the connection was closed or failed

Definition at line 1391 of file connection.hpp.

◆ get_handle()

template<typename config >

connection_hdl websocketpp::connection< config >::get_handle()const
inline

Get Connection Handle.

The connection handle is a token that can be shared outside the WebSocket++ core for the purposes of identifying a connection and sending it messages.

Returns

A handle to the connection

Definition at line 1320 of file connection.hpp.

◆ get_host()

template<typename config >

std::string const & websocketpp::connection< config >::get_host

Returns the host component of the connection URI.

This value is available after the HTTP request has been fully read and may be called from any thread.

Returns

The host component of the connection URI

Definition at line 412 of file connection_impl.hpp.

◆ get_local_close_code()

template<typename config >

close::status::value websocketpp::connection< config >::get_local_close_code()const
inline

Get the WebSocket close code sent by this endpoint.

Returns

The WebSocket close code sent by this endpoint.

Definition at line 1354 of file connection.hpp.

◆ get_local_close_reason()

template<typename config >

std::string const& websocketpp::connection< config >::get_local_close_reason()const
inline

Get the WebSocket close reason sent by this endpoint.

Returns

The WebSocket close reason sent by this endpoint.

Definition at line 1362 of file connection.hpp.

◆ get_max_http_body_size()

template<typename config >

size_t websocketpp::connection< config >::get_max_http_body_size()const
inline

Get maximum HTTP message body size.

Get maximum HTTP message body size. Maximum message body size determines the point at which the connection will stop reading an HTTP request whose body is too large.

The default is set by the endpoint that creates the connection.

Since

0.5.0

Returns

The maximum HTTP message body size

Definition at line 594 of file connection.hpp.

◆ get_max_message_size()

template<typename config >

size_t websocketpp::connection< config >::get_max_message_size()const
inline

Get maximum message size.

Get maximum message size. Maximum message size determines the point at which the connection will fail with the message_too_big protocol error.

The default is set by the endpoint that creates the connection.

Since

0.3.0

Definition at line 559 of file connection.hpp.

◆ get_message()

template<typename config >

message_ptr websocketpp::connection< config >::get_message(websocketpp::frame::opcode::value op,
size_t size 
)const
inline

Get a message buffer.

Warning: The API related to directly sending message buffers may change before the 1.0 release. If you plan to use it, please keep an eye on any breaking changes notifications in future release notes. Also if you have any feedback about usage and capabilities now is a great time to provide it.

Message buffers are used to store message payloads and other message metadata.

The size parameter is a hint only. Your final payload does not need to match it. There may be some performance benefits if the initial size guess is equal to or slightly higher than the final payload size.

Parameters

opThe opcode for the new message
sizeA hint to optimize the initial allocation of payload space.

Returns

A new message buffer

Definition at line 1414 of file connection.hpp.

◆ get_origin()

template<typename config >

std::string const & websocketpp::connection< config >::get_origin

Return the same origin policy origin value from the opening request.

This value is available after the HTTP request has been fully read and may be called from any thread.

Returns

The connection's origin value from the opening handshake.

Definition at line 65 of file connection_impl.hpp.

◆ get_port()

template<typename config >

uint16_t websocketpp::connection< config >::get_port

Returns the port component of the connection URI.

This value is available after the HTTP request has been fully read and may be called from any thread.

Returns

The port component of the connection URI

Definition at line 424 of file connection_impl.hpp.

◆ get_remote_close_code()

template<typename config >

close::status::value websocketpp::connection< config >::get_remote_close_code()const
inline

Get the WebSocket close code sent by the remote endpoint.

Returns

The WebSocket close code sent by the remote endpoint.

Definition at line 1370 of file connection.hpp.

◆ get_remote_close_reason()

template<typename config >

std::string const& websocketpp::connection< config >::get_remote_close_reason()const
inline

Get the WebSocket close reason sent by the remote endpoint.

Returns

The WebSocket close reason sent by the remote endpoint.

Definition at line 1378 of file connection.hpp.

◆ get_request()

template<typename config >

request_type const& websocketpp::connection< config >::get_request()const
inline

Get request object.

Direct access to request object. This can be used to call methods of the request object that are not part of the standard request API that connection wraps.

Note use of this method involves using behavior specific to the configured HTTP policy. Such behavior may not work with alternate HTTP policies.

Since

0.3.0-alpha3

Returns

A const reference to the raw request object

Definition at line 1239 of file connection.hpp.

◆ get_request_body()

template<typename config >

std::string const & websocketpp::connection< config >::get_request_body

Retrieve a request body.

Retrieve the value of the request body. This value is typically used with PUT and POST requests to upload files or other data. Only HTTP connections will ever have bodies. WebSocket connection's will always have blank bodies.

Returns

The value of the request body.

Definition at line 534 of file connection_impl.hpp.

◆ get_request_header()

template<typename config >

std::string const & websocketpp::connection< config >::get_request_header(std::string const & key)const

Retrieve a request header.

Retrieve the value of a header from the handshake HTTP request.

Parameters

[in]keyName of the header to get

Returns

The value of the header

Definition at line 528 of file connection_impl.hpp.

◆ get_requested_subprotocols()

template<typename config >

std::vector< std::string > const & websocketpp::connection< config >::get_requested_subprotocols

Gets all of the subprotocols requested by the client.

Retrieves the subprotocols that were requested during the handshake. This method is valid in the validate handler and later.

Returns

A vector of the requested subprotocol

Definition at line 453 of file connection_impl.hpp.

◆ get_resource()

template<typename config >

std::string const & websocketpp::connection< config >::get_resource

Returns the resource component of the connection URI.

This value is available after the HTTP request has been fully read and may be called from any thread.

Returns

The resource component of the connection URI

Definition at line 418 of file connection_impl.hpp.

◆ get_response()

template<typename config >

response_type const& websocketpp::connection< config >::get_response()const
inline

Get response object.

Direct access to the HTTP response sent or received as a part of the opening handshake. This can be used to call methods of the response object that are not part of the standard request API that connection wraps.

Note use of this method involves using behavior specific to the configured HTTP policy. Such behavior may not work with alternate HTTP policies.

Since

0.7.0

Returns

A const reference to the raw response object

Definition at line 1258 of file connection.hpp.

◆ get_response_code()

template<typename config >

http::status_code::value websocketpp::connection< config >::get_response_code()const
inline

Get response HTTP status code.

Gets the response status code

Since

0.7.0

Returns

The response status code sent

Definition at line 981 of file connection.hpp.

◆ get_response_header()

template<typename config >

std::string const & websocketpp::connection< config >::get_response_header(std::string const & key)const

Retrieve a response header.

Retrieve the value of a header from the handshake HTTP request.

Parameters

[in]keyName of the header to get

Returns

The value of the header

Definition at line 540 of file connection_impl.hpp.

◆ get_response_msg()

template<typename config >

std::string const& websocketpp::connection< config >::get_response_msg()const
inline

Get response HTTP status message.

Gets the response status message

Since

0.7.0

Returns

The response status message sent

Definition at line 993 of file connection.hpp.

◆ get_secure()

template<typename config >

bool websocketpp::connection< config >::get_secure

Returns the secure flag from the connection URI.

This value is available after the HTTP request has been fully read and may be called from any thread.

Returns

Whether or not the connection URI is flagged secure.

Definition at line 406 of file connection_impl.hpp.

◆ get_state()

template<typename config >

session::state::value websocketpp::connection< config >::get_state

Return the connection state.

Values can be connecting, open, closing, and closed

Returns

The connection's current state.

Definition at line 77 of file connection_impl.hpp.

◆ get_subprotocol()

template<typename config >

std::string const & websocketpp::connection< config >::get_subprotocol

Gets the negotated subprotocol.

Retrieves the subprotocol that was negotiated during the handshake. This method is valid in the open handler and later.

Returns

The negotiated subprotocol

Definition at line 447 of file connection_impl.hpp.

◆ get_uri()

template<typename config >

uri_ptr websocketpp::connection< config >::get_uri

Gets the connection URI.

This should really only be called by internal library methods unless you really know what you are doing.

Returns

A pointer to the connection's URI

Definition at line 430 of file connection_impl.hpp.

◆ handle_pause_reading()

template<typename config >

void websocketpp::connection< config >::handle_pause_reading

Pause reading callback.

Pause reading handler. Not safe to call directly.

Definition at line 372 of file connection_impl.hpp.

◆ handle_resume_reading()

template<typename config >

void websocketpp::connection< config >::handle_resume_reading

Resume reading callback.

Resume reading helper method. Not safe to call directly.

Definition at line 390 of file connection_impl.hpp.

◆ handle_write_frame()

template<typename config >

void websocketpp::connection< config >::handle_write_frame(lib::error_code const & ec)

Process the results of a frame write operation and start the next write.

Todo:

unit tests

This method locks the m_write_lock mutex

Parameters

terminateWhether or not to terminate the connection upon completion of this write.
ecA status code from the transport layer, zero on success, non-zero otherwise.

Definition at line 1963 of file connection_impl.hpp.

◆ initialize_processor()

template<typename config >

lib::error_code websocketpp::connection< config >::initialize_processor
protected

Set m_processor based on information in m_request. Set m_response status and return an error code indicating status.

Definition at line 1196 of file connection_impl.hpp.

◆ interrupt()

template<typename config >

lib::error_code websocketpp::connection< config >::interrupt

Asyncronously invoke handler::on_inturrupt.

Trigger the on_interrupt handler.

Signals to the connection to asyncronously invoke the on_inturrupt callback for this connection's handler once it is safe to do so.

When the on_inturrupt handler callback is called it will be from within the transport event loop with all the thread safety features guaranteed by the transport to regular handlers

Multiple inturrupt signals can be active at once on the same connection

Returns

An error code

This is thread safe if the transport is thread safe

Definition at line 341 of file connection_impl.hpp.

◆ is_server()

template<typename config >

bool websocketpp::connection< config >::is_server()const
inline

Get whether or not this connection is part of a server or client.

Returns

whether or not the connection is attached to a server endpoint

Definition at line 1328 of file connection.hpp.

◆ pause_reading()

template<typename config >

lib::error_code websocketpp::connection< config >::pause_reading

Pause reading of new data.

Signals to the connection to halt reading of new data. While reading is paused, the connection will stop reading from its associated socket. In turn this will result in TCP based flow control kicking in and slowing data flow from the remote endpoint.

This is useful for applications that push new requests to a queue to be processed by another thread and need a way to signal when their request queue is full without blocking the network processing thread.

Use resume_reading() to resume.

If supported by the transport this is done asynchronously. As such reading may not stop until the current read operation completes. Typically you can expect to receive no more bytes after initiating a read pause than the size of the read buffer.

If reading is paused for this connection already nothing is changed.

Definition at line 360 of file connection_impl.hpp.

◆ ping()

template<typename config >

void websocketpp::connection< config >::ping(std::string const & payload)

Send a ping.

Initiates a ping with the given payload/

There is no feedback directly from ping except in cases of immediately detectable errors. Feedback will be provided via on_pong or on_pong_timeout callbacks.

Ping locks the m_write_lock mutex

Parameters

payloadPayload to be used for the ping

Definition at line 224 of file connection_impl.hpp.

◆ pong()

template<typename config >

void websocketpp::connection< config >::pong(std::string const & payload)

Send a pong.

Initiates a pong with the given payload.

There is no feedback from a pong once sent.

Pong locks the m_write_lock mutex

Parameters

payloadPayload to be used for the pong

Definition at line 295 of file connection_impl.hpp.

◆ process_handshake_request()

template<typename config >

lib::error_code websocketpp::connection< config >::process_handshake_request
protected

Perform WebSocket handshake validation of m_request using m_processor. set m_response and return an error code indicating status.

Definition at line 1238 of file connection_impl.hpp.

◆ remove_header() [1/2]

template<typename config >

void websocketpp::connection< config >::remove_header(std::string const & key)

Remove a header (exception)

Removes a header from the handshake HTTP request or response.

When can this member function be called?

Parameters

[in]keyThe name of the header to remove

Exceptions

websocketpp::exception

See also

websocketpp::http::parser::parser::remove_header

remove_header(std::string const &, lib::error_code &) (exception free version)

Definition at line 676 of file connection_impl.hpp.

◆ remove_header() [2/2]

template<typename config >

void websocketpp::connection< config >::remove_header(std::string const & key,
lib::error_code & ec 
)

Remove a header (exception free)

Removes a header from the handshake HTTP request or response.

When can this member function be called?

Parameters

[in]keyThe name of the header to remove
[out]ecA status code describing the outcome of the operation

See also

websocketpp::http::parser::parser::remove_header

remove_header(std::string const &) (exception version)

◆ replace_header() [1/2]

template<typename config >

void websocketpp::connection< config >::replace_header(std::string const & key,
std::string const & val 
)

Replace a header (exception)

Set the value of a header in the handshake HTTP request or response. If a header with this name already exists the old value will be replaced Use connection::append_header to append to a list of existing values.

When can this member function be called?

Parameters

[in]keyName of the header to set
[in]valValue to set

Exceptions

websocketpp::exception

See also

connection::append_header

websocketpp::http::parser::parser::replace_header

replace_header(std::string const & key, std::string const & val, lib::error_code & ec) (exception free version)

Definition at line 644 of file connection_impl.hpp.

◆ replace_header() [2/2]

template<typename config >

void websocketpp::connection< config >::replace_header(std::string const & key,
std::string const & val,
lib::error_code & ec 
)

Replace a header (exception free)

Set the value of a header in the handshake HTTP request or response. If a header with this name already exists the old value will be replaced Use connection::append_header to append to a list of existing values.

When can this member function be called?

Parameters

[in]keyName of the header to set
[in]valValue to set
[out]ecA status code describing the outcome of the operation

See also

connection::append_header

websocketpp::http::parser::parser::replace_header

replace_header(std::string const &, std::string const &) (exception version)

◆ resume_reading()

template<typename config >

lib::error_code websocketpp::connection< config >::resume_reading

Resume reading of new data.

Signals to the connection to resume reading of new data after it was paused by pause_reading().

If reading is not paused for this connection already nothing is changed.

Definition at line 378 of file connection_impl.hpp.

◆ select_subprotocol() [1/2]

template<typename config >

void websocketpp::connection< config >::select_subprotocol(std::string const & value)

Select a subprotocol to use (exception)

Indicates which subprotocol should be used for this connection. Valid only during the validate handler callback. Subprotocol selected must have been requested by the client. Consult get_requested_subprotocols() for a list of valid subprotocols.

This member function is valid on server endpoints/connections only

Parameters

[in]valueThe subprotocol to select

Definition at line 517 of file connection_impl.hpp.

◆ select_subprotocol() [2/2]

template<typename config >

void websocketpp::connection< config >::select_subprotocol(std::string const & value,
lib::error_code & ec 
)

Select a subprotocol to use (exception free)

Indicates which subprotocol should be used for this connection. Valid only during the validate handler callback. Subprotocol selected must have been requested by the client. Consult get_requested_subprotocols() for a list of valid subprotocols.

This member function is valid on server endpoints/connections only

Parameters

[in]valueThe subprotocol to select
[out]ecA status code describing the outcome of the operation

Definition at line 488 of file connection_impl.hpp.

◆ send() [1/3]

template<typename config >

lib::error_code websocketpp::connection< config >::send(message_ptr msg)

Add a message to the outgoing send queue.

If presented with a prepared message it is added without validation or framing. If presented with an unprepared message it is validated, framed, and then added

Errors are returned via an exception

Todo:

make exception system_error rather than error_code

This method invokes the m_write_lock mutex

Parameters

msgA message_ptr to the message to send.

◆ send() [2/3]

template<typename config >

lib::error_code websocketpp::connection< config >::send(std::string const & payload,
frame::opcode::value op = frame::opcode::text 
)

Create a message and then add it to the outgoing send queue.

Convenience method to send a message given a payload string and optionally an opcode. Default opcode is utf8 text.

This method locks the m_write_lock mutex

Parameters

payloadThe payload string to generated the message with
opThe opcode to generated the message with. Default is frame::opcode::text

Definition at line 83 of file connection_impl.hpp.

◆ send() [3/3]

template<typename config >

lib::error_code websocketpp::connection< config >::send(void const * payload,
size_t len,
frame::opcode::value op = frame::opcode::binary 
)

Send a message (raw array overload)

Convenience method to send a message given a raw array and optionally an opcode. Default opcode is binary.

This method locks the m_write_lock mutex

Parameters

payloadA pointer to the array containing the bytes to send.
lenLength of the array.
opThe opcode to generated the message with. Default is frame::opcode::binary

Definition at line 94 of file connection_impl.hpp.

◆ send_http_response()

template<typename config >

void websocketpp::connection< config >::send_http_response(lib::error_code & ec)

Send deferred HTTP Response (exception free)

Sends an http response to an HTTP connection that was deferred. This will send a complete response including all headers, status line, and body text. The connection will be closed afterwards.

Since

0.6.0

Parameters

ecA status code, zero on success, non-zero otherwise

Definition at line 742 of file connection_impl.hpp.

◆ set_body() [1/2]

template<typename config >

void websocketpp::connection< config >::set_body(std::string const & value)

Set response body content (exception)

Set the body content of the HTTP response to the parameter string. Note set_body will also set the Content-Length HTTP header to the appropriate value. If you want the Content-Length header to be something else set it to something else after calling set_body

This member function is valid only from the http() and validate() handler callbacks.

Parameters

[in]valueString data to include as the body content.

Exceptions

websocketpp::exception

See also

websocketpp::http::response::set_body

set_body(std::string const &, lib::error_code &) (exception free version)

Definition at line 603 of file connection_impl.hpp.

◆ set_body() [2/2]

template<typename config >

void websocketpp::connection< config >::set_body(std::string const & value,
lib::error_code & ec 
)

Set response body content (exception free)

Set the body content of the HTTP response to the parameter string. Note set_body will also set the Content-Length HTTP header to the appropriate value. If you want the Content-Length header to be something else set it to something else after calling set_body

This member function is valid only from the http() and validate() handler callbacks.

Since

0.9.0

Parameters

[in]valueString data to include as the body content.
[out]ecA status code describing the outcome of the operation

See also

websocketpp::http::response::set_body

set_body(std::string const &) (exception version)

Definition at line 591 of file connection_impl.hpp.

◆ set_close_handler()

template<typename config >

void websocketpp::connection< config >::set_close_handler(close_handlerh)
inline

Set close handler.

The close handler is called immediately after the connection is closed.

Parameters

hThe new close_handler

Definition at line 361 of file connection.hpp.

◆ set_close_handshake_timeout()

template<typename config >

void websocketpp::connection< config >::set_close_handshake_timeout(long dur)
inline

Set close handshake timeout.

Sets the length of time the library will wait after a closing handshake has been initiated before cancelling it. This can be used to prevent excessive wait times for outgoing clients or excessive resource usage from broken clients or DoS attacks on servers.

Connections that time out will have their close handlers called with the close_handshake_timeout error code.

The default value is specified via the compile time config value 'timeout_close_handshake'. The default value in the core config is 5000ms. A value of 0 will disable the timer entirely.

To be effective, the transport you are using must support timers. See the documentation for your transport policy for details about its timer support.

Parameters

durThe length of the close handshake timeout in ms

Definition at line 525 of file connection.hpp.

◆ set_fail_handler()

template<typename config >

void websocketpp::connection< config >::set_fail_handler(fail_handlerh)
inline

Set fail handler.

The fail handler is called whenever the connection fails while the handshake is bring processed.

Parameters

hThe new fail_handler

Definition at line 372 of file connection.hpp.

◆ set_handle()

template<typename config >

void websocketpp::connection< config >::set_handle(connection_hdlhdl)
inline

Set Connection Handle.

The connection handle is a token that can be shared outside the WebSocket++ core for the purposes of identifying a connection and sending it messages.

Parameters

hdlA connection_hdl that the connection will use to refer to itself.

Definition at line 1493 of file connection.hpp.

◆ set_http_handler()

template<typename config >

void websocketpp::connection< config >::set_http_handler(http_handlerh)
inline

Set http handler.

The http handler is called after an HTTP request other than a WebSocket upgrade request is received. It allows a WebSocket++ server to respond to regular HTTP requests on the same port as it processes WebSocket connections. This can be useful for hosting error messages, flash policy files, status pages, and other simple HTTP responses. It is not intended to be used as a primary web server.

Parameters

hThe new http_handler

Definition at line 447 of file connection.hpp.

◆ set_interrupt_handler()

template<typename config >

void websocketpp::connection< config >::set_interrupt_handler(interrupt_handlerh)
inline

Set interrupt handler.

The interrupt handler is called whenever the connection is manually interrupted by the application.

Parameters

hThe new interrupt_handler

Definition at line 432 of file connection.hpp.

◆ set_max_http_body_size()

template<typename config >

void websocketpp::connection< config >::set_max_http_body_size(size_t new_value)
inline

Set maximum HTTP message body size.

Set maximum HTTP message body size. Maximum message body size determines the point at which the connection will stop reading an HTTP request whose body is too large.

The default is set by the endpoint that creates the connection.

Since

0.5.0

Parameters

new_valueThe value to set as the maximum message size.

Definition at line 610 of file connection.hpp.

◆ set_max_message_size()

template<typename config >

void websocketpp::connection< config >::set_max_message_size(size_t new_value)
inline

Set maximum message size.

Set maximum message size. Maximum message size determines the point at which the connection will fail with the message_too_big protocol error. This value may be changed during the connection.

The default is set by the endpoint that creates the connection.

Since

0.3.0

Parameters

new_valueThe value to set as the maximum message size.

Definition at line 575 of file connection.hpp.

◆ set_message_handler()

template<typename config >

void websocketpp::connection< config >::set_message_handler(message_handler h)
inline

Set message handler.

The message handler is called after a new message has been received.

Parameters

hThe new message_handler

Definition at line 473 of file connection.hpp.

◆ set_open_handler()

template<typename config >

void websocketpp::connection< config >::set_open_handler(open_handlerh)
inline

Set open handler.

The open handler is called after the WebSocket handshake is complete and the connection is considered OPEN.

Parameters

hThe new open_handler

Definition at line 351 of file connection.hpp.

◆ set_open_handshake_timeout()

template<typename config >

void websocketpp::connection< config >::set_open_handshake_timeout(long dur)
inline

Set open handshake timeout.

Sets the length of time the library will wait after an opening handshake has been initiated before cancelling it. This can be used to prevent excessive wait times for outgoing clients or excessive resource usage from broken clients or DoS attacks on servers.

Connections that time out will have their fail handlers called with the open_handshake_timeout error code.

The default value is specified via the compile time config value 'timeout_open_handshake'. The default value in the core config is 5000ms. A value of 0 will disable the timer entirely.

To be effective, the transport you are using must support timers. See the documentation for your transport policy for details about its timer support.

Parameters

durThe length of the open handshake timeout in ms

Definition at line 501 of file connection.hpp.

◆ set_ping_handler()

template<typename config >

void websocketpp::connection< config >::set_ping_handler(ping_handlerh)
inline

Set ping handler.

The ping handler is called whenever the connection receives a ping control frame. The ping payload is included.

The ping handler's return time controls whether or not a pong is sent in response to this ping. Returning false will suppress the return pong. If no ping handler is set a pong will be sent.

Parameters

hThe new ping_handler

Definition at line 387 of file connection.hpp.

◆ set_pong_handler()

template<typename config >

void websocketpp::connection< config >::set_pong_handler(pong_handlerh)
inline

Set pong handler.

The pong handler is called whenever the connection receives a pong control frame. The pong payload is included.

Parameters

hThe new pong_handler

Definition at line 398 of file connection.hpp.

◆ set_pong_timeout()

template<typename config >

void websocketpp::connection< config >::set_pong_timeout(long dur)
inline

Set pong timeout.

Sets the length of time the library will wait for a pong response to a ping. This can be used as a keepalive or to detect broken connections.

Pong responses that time out will have the pong timeout handler called.

The default value is specified via the compile time config value 'timeout_pong'. The default value in the core config is 5000ms. A value of 0 will disable the timer entirely.

To be effective, the transport you are using must support timers. See the documentation for your transport policy for details about its timer support.

Parameters

durThe length of the pong timeout in ms

Definition at line 546 of file connection.hpp.

◆ set_pong_timeout_handler()

template<typename config >

void websocketpp::connection< config >::set_pong_timeout_handler(pong_timeout_handlerh)
inline

Set pong timeout handler.

If the transport component being used supports timers, the pong timeout handler is called whenever a pong control frame is not received with the configured timeout period after the application sends a ping.

The config setting timeout_pong controls the length of the timeout period. It is specified in milliseconds.

This can be used to probe the health of the remote endpoint's WebSocket implementation. This does not guarantee that the remote application itself is still healthy but can be a useful diagnostic.

Note: receipt of this callback doesn't mean the pong will never come. This functionality will not suppress delivery of the pong in question should it arrive after the timeout.

Parameters

hThe new pong_timeout_handler

Definition at line 421 of file connection.hpp.

◆ set_status() [1/4]

template<typename config >

void websocketpp::connection< config >::set_status(http::status_code::valuecode)

Set response status code and message (exception)

Sets the response status code and message to independent custom values. use set_status(status_code::value) to set the code and have the standard message be automatically set.

This member function is valid only from the http() and validate() handler callbacks.

Parameters

[in]codeCode to set
[in]msgMessage to set

Exceptions

websocketpp::exception

See also

websocketpp::http::response::set_status()

websocketpp::http::status_code::value (list of valid codes)

Definition at line 557 of file connection_impl.hpp.

◆ set_status() [2/4]

template<typename config >

void websocketpp::connection< config >::set_status(http::status_code::valuecode,
lib::error_code & ec 
)

Set response status code and message (exception free)

Sets the response status code to code and looks up the corresponding message for standard codes. Non-standard codes will be entered as Unknown use set_status(status_code::value,std::string) overload to set both values explicitly.

This member function is valid only from the http() and validate() handler callbacks.

Since

0.9.0

Parameters

[in]codeCode to set
[in]msgMessage to set
[out]ecA status code describing the outcome of the operation

See also

websocketpp::http::parser::response::set_status

websocketpp::http::status_code::value (list of valid codes)

Definition at line 545 of file connection_impl.hpp.

◆ set_status() [3/4]

template<typename config >

void websocketpp::connection< config >::set_status(http::status_code::valuecode,
std::string const & msg 
)

Set response status code and message (exception)

Sets the response status code and message to independent custom values. use set_status(status_code::value) to set the code and have the standard message be automatically set.

This member function is valid only from the http() and validate() handler callbacks.

Parameters

[in]codeCode to set
[in]msgMessage to set

Exceptions

websocketpp::exception

See also

websocketpp::http::response::set_status()

websocketpp::http::status_code::value (list of valid codes)

Definition at line 580 of file connection_impl.hpp.

◆ set_status() [4/4]

template<typename config >

void websocketpp::connection< config >::set_status(http::status_code::valuecode,
std::string const & msg,
lib::error_code & ec 
)

Set response status code and message (exception free)

Sets the response status code and message to independent custom values. use set_status(status_code::value) to set the code and have the standard message be automatically set.

This member function is valid only from the http() and validate() handler callbacks.

Since

0.9.0

Parameters

[in]codeCode to set
[in]msgMessage to set
[out]ecA status code describing the outcome of the operation

See also

websocketpp::http::response::set_status()

websocketpp::http::status_code::value (list of valid codes)

Definition at line 567 of file connection_impl.hpp.

◆ set_termination_handler()

template<typename config >

void websocketpp::connection< config >::set_termination_handler(termination_handler new_handler)

Sets the handler for a terminating connection. Should only be used internally by the endpoint class.

Definition at line 53 of file connection_impl.hpp.

◆ set_uri()

template<typename config >

void websocketpp::connection< config >::set_uri(uri_ptruri)

Sets the connection URI.

This should really only be called by internal library methods unless you really know what you are doing.

Parameters

uriThe new URI to set

Definition at line 436 of file connection_impl.hpp.

◆ set_validate_handler()

template<typename config >

void websocketpp::connection< config >::set_validate_handler(validate_handlerh)
inline

Set validate handler.

The validate handler is called after a WebSocket handshake has been parsed but before a response is returned. It provides the application a chance to examine the request and determine whether or not it wants to accept the connection.

Returning false from the validate handler will reject the connection. If no validate handler is present, all connections will be allowed.

Parameters

hThe new validate_handler

Definition at line 463 of file connection.hpp.

◆ write_frame()

template<typename config >

void websocketpp::connection< config >::write_frame

Checks if there are frames in the send queue and if there are sends one.

Todo:

unit tests

This method locks the m_write_lock mutex

Definition at line 1867 of file connection_impl.hpp.

The documentation for this class was generated from the following files:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值