From 28e01807194c94b3e0f7b29985b23ec72a624833 Mon Sep 17 00:00:00 2001 From: huangfeijie Date: Fri, 4 Nov 2022 15:21:13 +0800 Subject: [PATCH] issue: https://gitee.com/openharmony/arkcompiler_toolchain/issues/I5ZFV2 Adapt to the debugger of the Android platform modify the config of ip address Signed-off-by: huangfeijie --- inspector/ws_server.cpp | 4 ++-- websocket/websocket.cpp | 13 +++++++------ websocket/websocket.h | 4 ++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/inspector/ws_server.cpp b/inspector/ws_server.cpp index 0bb62438..6eef6806 100644 --- a/inspector/ws_server.cpp +++ b/inspector/ws_server.cpp @@ -31,7 +31,7 @@ void WsServer::RunServer() terminateExecution_ = false; webSocket_ = std::make_unique(); #if !defined(OHOS_PLATFORM) - if (!webSocket_->StartForSimulator()) { + if (!webSocket_->StartTcpWebSocket()) { return; } #else @@ -45,7 +45,7 @@ void WsServer::RunServer() } std::string sockName = pidStr + instanceIdStr + componentName_; LOGI("WsServer RunServer: %{public}d%{public}s%{public}s", appPid, instanceIdStr.c_str(), componentName_.c_str()); - if (!webSocket_->StartWebSocket(sockName)) { + if (!webSocket_->StartUnixWebSocket(sockName)) { return; } #endif diff --git a/websocket/websocket.cpp b/websocket/websocket.cpp index 2310bc63..ba949efe 100644 --- a/websocket/websocket.cpp +++ b/websocket/websocket.cpp @@ -259,7 +259,7 @@ bool WebSocket::HttpHandShake() } #if !defined(OHOS_PLATFORM) -bool WebSocket::StartForSimulator() +bool WebSocket::StartTcpWebSocket() { #if defined(WINDOWS_PLATFORM) WORD sockVersion = MAKEWORD(2, 2); // 2: version 2.2 @@ -275,10 +275,11 @@ bool WebSocket::StartForSimulator() return false; } - sockaddr_in sin; - sin.sin_family = AF_INET; - sin.sin_port = htons(9230); // 9230: sockName for tcp - if (bind(fd_, reinterpret_cast(&sin), sizeof(sin)) < SOCKET_SUCCESS) { + sockaddr_in addr_sin; + addr_sin.sin_family = AF_INET; + addr_sin.sin_port = htons(9230); // 9230: sockName for tcp + addr_sin.sin_addr.s_addr = INADDR_ANY; + if (bind(fd_, reinterpret_cast(&addr_sin), sizeof(addr_sin)) < SOCKET_SUCCESS) { LOGE("StartWebSocket bind failed"); return false; } @@ -300,7 +301,7 @@ bool WebSocket::StartForSimulator() return true; } #else -bool WebSocket::StartWebSocket(std::string sockName) +bool WebSocket::StartUnixWebSocket(std::string sockName) { fd_ = socket(AF_UNIX, SOCK_STREAM, 0); // 0: defautlt protocol if (fd_ < SOCKET_SUCCESS) { diff --git a/websocket/websocket.h b/websocket/websocket.h index db83a813..d6fbf410 100644 --- a/websocket/websocket.h +++ b/websocket/websocket.h @@ -47,8 +47,8 @@ public: bool HandleFrame(WebSocketFrame& wsFrame); bool ProtocolUpgrade(const HttpProtocol& req); void SendReply(const std::string& message) const; - bool StartForSimulator(); - bool StartWebSocket(std::string sockName); + bool StartTcpWebSocket(); + bool StartUnixWebSocket(std::string sockName); std::atomic connectState_; private: -- Gitee