Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
websocketpp::close Namespace Reference

A package of types and methods for manipulating WebSocket close codes.

Namespaces

namespace  status
 A package of types and methods for manipulating WebSocket close status'.
 

Classes

union  code_converter
 Type used to convert close statuses between integer and wire representations. More...
 

Functions

status::value extract_code (std::string const &payload, lib::error_code &ec)
 Extract a close code value from a close payload.
 
std::string extract_reason (std::string const &payload, lib::error_code &ec)
 Extract the reason string from a close payload.
 

Function Documentation

◆ extract_code()

status::value websocketpp::close::extract_code ( std::string const & payload,
lib::error_code & ec )
inline

If there is no close value (ie string is empty) status::no_status is returned. If a code couldn't be extracted (usually do to a short or otherwise mangled payload) status::protocol_error is returned and the ec value is flagged as an error. Note that this case is different than the case where protocol error is received over the wire.

If the value is in an invalid or reserved range ec is set accordingly.

Parameters
[in]payloadClose frame payload value received over the wire.
[out]ecSet to indicate what error occurred, if any.
Returns
The extracted value

Definition at line 283 of file close.hpp.

285{
286 ec = lib::error_code();
287
288 if (payload.size() == 0) {
289 return status::no_status;
290 } else if (payload.size() == 1) {
291 ec = make_error_code(error::bad_close_code);
292 return status::protocol_error;
293 }
294
295 code_converter val;
296
297 val.c[0] = payload[0];
298 val.c[1] = payload[1];
299
300 status::value code(ntohs(val.i));
301
302 if (status::invalid(code)) {
303 ec = make_error_code(error::invalid_close_code);
304 }
305
306 if (status::reserved(code)) {
307 ec = make_error_code(error::reserved_close_code);
308 }
309
310 return code;
311}
Here is the call graph for this function:

◆ extract_reason()

std::string websocketpp::close::extract_reason ( std::string const & payload,
lib::error_code & ec )
inline

The string should be a valid UTF8 message. error::invalid_utf8 will be set if the function extracts a reason that is not valid UTF8.

Parameters
[in]payloadThe payload string to extract a reason from.
[out]ecSet to indicate what error occurred, if any.
Returns
The reason string.

Definition at line 322 of file close.hpp.

324{
325 std::string reason;
326 ec = lib::error_code();
327
328 if (payload.size() > 2) {
329 reason.append(payload.begin()+2,payload.end());
330 }
331
333 ec = make_error_code(error::invalid_utf8);
334 }
335
336 return reason;
337}
bool validate(std::string const &s)
Validate a UTF8 string.
Here is the call graph for this function: