MCPcopy Create free account
hub / github.com/cocos/cocos-engine / onConnectionError

Method onConnectionError

native/cocos/network/WebSocket-libwebsockets.cpp:1225–1247  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1223}
1224
1225int 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
1249int WebSocketImpl::onConnectionClosed(uint16_t code, const ccstd::string &reason) {
1250 {

Callers

nothing calls this directly

Calls 2

onErrorMethod · 0.45

Tested by

no test coverage detected