From 1f32a1c3af1781cda7950ba601ba5c5499453ccb Mon Sep 17 00:00:00 2001 From: huangfeijie Date: Thu, 3 Nov 2022 20:32:51 +0800 Subject: [PATCH] issue: https://gitee.com/openharmony/arkcompiler_toolchain/issues/I5ZCVQ fix the std::optional error in ios11 replace the use of optional Signed-off-by: huangfeijie --- inspector/ws_server.cpp | 11 +++++++---- websocket/websocket.cpp | 4 ++-- websocket/websocket.h | 3 +-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/inspector/ws_server.cpp b/inspector/ws_server.cpp index a52ec2aa..0bb62438 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 31e0c46c..2310bc63 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 e5146b57..db83a813 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(); -- Gitee