29#ifndef WEBSOCKETPP_CLOSE_HPP
30#define WEBSOCKETPP_CLOSE_HPP
52 static value const blank = 0;
62 static value const omit_handshake = 1;
72 static value const force_tcp_drop = 2;
76 static value const normal = 1000;
80 static value const going_away = 1001;
83 static value const protocol_error = 1002;
91 static value const unsupported_data = 1003;
97 static value const no_status = 1005;
104 static value const abnormal_close = 1006;
110 static value const invalid_payload = 1007;
118 static value const policy_violation = 1008;
121 static value const message_too_big = 1009;
129 static value const extension_required = 1010;
133 static value const internal_endpoint_error = 1011;
138 static value const service_restart = 1012;
143 static value const try_again_later = 1013;
152 static value const tls_handshake = 1015;
160 static value const subprotocol_error = 3000;
167 static value const invalid_subprotocol_data = 3001;
170 static value const rsv_start = 1016;
172 static value const rsv_end = 2999;
180 return ((code >= rsv_start && code <= rsv_end) ||
181 code == 1004 || code == 1014);
185 static value const invalid_low = 999;
187 static value const invalid_high = 5000;
195 return (code <= invalid_low || code >= invalid_high ||
196 code == no_status || code == abnormal_close ||
197 code == tls_handshake);
213 return (code == protocol_error || code == invalid_payload ||
214 code == policy_violation || code == message_too_big ||
215 code == internal_endpoint_error);
230 return "Normal close";
234 return "Protocol error";
235 case unsupported_data:
236 return "Unsupported data";
238 return "No status set";
240 return "Abnormal close";
241 case invalid_payload:
242 return "Invalid payload";
243 case policy_violation:
244 return "Policy violoation";
245 case message_too_big:
246 return "Message too big";
247 case extension_required:
248 return "Extension required";
249 case internal_endpoint_error:
250 return "Internal endpoint error";
252 return "TLS handshake failure";
253 case subprotocol_error:
254 return "Generic subprotocol error";
255 case invalid_subprotocol_data:
256 return "Invalid subprotocol data";
286 ec = lib::error_code();
288 if (payload.size() == 0) {
289 return status::no_status;
290 }
else if (payload.size() == 1) {
292 return status::protocol_error;
297 val.
c[0] = payload[0];
298 val.
c[1] = payload[1];
326 ec = lib::error_code();
328 if (payload.size() > 2) {
329 reason.append(payload.begin()+2,payload.end());
void close(T *e, websocketpp::connection_hdl hdl)
bool terminal(value code)
Determine if the code represents an unrecoverable error.
std::string get_string(value code)
Return a human readable interpretation of a WebSocket close code.
uint16_t value
The type of a close code value.
bool invalid(value code)
Test whether a close code is invalid on the wire.
bool reserved(value code)
Test whether a close code is in a reserved range.
std::string extract_reason(std::string const &payload, lib::error_code &ec)
Extract the reason string from a close payload.
status::value extract_code(std::string const &payload, lib::error_code &ec)
Extract a close code value from a close payload.
@ reserved_close_code
Close code is in a reserved range.
@ invalid_utf8
Invalid UTF-8.
@ invalid_close_code
Close code is invalid.
@ bad_close_code
Unable to parse close code.
bool validate(std::string const &s)
Validate a UTF8 string.
Namespace for the WebSocket++ project.
Type used to convert close statuses between integer and wire representations.