From 8300a76feb50c7c12d3431c62251e3e12568652f Mon Sep 17 00:00:00 2001 From: wangsen1994 Date: Mon, 23 Jun 2025 16:40:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=87=E6=8D=A2=E5=8F=91=E9=80=81byte?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E4=B8=BA=E5=BC=82=E6=AD=A5=E5=8F=91=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangsen1994 --- .../include/base/distributed_socket.h | 4 ++- .../src/base/distributed_client.cpp | 28 +++++++++++++++---- .../src/base/distributed_socket.cpp | 18 ++++++------ 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/services/distributed/include/base/distributed_socket.h b/services/distributed/include/base/distributed_socket.h index 5ab7035f7..3f9be940f 100644 --- a/services/distributed/include/base/distributed_socket.h +++ b/services/distributed/include/base/distributed_socket.h @@ -31,7 +31,9 @@ int32_t ClientBind(const std::string& name, const std::string& pkgName, void CloseSocket(int32_t socketId); -int32_t ClientSendMsg(int32_t socketId, const void* data, int32_t length, TransDataType type); +int32_t ClientSendBytes(int32_t socketId, const void* data, int32_t length); + +int32_t ClientSendMessage(int32_t socketId, const void* data, int32_t length); } } #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SOCKET_H diff --git a/services/distributed/src/base/distributed_client.cpp b/services/distributed/src/base/distributed_client.cpp index a673e917d..c29b5f580 100644 --- a/services/distributed/src/base/distributed_client.cpp +++ b/services/distributed/src/base/distributed_client.cpp @@ -155,13 +155,29 @@ int32_t DistributedClient::SendMessage(const std::shared_ptr& boxPtr, T AnalyticsUtil::GetInstance().SendHaReport(eventType, result, BRANCH1_ID, errorReason); return result; } - result = ClientSendMsg(socketId, boxPtr->GetByteBuffer(), boxPtr->GetByteLength(), dataType); - if (result != ERR_OK) { - std::string errorReason = "Send failed type: " + std::to_string(type) + " , id: " + StringAnonymous(deviceId); - AnalyticsUtil::GetInstance().SendEventReport(0, result, errorReason); - AnalyticsUtil::GetInstance().SendHaReport(eventType, result, BRANCH2_ID, errorReason); + + if (dataType == TransDataType::DATA_TYPE_MESSAGE) { + result = ClientSendMessage(socketId, boxPtr->GetByteBuffer(), boxPtr->GetByteLength()); + if (result != ERR_OK) { + std::string errorReason = "Send failed type: " + std::to_string(type) + " , id: " + + StringAnonymous(deviceId); + AnalyticsUtil::GetInstance().SendEventReport(0, result, errorReason); + AnalyticsUtil::GetInstance().SendHaReport(eventType, result, BRANCH2_ID, errorReason); + } + return result; } - return result; + + // async to send byte message + std::string errorReason = "Send failed type: " + std::to_string(type) + " , id: " + StringAnonymous(deviceId); + std::function sendByteTask = std::bind([boxPtr, socketId, eventType, errorReason]() { + int32_t res = ClientSendBytes(socketId, boxPtr->GetByteBuffer(), boxPtr->GetByteLength()); + if (res != ERR_OK) { + AnalyticsUtil::GetInstance().SendEventReport(0, res, errorReason); + AnalyticsUtil::GetInstance().SendHaReport(eventType, res, BRANCH2_ID, errorReason); + } + }); + ffrt::submit(sendByteTask); + return ERR_OK; } std::string DistributedClient::ShutdownReasonToString(ShutdownReason reason) diff --git a/services/distributed/src/base/distributed_socket.cpp b/services/distributed/src/base/distributed_socket.cpp index 724d08d95..fa4410412 100644 --- a/services/distributed/src/base/distributed_socket.cpp +++ b/services/distributed/src/base/distributed_socket.cpp @@ -206,15 +206,17 @@ int32_t ClientBind(const std::string& name, const std::string& pkgName, return ERR_OK; } -int32_t ClientSendMsg(int32_t socketId, const void* data, int32_t length, TransDataType type) +int32_t ClientSendBytes(int32_t socketId, const void* data, int32_t length) { - int32_t result = 0; - if (type == TransDataType::DATA_TYPE_BYTES) { - result = ::SendBytes(socketId, data, length); - } else if (type == TransDataType::DATA_TYPE_MESSAGE) { - result = ::SendMessage(socketId, data, length); - } - ANS_LOGI("socket Send %{public}d %{public}d %{public}d %{public}d", socketId, length, type, result); + int32_t result = ::SendBytes(socketId, data, length); + ANS_LOGI("Socket send byte %{public}d %{public}d %{public}d ", socketId, length, result); + return result; +} + +int32_t ClientSendMessage(int32_t socketId, const void* data, int32_t length) +{ + int32_t result = ::SendMessage(socketId, data, length); + ANS_LOGI("Socket send message %{public}d %{public}d %{public}d ", socketId, length, result); return result; } -- Gitee