diff --git a/inspector/ws_server.cpp b/inspector/ws_server.cpp index a52ec2aa99d78dc75766f06158f1f31d96fff29a..0bb62438a69a173c5d170a12fdf1f0f7c966938f 100644 --- a/inspector/ws_server.cpp +++ b/inspector/ws_server.cpp @@ -31,7 +31,9 @@ void WsServer::RunServer() terminateExecution_ = false; webSocket_ = std::make_unique(); #if !defined(OHOS_PLATFORM) - webSocket_->StartForSimulator(); + if (!webSocket_->StartForSimulator()) { + return; + } #else tid_ = pthread_self(); int appPid = getpid(); @@ -48,9 +50,10 @@ void WsServer::RunServer() } #endif while (!terminateExecution_) { - std::optional message = webSocket_->Decode(); - if (message.has_value()) { - wsOnMessage_(std::move(message.value())); + std::string message = webSocket_->Decode(); + if (!message.empty()) { + LOGI("WsServer OnMessage: %{public}s", message.c_str()); + wsOnMessage_(std::move(message)); } } } diff --git a/websocket/websocket.cpp b/websocket/websocket.cpp index 31e0c46c287e1e74caaec870d8c96a8a526cfcbf..2310bc63ac8cd35bfa7c42bca99167e28e149897 100644 --- a/websocket/websocket.cpp +++ b/websocket/websocket.cpp @@ -214,7 +214,7 @@ bool WebSocket::ProtocolUpgrade(const HttpProtocol& req) return true; } -std::optional WebSocket::Decode() +std::string WebSocket::Decode() { char recvbuf[SOCKET_HEADER_LEN + 1]; int32_t msgLen = recv(client_, recvbuf, SOCKET_HEADER_LEN, 0); @@ -233,7 +233,7 @@ std::optional WebSocket::Decode() HandleFrame(wsFrame); return wsFrame.payload.get(); } - return {}; + return std::string(); } bool WebSocket::HttpHandShake() diff --git a/websocket/websocket.h b/websocket/websocket.h index e5146b577fc64fe4ae76a3b35370717b45abe335..db83a8131b458158bebb16a12929668f0773c053 100644 --- a/websocket/websocket.h +++ b/websocket/websocket.h @@ -17,7 +17,6 @@ #define ARKCOMPILER_TOOLCHAIN_WEBSOCKET_WEBSOCKET_H #include -#include namespace OHOS::ArkCompiler::Toolchain { struct WebSocketFrame { @@ -40,7 +39,7 @@ class WebSocket { public: WebSocket() = default; ~WebSocket() = default; - std::optional Decode(); + std::string Decode(); void Close(); bool DecodeMessage(WebSocketFrame& wsFrame); bool HttpHandShake();