| 518 | } |
| 519 | |
| 520 | void WebSocket::handleNetworkEvent(yasio::io_event* event) |
| 521 | { |
| 522 | int channelIndex = event->cindex(); |
| 523 | auto channel = _service->channel_at(event->cindex()); |
| 524 | switch (event->kind()) |
| 525 | { |
| 526 | case YEK_ON_PACKET: |
| 527 | if (_state == State::CONNECTING) |
| 528 | { |
| 529 | auto&& pkt = event->packet_view(); |
| 530 | this->do_handshake(pkt.data(), pkt.size()); |
| 531 | if (_handshakeFinished) |
| 532 | { |
| 533 | ErrorCode error = ErrorCode::OK; |
| 534 | if (_responseCode == 101) |
| 535 | { |
| 536 | auto it = _responseHeaders.find("sec-websocket-accept"); |
| 537 | if (it != _responseHeaders.end()) |
| 538 | { |
| 539 | auto& secAccept = it->second; |
| 540 | if (_verifySecKey != secAccept) |
| 541 | error = ErrorCode::VERIFY_SEC_ACCEPT_FAILURE; |
| 542 | } |
| 543 | else |
| 544 | error = ErrorCode::NO_SEC_ACCEPT; |
| 545 | } |
| 546 | else |
| 547 | error = ErrorCode::UPGRADE_FAILURE; |
| 548 | |
| 549 | if (error == ErrorCode::OK) |
| 550 | { |
| 551 | _state = State::OPEN; |
| 552 | auto& timerForRead = channel->get_user_timer(); |
| 553 | timerForRead.cancel(); |
| 554 | _transport = event->transport(); |
| 555 | _eventQueue.emplace_back(new WsOpenEvent()); |
| 556 | |
| 557 | // WebSocketProtocol::sendPing(*this); |
| 558 | |
| 559 | // starts websocket heartbeat timer |
| 560 | //_heartbeatTimer->expires_from_now(std::chrono::seconds(30)); |
| 561 | //_heartbeatTimer->async_wait([this](io_service& service) { |
| 562 | // WebSocketProtocol::sendFrame(*this, "WSWS", 4, ws::detail::opcode::ping); |
| 563 | // return false; |
| 564 | //}); |
| 565 | } |
| 566 | else |
| 567 | { |
| 568 | if (!_responseData.empty()) |
| 569 | AXLOGE("WebSocket: handshake fail, detail: {}", _responseData); |
| 570 | |
| 571 | //_state = State::CLOSING; |
| 572 | _service->close(channelIndex); |
| 573 | _eventQueue.emplace_back(new ErrorEvent(error)); |
| 574 | } |
| 575 | } |
| 576 | } |
| 577 | else if (_state == State::OPEN) |
nothing calls this directly
no test coverage detected