| 1223 | } |
| 1224 | |
| 1225 | int WebSocketImpl::onConnectionError() { |
| 1226 | { |
| 1227 | std::lock_guard<std::mutex> lk(_readyStateMutex); |
| 1228 | LOGD("WebSocket (%p) onConnectionError, state: %d ...\n", this, (int)_readyState); |
| 1229 | if (_readyState == cc::network::WebSocket::State::CLOSED) { |
| 1230 | return 0; |
| 1231 | } |
| 1232 | _readyState = cc::network::WebSocket::State::CLOSING; |
| 1233 | } |
| 1234 | |
| 1235 | std::shared_ptr<std::atomic<bool>> isDestroyed = _isDestroyed; |
| 1236 | wsHelper->sendMessageToCocosThread([this, isDestroyed]() { |
| 1237 | if (*isDestroyed) { |
| 1238 | LOGD("WebSocket instance was destroyed!\n"); |
| 1239 | } else { |
| 1240 | _delegate->onError(_ws, cc::network::WebSocket::ErrorCode::CONNECTION_FAILURE); |
| 1241 | } |
| 1242 | }); |
| 1243 | |
| 1244 | onConnectionClosed(static_cast<uint16_t>(cc::network::WebSocket::ErrorCode::CONNECTION_FAILURE), "connection error"); |
| 1245 | |
| 1246 | return 0; |
| 1247 | } |
| 1248 | |
| 1249 | int WebSocketImpl::onConnectionClosed(uint16_t code, const ccstd::string &reason) { |
| 1250 | { |
nothing calls this directly
no test coverage detected