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.
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}