| 402 | #define ntoh64(val) hton64(val) |
| 403 | |
| 404 | bool websocket::read_frame_head(void) |
| 405 | { |
| 406 | reset(); |
| 407 | |
| 408 | unsigned char buf[8]; |
| 409 | |
| 410 | if (client_.read(buf, 2) == -1) { |
| 411 | if (last_error() != ACL_ETIMEDOUT) { |
| 412 | //logger_error("read first two char error: %d, %s", |
| 413 | // last_error(), last_serror()); |
| 414 | } |
| 415 | return false; |
| 416 | } |
| 417 | |
| 418 | update_head_2bytes(buf[0], buf[1]); |
| 419 | |
| 420 | size_t count; |
| 421 | |
| 422 | // payload_len: <= 125 | 126 | 127 |
| 423 | |
| 424 | if (header_.payload_len == 126) { |
| 425 | count = 2; |
| 426 | } else if (header_.payload_len > 126) { |
| 427 | count = 8; |
| 428 | } else { |
| 429 | count = 0; |
| 430 | } |
| 431 | |
| 432 | if (count > 0) { |
| 433 | int ret; |
| 434 | |
| 435 | if ((ret = client_.read(buf, count)) == -1) { |
| 436 | if (last_error() != ACL_ETIMEDOUT) { |
| 437 | logger_error("read ext_payload_len error:" |
| 438 | " %d, %s", last_error(), last_serror()); |
| 439 | } |
| 440 | return false; |
| 441 | } else if (ret == 2) { |
| 442 | unsigned short n; |
| 443 | memcpy(&n, buf, ret); |
| 444 | header_.payload_len = ntohs(n); |
| 445 | } else { |
| 446 | // ret == 8 |
| 447 | memcpy(&header_.payload_len, buf, ret); |
| 448 | header_.payload_len = ntoh64(header_.payload_len); |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | if (!header_.mask) { |
| 453 | return true; |
| 454 | } |
| 455 | |
| 456 | if (client_.read(&header_.masking_key, sizeof(unsigned int)) == -1) { |
| 457 | if (last_error() != ACL_ETIMEDOUT) { |
| 458 | logger_error("read masking_key error: %d, %s", |
| 459 | last_error(), last_serror()); |
| 460 | } |
| 461 | return false; |
no test coverage detected