* @brief Closes the connection to server asynchronously. * @note It's an asynchronous method, it just notifies websocket thread to exit and returns directly, * If using 'closeAsync' to close websocket connection, * be careful of not using destructed variables in the callback of 'onClose'. */
| 491 | * be careful of not using destructed variables in the callback of 'onClose'. |
| 492 | */ |
| 493 | void WebSocket::closeAsync(uint16_t code, std::string_view reason) |
| 494 | { |
| 495 | if (_state < State::CLOSING) |
| 496 | { |
| 497 | if (_service->is_open(0)) |
| 498 | { |
| 499 | _state = State::CLOSING; |
| 500 | _service->close(0); |
| 501 | } |
| 502 | else |
| 503 | _state = State::CLOSED; |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | void WebSocket::generateHandshakeSecKey() |
| 508 | { |