diff --git a/services/distributed/include/base/distributed_socket.h b/services/distributed/include/base/distributed_socket.h index 5ab7035f79f4d72dada56f6656f2498384b965b3..3f9be940fd2713cc55fcc5f780314f5abd5c30f6 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 a673e917dc3e4f55d3b321a2fb9a71de57498417..c29b5f5801f04a50d8c2cc50683520b1630321ac 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 724d08d959528b299bbf726be21495d0b3733f98..fa4410412ae95141ce693da70ce8a2920ae524a9 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; }