From 650bc35eb48527ef7e775364e20b718f16bf9140 Mon Sep 17 00:00:00 2001 From: PQBUG Date: Mon, 12 May 2025 11:29:02 +0000 Subject: [PATCH 01/14] =?UTF-8?q?=E9=80=9A=E4=BF=A1=E7=94=9F=E6=80=81?= =?UTF-8?q?=E7=AE=A1=E6=8E=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: PQBUG --- .../socket/socket_exec/include/socket_exec.h | 55 +++++++++++++++++++ .../socket_module/include/socket_module.h | 2 + .../socket_module/src/socket_module.cpp | 22 ++++++++ 3 files changed, 79 insertions(+) diff --git a/frameworks/js/napi/socket/socket_exec/include/socket_exec.h b/frameworks/js/napi/socket/socket_exec/include/socket_exec.h index 1513bb492..2e877db1c 100644 --- a/frameworks/js/napi/socket/socket_exec/include/socket_exec.h +++ b/frameworks/js/napi/socket/socket_exec/include/socket_exec.h @@ -34,6 +34,9 @@ #include "udp_extra_context.h" #include "udp_send_context.h" #include "napi_utils.h" +#include "common_event_manager.h" +#include "common_event_support.h" +#include "want.h" #include @@ -45,6 +48,8 @@ bool ExecUdpBind(BindContext *context); bool ExecUdpSend(UdpSendContext *context); +bool ExecUdpSendWithDelayTime(UdpSendContext *context); + bool ExecUdpAddMembership(MulticastMembershipContext *context); bool ExecUdpDropMembership(MulticastMembershipContext *context); @@ -63,6 +68,8 @@ bool ExecConnect(ConnectContext *context); bool ExecTcpSend(TcpSendContext *context); +bool ExecTcpSendWithDelayTime(TcpSendContext *context); + bool ExecClose(CloseContext *context); bool ExecGetState(GetStateContext *context); @@ -95,6 +102,14 @@ bool ExecTcpServerGetState(TcpServerGetStateContext *context); bool ExecTcpServerGetLocalAddress(TcpServerGetLocalAddressContext *context); +void SendNewEarlyExecTime(int64_t earlyExecTime, int64_t delayTime); + +void HandleCtrlStatusChanged(bool ctrlStatus); + +void SubscribeCommonEvent(); + +int64_t CalEarlyExecTime(int64_t delayTime); + /* async work callback */ napi_value BindCallback(BindContext *context); @@ -266,5 +281,45 @@ protected: using SocketRecvCallback = std::function &, int> &bufInfo, std::pair &addrInfo, const MessageCallback &callback)>; +static bool isControl_; + +struct DataSendTask { + TcpSendContext* tcpContext_; + UdpSendContext* udpContext_; + int64_t earlyExecTime_; + int64_t delayTime_; + + DataSendTask(TcpSendContext* context, int64_t earlyExecTime, int64_t delayTime) + { + tcpContext_ = context; + this->earlyExecTime_ = earlyExecTime; + this->delayTime_ = delayTime; + } + + DataSendTask(UdpSendContext* context, int64_t earlyExecTime, int64_t delayTime) + { + udpContext_ = context; + this->earlyExecTime_ = earlyExecTime; + this->delayTime_ = delayTime; + } +}; + +struct ControlCompare { + bool operator()(const DataSendTask& a, const DataSendTask& b) const + { + return a.earlyExecTime_ > b.earlyExecTime_; + } +}; + +static std::priority_queue, ControlCompare> controlQueue_; + +class ControlEventSubscriber : public OHOS::EventFwk::CommonEventSubscriber { +public: + explicit ControlEventSubscriber(const OHOS::EventFwk::CommonEventSubscribeInfo &subscribeInfo) + : OHOS::EventFwk::CommonEventSubscriber(subscribeInfo) {}; + virtual void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &eventData) override; +}; + +static std::shared_ptr controlEventSubscriber_; } // namespace OHOS::NetStack::Socket::SocketExec #endif /* COMMUNICATIONNETSTACK_SOCKET_EXEC_H */ diff --git a/frameworks/js/napi/socket/socket_module/include/socket_module.h b/frameworks/js/napi/socket/socket_module/include/socket_module.h index 37cdcfb28..210ac18b5 100644 --- a/frameworks/js/napi/socket/socket_module/include/socket_module.h +++ b/frameworks/js/napi/socket/socket_module/include/socket_module.h @@ -35,6 +35,7 @@ public: static napi_value Bind(napi_env env, napi_callback_info info); static napi_value Send(napi_env env, napi_callback_info info); + static napi_value SendWithDelayTime(napi_env env, napi_callback_info info); static napi_value Close(napi_env env, napi_callback_info info); static napi_value GetState(napi_env env, napi_callback_info info); static napi_value GetLocalAddress(napi_env env, napi_callback_info info); @@ -142,6 +143,7 @@ public: static napi_value Bind(napi_env env, napi_callback_info info); static napi_value Connect(napi_env env, napi_callback_info info); static napi_value Send(napi_env env, napi_callback_info info); + static napi_value SendWithDelayTime(napi_env env, napi_callback_info info); static napi_value Close(napi_env env, napi_callback_info info); static napi_value GetRemoteAddress(napi_env env, napi_callback_info info); static napi_value GetLocalAddress(napi_env env, napi_callback_info info); diff --git a/frameworks/js/napi/socket/socket_module/src/socket_module.cpp b/frameworks/js/napi/socket/socket_module/src/socket_module.cpp index bfbcad5ed..bcabad682 100644 --- a/frameworks/js/napi/socket/socket_module/src/socket_module.cpp +++ b/frameworks/js/napi/socket/socket_module/src/socket_module.cpp @@ -693,6 +693,17 @@ napi_value SocketModuleExports::UDPSocket::Send(napi_env env, napi_callback_info UDP_SEND_NAME, SocketAsyncWork::ExecUdpSend, SocketAsyncWork::UdpSendCallback); } +napi_value SocketModuleExports::UDPSocket::SendWithDelayTime(napi_env env, napi_callback_info info) +{ + return ModuleTemplate::InterfaceWithOutAsyncWorkWithSharedManager( + env, info, + [](napi_env, napi_value, UdpSendContext *context) -> bool { + SocketAsyncWork::ExecUdpSendWithDelayTime(context->GetEnv(), context); + return true; + }, + UDP_SEND_NAME, SocketAsyncWork::ExecUdpSend, SocketAsyncWork::UdpSendCallback); +} + napi_value SocketModuleExports::UDPSocket::Close(napi_env env, napi_callback_info info) { return SOCKET_INTERFACE(CloseContext, ExecClose, CloseCallback, nullptr, UDP_CLOSE_NAME); @@ -796,6 +807,17 @@ napi_value SocketModuleExports::TCPSocket::Send(napi_env env, napi_callback_info TCP_SEND_NAME, SocketAsyncWork::ExecTcpSend, SocketAsyncWork::TcpSendCallback); } +napi_value SocketModuleExports::TCPSocket::SendWithDelayTime(napi_env env, napi_callback_info info) +{ + return ModuleTemplate::InterfaceWithOutAsyncWorkWithSharedManager( + env, info, + [](napi_env, napi_value, TcpSendContext *context) -> bool { + SocketAsyncWork::ExecTcpSendWithDelayTime(context->GetEnv(), context); + return true; + }, + TCP_SEND_NAME, SocketAsyncWork::ExecTcpSend, SocketAsyncWork::TcpSendCallback); +} + napi_value SocketModuleExports::TCPSocket::Close(napi_env env, napi_callback_info info) { return SOCKET_INTERFACE(CloseContext, ExecClose, CloseCallback, nullptr, TCP_CLOSE_NAME); -- Gitee From e0ee7d0785dc5b4fcec2c5a32a8a8ad496c25c5b Mon Sep 17 00:00:00 2001 From: PQBUG Date: Mon, 12 May 2025 11:29:10 +0000 Subject: [PATCH 02/14] =?UTF-8?q?=E9=80=9A=E4=BF=A1=E7=94=9F=E6=80=81?= =?UTF-8?q?=E7=AE=A1=E6=8E=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: PQBUG --- .../socket/socket_exec/src/socket_exec.cpp | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/frameworks/js/napi/socket/socket_exec/src/socket_exec.cpp b/frameworks/js/napi/socket/socket_exec/src/socket_exec.cpp index e57c43aa1..3b2f5e25d 100644 --- a/frameworks/js/napi/socket/socket_exec/src/socket_exec.cpp +++ b/frameworks/js/napi/socket/socket_exec/src/socket_exec.cpp @@ -86,6 +86,10 @@ static constexpr const char *SOCKET_RECV_FROM_MULTI_CAST = "OS_NET_SockMPRD"; static constexpr const char *WILD_ADDRESS = "0.0.0.0"; +static constexpr const char *COMMON_EVENT_CONTROL_STATUS = "usual.event.CONTROL_STATUS"; + +static constexpr const char *COMMON_EVENT_SEND_EARLY_EXEC_TIME = "usual.event.SEND_EARLY_EXEC_TIME"; + namespace OHOS::NetStack::Socket::SocketExec { #define ERROR_RETURN(context, ...) \ do { \ @@ -100,6 +104,7 @@ std::map> g_clientEventManagers; std::condition_variable g_cv; std::mutex g_mutex; std::shared_mutex g_fdMutex; +std::mutex g_queueMutex; std::atomic_int g_userCounter = 0; static void SetIsBound(sa_family_t family, GetStateContext *context, const sockaddr_in *addr4, @@ -1065,6 +1070,36 @@ bool ExecUdpSend(UdpSendContext *context) return result; } +bool ExecUdpSendWithDelayTime(UdpSendContext *context) +{ + if (context->GetDelayTime() == 0 || !isControl_) { + ExecUdpSend(context); + return true; + } + + auto delayTime = context->GetDelayTime(); + auto curEarlyExecTime = CalEarlyExecTime(delayTime); + DataSendTask dataSendTask(context, curEarlyExecTime, delayTime); + + std::unique_lock lock(g_queueMutex); + if (controlQueue_.empty()) { + controlQueue_.push(dataSendTask); + SendNewEarlyExecTime(curEarlyExecTime, delayTime); + lock.unlock(); + return true; + } + + auto earlyExecTime = controlQueue_.top().earlyExecTime_; + controlQueue_.push(dataSendTask); + lock.unlock(); + + if (curEarlyExecTime >= earlyExecTime) { + return true; + } + SendNewEarlyExecTime(curEarlyExecTime, delayTime); + return true; +} + bool ExecTcpBind(BindContext *context) { return ExecBind(context); @@ -1198,6 +1233,36 @@ bool ExecTcpSend(TcpSendContext *context) return result; } +bool ExecTcpSendWithDelayTime(TcpSendContext *context) +{ + if (context->GetDelayTime() == 0 || !isControl_) { + ExecTcpSend(context); + return true; + } + + auto delayTime = context->GetDelayTime(); + auto curEarlyExecTime = CalEarlyExecTime(delayTime); + DataSendTask dataSendTask(context, curEarlyExecTime, delayTime); + + std::unique_lock lock(g_queueMutex); + if (controlQueue_.empty()) { + controlQueue_.push(dataSendTask); + SendNewEarlyExecTime(curEarlyExecTime, delayTime); + lock.unlock(); + return true; + } + + auto earlyExecTime = controlQueue_.top().earlyExecTime_; + controlQueue_.push(dataSendTask); + lock.unlock(); + + if (curEarlyExecTime >= earlyExecTime) { + return true; + } + SendNewEarlyExecTime(curEarlyExecTime, delayTime); + return true; +} + bool ExecClose(CloseContext *context) { if (!CommonUtils::HasInternetPermission()) { @@ -2337,6 +2402,38 @@ bool ExecTcpServerGetState(TcpServerGetStateContext *context) return GetTcpServerState(context); } +void SendNewEarlyExecTime(int64_t earlyExecTime, int64_t delayTime) +{ + OHOS::EventFwk::CommonEventData data; + AAFwk::Want want; + want.SetAction(COMMON_EVENT_SEND_EARLY_EXEC_TIME); + want.SetParam("earlyExecTime", earlyExecTime); + want.SetParam("delayTime", delayTime); + data.SetWant(want); + OHOS::EventFwk::CommonEventPublishInfo publishInfo; + EventFwk::CommonEventManager::PublishCommonEvent(data, publishInfo); +} + +void HandleCtrlStatusChanged(bool ctrlStatus) +{ + isControl_ = ctrlStatus; + if (isControl_) { + return; + } + + std::unique_lock lock(g_queueMutex); + while (!controlQueue_.empty()) { + auto data = controlQueue_.top(); + if (data.tcpContext_ != nullptr) { + ExecTcpSend(data.tcpContext_); + } else if (data.udpContext_ != nullptr){ + ExecUdpSend(data.udpContext_); + } + controlQueue_.pop(); + } + lock.unlock(); +} + napi_value BindCallback(BindContext *context) { context->EmitSharedManager(EVENT_LISTENING, std::make_pair(NapiUtils::GetUndefined(context->GetEnv()), -- Gitee From b4bde2adeab57b57eb052a0e848bb5f035638f46 Mon Sep 17 00:00:00 2001 From: PQBUG Date: Mon, 12 May 2025 11:38:53 +0000 Subject: [PATCH 03/14] =?UTF-8?q?=E9=80=9A=E4=BF=A1=E7=94=9F=E6=80=81?= =?UTF-8?q?=E7=AE=A1=E6=8E=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: PQBUG --- bundle.json | 3 ++- frameworks/js/napi/http/BUILD.gn | 1 + frameworks/js/napi/socket/BUILD.gn | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/bundle.json b/bundle.json index c648b56b7..a4b7c6ae0 100644 --- a/bundle.json +++ b/bundle.json @@ -57,7 +57,8 @@ "libwebsockets", "node", "jsoncpp", - "netmanager_enhanced" + "netmanager_enhanced", + "common_event_service" ] }, "build": { diff --git a/frameworks/js/napi/http/BUILD.gn b/frameworks/js/napi/http/BUILD.gn index 81fa9f8ff..7edab3f5b 100644 --- a/frameworks/js/napi/http/BUILD.gn +++ b/frameworks/js/napi/http/BUILD.gn @@ -142,6 +142,7 @@ ohos_shared_library("http") { "napi:ace_napi", "samgr:samgr_proxy", "time_service:time_client", + "common_event_service:cesfwk_innerkits", ] if (netstack_http_boringssl) { external_deps += [ diff --git a/frameworks/js/napi/socket/BUILD.gn b/frameworks/js/napi/socket/BUILD.gn index 20b498be3..7875072e7 100644 --- a/frameworks/js/napi/socket/BUILD.gn +++ b/frameworks/js/napi/socket/BUILD.gn @@ -144,6 +144,7 @@ ohos_shared_library("socket") { "openssl:libcrypto_shared", "openssl:libssl_shared", "samgr:samgr_proxy", + "common_event_service:cesfwk_innerkits", ] defines = [ "OPENSSL_SUPPRESS_DEPRECATED" ] if (defined(global_parts_info) && -- Gitee From 347f0176b3d62df8195109f84462dc019190fef6 Mon Sep 17 00:00:00 2001 From: PQBUG Date: Mon, 12 May 2025 11:39:07 +0000 Subject: [PATCH 04/14] =?UTF-8?q?=E9=80=9A=E4=BF=A1=E7=94=9F=E6=80=81?= =?UTF-8?q?=E7=AE=A1=E6=8E=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: PQBUG --- .../napi/http/http_exec/include/http_exec.h | 49 ++++++++++ .../js/napi/http/http_exec/src/http_exec.cpp | 97 +++++++++++++++++++ 2 files changed, 146 insertions(+) diff --git a/frameworks/js/napi/http/http_exec/include/http_exec.h b/frameworks/js/napi/http/http_exec/include/http_exec.h index a16f94206..b7ad073b0 100644 --- a/frameworks/js/napi/http/http_exec/include/http_exec.h +++ b/frameworks/js/napi/http/http_exec/include/http_exec.h @@ -33,6 +33,10 @@ #include "napi/native_api.h" #include "request_context.h" +#include "common_event_manager.h" +#include "common_event_support.h" +#include "want.h" + namespace OHOS::NetStack::Http { class HttpResponseCacheExec final { public: @@ -87,6 +91,16 @@ public: static void AsyncRunRequest(RequestContext *context); + static void RunRequestWithDelayTime(RequestContext *context); + + static void SendNewEarlyExecTime(int64_t earlyExecTime, int64_t delayTime); + + static void HandleCtrlStatusChanged(bool ctrlStatus); + + static void SubscribeCommonEvent(); + + static int64_t CalEarlyExecTime(int64_t delayTime); + private: static bool SetOption(CURL *curl, RequestContext *context, struct curl_slist *requestHeader); @@ -227,6 +241,41 @@ private: }; static StaticVariable staticVariable_; #endif + + static bool isControl_; + + static std::mutex mtx; + + struct RequestTask { + RequestContext* context_; + int64_t earlyExecTime_; + int64_t delayTime_; + + RequestTask(RequestContext* context, int64_t earlyExecTime, int64_t delayTime) + { + context_ = context; + this->earlyExecTime_ = earlyExecTime; + this->delayTime_ = delayTime; + } + }; + + struct ControlCompare { + bool operator()(const RequestTask& a, const RequestTask& b) const + { + return a.earlyExecTime_ > b.earlyExecTime_; + } + }; + + static std::priority_queue, ControlCompare> controlQueue_; + + class ControlEventSubscriber : public OHOS::EventFwk::CommonEventSubscriber { + public: + explicit ControlEventSubscriber(const OHOS::EventFwk::CommonEventSubscribeInfo &subscribeInfo) + : OHOS::EventFwk::CommonEventSubscriber(subscribeInfo) {}; + virtual void OnReceiveEvent(const OHOS::EventFwk::CommonEventData &eventData) override; + }; + + static std::shared_ptr controlEventSubscriber_; }; } // namespace OHOS::NetStack::Http diff --git a/frameworks/js/napi/http/http_exec/src/http_exec.cpp b/frameworks/js/napi/http/http_exec/src/http_exec.cpp index 8d4215801..ed93c2413 100755 --- a/frameworks/js/napi/http/http_exec/src/http_exec.cpp +++ b/frameworks/js/napi/http/http_exec/src/http_exec.cpp @@ -79,6 +79,12 @@ } while (0) namespace OHOS::NetStack::Http { +bool HttpExec::isControl_ = true; +std::mutex HttpExec::mtx; +std::priority_queue, + HttpExec::ControlCompare> HttpExec::controlQueue_; +std::shared_ptr HttpExec::controlEventSubscriber_; + #if !HAS_NETMANAGER_BASE static constexpr int CURL_TIMEOUT_MS = 20; static constexpr int CONDITION_TIMEOUT_S = 3600; @@ -117,6 +123,8 @@ static constexpr const int SSL_CTX_EX_DATA_REQUEST_CONTEXT_INDEX = 1; static constexpr const char *HTTP_AF_ONLYV4 = "ONLY_V4"; static constexpr const char *HTTP_AF_ONLYV6 = "ONLY_V6"; +static constexpr const char *COMMON_EVENT_CONTROL_STATUS = "usual.event.NET_CTRL_STATUS"; +static constexpr const char *COMMON_EVENT_SEND_EARLY_EXEC_TIME = "usual.event.SEND_EARLY_EXEC_TIME"; static void RequestContextDeleter(RequestContext *context) { @@ -901,6 +909,8 @@ bool HttpExec::Initialize() return false; } + SubscribeCommonEvent(); + staticVariable_.workThread = std::thread(RunThread); staticVariable_.initialized = true; return staticVariable_.initialized; @@ -1780,6 +1790,93 @@ void HttpExec::AsyncRunRequest(RequestContext *context) HttpAsyncWork::ExecRequest(context->GetEnv(), context); } +void HttpExec::RunRequestWithDelayTime(RequestContext *context) +{ + if (context->GetDelayTime() == 0 || !isControl_) { + NETSTACK_LOGI("Cur request is urgent, or cur ctrl status is release"); + AsyncRunRequest(context); + return; + } + + auto delayTime = context->GetDelayTime(); + auto curEarlyExecTime = CalEarlyExecTime(delayTime); + RequestTask reqTask(context, curEarlyExecTime, delayTime); + + std::unique_lock lock(mtx); + if (controlQueue_.empty()) { + controlQueue_.push(reqTask); + SendNewEarlyExecTime(curEarlyExecTime, delayTime); + lock.unlock(); + return; + } + + auto earlyExecTime = controlQueue_.top().earlyExecTime_; + controlQueue_.push(reqTask); + lock.unlock(); + + if (curEarlyExecTime >= earlyExecTime) { + return; + } + SendNewEarlyExecTime(curEarlyExecTime, delayTime); +} + +void HttpExec::SendNewEarlyExecTime(int64_t earlyExecTime, int64_t delayTime) +{ + OHOS::EventFwk::CommonEventData data; + AAFwk::Want want; + want.SetAction(COMMON_EVENT_SEND_EARLY_EXEC_TIME); + want.SetParam("earlyExecTime", earlyExecTime); + want.SetParam("delayTime", delayTime); + data.SetWant(want); + OHOS::EventFwk::CommonEventPublishInfo publishInfo; + OHOS::EventFwk::CommonEventManager::PublishCommonEvent(data, publishInfo); +} + +void HttpExec::HandleCtrlStatusChanged(bool ctrlStatus) +{ + isControl_ = ctrlStatus; + if (isControl_) { + return; + } + + std::unique_lock lock(mtx); + while (!controlQueue_.empty()) { + AsyncRunRequest(controlQueue_.top().context_); + controlQueue_.pop(); + } + lock.unlock(); +} + +void HttpExec::SubscribeCommonEvent() +{ + EventFwk::MatchingSkills matchingSkills; + matchingSkills.AddEvent(COMMON_EVENT_CONTROL_STATUS); + EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills); + controlEventSubscriber_ = std::make_shared(subscribeInfo); + bool ret = EventFwk::CommonEventManager::SubscribeCommonEvent(controlEventSubscriber_); + if (!ret) { + NETSTACK_LOGE("Subscribe control event fail:%{public}d", ret); + } +} + +void HttpExec::ControlEventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &eventData) +{ + const auto &action = eventData.GetWant().GetAction(); + if (action != COMMON_EVENT_CONTROL_STATUS) { + return; + } + + const auto ctrlStatus = eventData.GetWant().GetBoolParam("ctrlStatus", false); + HandleCtrlStatusChanged(ctrlStatus); +} + +int64_t HttpExec::CalEarlyExecTime(int64_t delayTime) +{ + auto earlyExecTimePoint = std::chrono::system_clock::now() + std::chrono::seconds(delayTime); + auto earlyExecTimeMillisecond = std::chrono::time_point_cast(earlyExecTimePoint); + return earlyExecTimeMillisecond.time_since_epoch().count(); +} + #if !HAS_NETMANAGER_BASE bool HttpExec::IsInitialized() { -- Gitee From 74a5df0eb4b0de5969a8a7b5ab86c53e035e8268 Mon Sep 17 00:00:00 2001 From: PQBUG Date: Mon, 12 May 2025 11:39:14 +0000 Subject: [PATCH 05/14] =?UTF-8?q?=E9=80=9A=E4=BF=A1=E7=94=9F=E6=80=81?= =?UTF-8?q?=E7=AE=A1=E6=8E=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: PQBUG --- .../async_context/include/request_context.h | 4 ++++ .../async_context/src/request_context.cpp | 10 ++++++++++ .../http/http_module/include/http_module.h | 1 + .../napi/http/http_module/src/http_module.cpp | 19 +++++++++++++++++++ 4 files changed, 34 insertions(+) diff --git a/frameworks/js/napi/http/async_context/include/request_context.h b/frameworks/js/napi/http/async_context/include/request_context.h index dc7a92c9e..b96a0e468 100644 --- a/frameworks/js/napi/http/async_context/include/request_context.h +++ b/frameworks/js/napi/http/async_context/include/request_context.h @@ -157,6 +157,10 @@ public: void SetPinnedPubkey(std::string &pubkey); std::string GetPinnedPubkey() const; + + void SetDelayTime(int64_t delayTime); + + int64_t GetDelayTime(); private: uint32_t magicNumber_ = MAGIC_NUMBER; int32_t taskId_ = -1; diff --git a/frameworks/js/napi/http/async_context/src/request_context.cpp b/frameworks/js/napi/http/async_context/src/request_context.cpp index 38b5224bf..c5b5d56b2 100755 --- a/frameworks/js/napi/http/async_context/src/request_context.cpp +++ b/frameworks/js/napi/http/async_context/src/request_context.cpp @@ -1038,4 +1038,14 @@ void RequestContext::ParseAddressFamily(napi_value optionsValue) options.SetAddressFamily(addressFamily); } } + +void RequestContext::SetDelayTime(int64_t delayTime) +{ + delayTime_ = delayTime; +} + +int64_t RequestContext::GetDelayTime() +{ + return delayTime_; +} } // namespace OHOS::NetStack::Http diff --git a/frameworks/js/napi/http/http_module/include/http_module.h b/frameworks/js/napi/http/http_module/include/http_module.h index 9f16542cd..2912c3b37 100644 --- a/frameworks/js/napi/http/http_module/include/http_module.h +++ b/frameworks/js/napi/http/http_module/include/http_module.h @@ -40,6 +40,7 @@ public: static constexpr const char *FUNCTION_OFF = "off"; static napi_value Request(napi_env env, napi_callback_info info); + static napi_value RequestWithDelayTime(napi_env env, napi_callback_info info); static napi_value RequestInStream(napi_env env, napi_callback_info info); static napi_value Destroy(napi_env env, napi_callback_info info); static napi_value On(napi_env env, napi_callback_info info); diff --git a/frameworks/js/napi/http/http_module/src/http_module.cpp b/frameworks/js/napi/http/http_module/src/http_module.cpp index dfa8279ca..d1f4fd298 100644 --- a/frameworks/js/napi/http/http_module/src/http_module.cpp +++ b/frameworks/js/napi/http/http_module/src/http_module.cpp @@ -283,6 +283,25 @@ napi_value HttpModuleExports::HttpRequest::Request(napi_env env, napi_callback_i "Request", HttpAsyncWork::ExecRequest, HttpAsyncWork::RequestCallback); } +napi_value HttpModuleExports::HttpRequest::RequestWithDelayTime(napi_env env, napi_callback_info info) +{ + return ModuleTemplate::InterfaceWithOutAsyncWorkWithManagerWrapper( + env, info, + [](napi_env, napi_value, RequestContext *context) -> bool { +#if !HAS_NETMANAGER_BASE + if (!HttpExec::Initialize()) { + return false; + } +#endif + context->SetModuleId(g_moduleId); + context->SetAtomicService(g_appIsAtomicService); + context->SetBundleName(g_appBundleName); + HttpExec::RunRequestWithDelayTime(context); + return context->IsExecOK(); + }, + "Request", HttpAsyncWork::ExecRequest, HttpAsyncWork::RequestCallback); +} + napi_value HttpModuleExports::HttpRequest::RequestInStream(napi_env env, napi_callback_info info) { return ModuleTemplate::InterfaceWithOutAsyncWorkWithManagerWrapper( -- Gitee From f5975a65c212e2bd2968bf09be8326043d2ea4da Mon Sep 17 00:00:00 2001 From: PQBUG Date: Mon, 12 May 2025 11:39:21 +0000 Subject: [PATCH 06/14] =?UTF-8?q?=E9=80=9A=E4=BF=A1=E7=94=9F=E6=80=81?= =?UTF-8?q?=E7=AE=A1=E6=8E=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: PQBUG --- .../socket/async_context/include/tcp_send_context.h | 6 ++++++ .../socket/async_context/include/udp_send_context.h | 5 +++++ .../napi/socket/async_context/src/tcp_send_context.cpp | 10 ++++++++++ .../napi/socket/async_context/src/udp_send_context.cpp | 10 ++++++++++ .../napi/socket/async_work/include/socket_async_work.h | 4 ++++ .../napi/socket/async_work/src/socket_async_work.cpp | 10 ++++++++++ 6 files changed, 45 insertions(+) diff --git a/frameworks/js/napi/socket/async_context/include/tcp_send_context.h b/frameworks/js/napi/socket/async_context/include/tcp_send_context.h index c9c852535..f52040ea9 100644 --- a/frameworks/js/napi/socket/async_context/include/tcp_send_context.h +++ b/frameworks/js/napi/socket/async_context/include/tcp_send_context.h @@ -44,10 +44,16 @@ public: TCPSendOptions options; + void SetDelayTime(int64_t delayTime); + + int64_t GetDelayTime(); + private: bool CheckParamsType(napi_value *params, size_t paramsCount); bool GetData(napi_value udpSendOptions); + + int64_t delayTime_; }; } // namespace OHOS::NetStack::Socket diff --git a/frameworks/js/napi/socket/async_context/include/udp_send_context.h b/frameworks/js/napi/socket/async_context/include/udp_send_context.h index 432a93189..23f401a35 100644 --- a/frameworks/js/napi/socket/async_context/include/udp_send_context.h +++ b/frameworks/js/napi/socket/async_context/include/udp_send_context.h @@ -46,12 +46,17 @@ public: std::shared_ptr proxyOptions{nullptr}; + void SetDelayTime(int64_t delayTime); + + int64_t GetDelayTime(); private: bool CheckParamsType(napi_value *params, size_t paramsCount); bool GetData(napi_value udpSendOptions); void HandleCallback(napi_value *params, size_t paramsCount); + + int64_t delayTime_; }; } // namespace OHOS::NetStack::Socket diff --git a/frameworks/js/napi/socket/async_context/src/tcp_send_context.cpp b/frameworks/js/napi/socket/async_context/src/tcp_send_context.cpp index 02eb09536..9f05ffb76 100644 --- a/frameworks/js/napi/socket/async_context/src/tcp_send_context.cpp +++ b/frameworks/js/napi/socket/async_context/src/tcp_send_context.cpp @@ -142,4 +142,14 @@ std::string TcpSendContext::GetErrorMessage() const return err; #endif } + +void TcpSendContext::SetDelayTime(int64_t delayTime) +{ + delayTime_ = delayTime; +} + +int64_t TcpSendContext::GetDelayTime() +{ + return delayTime_; +} } // namespace OHOS::NetStack::Socket diff --git a/frameworks/js/napi/socket/async_context/src/udp_send_context.cpp b/frameworks/js/napi/socket/async_context/src/udp_send_context.cpp index b5f9a3cdd..c40a2f498 100644 --- a/frameworks/js/napi/socket/async_context/src/udp_send_context.cpp +++ b/frameworks/js/napi/socket/async_context/src/udp_send_context.cpp @@ -186,4 +186,14 @@ std::string UdpSendContext::GetErrorMessage() const return err; #endif } + +void UdpSendContext::SetDelayTime(int64_t delayTime) +{ + delayTime_ = delayTime; +} + +int64_t UdpSendContext::GetDelayTime() +{ + return delayTime_; +} } // namespace OHOS::NetStack::Socket diff --git a/frameworks/js/napi/socket/async_work/include/socket_async_work.h b/frameworks/js/napi/socket/async_work/include/socket_async_work.h index 3e8753d54..0d4e8e2cf 100644 --- a/frameworks/js/napi/socket/async_work/include/socket_async_work.h +++ b/frameworks/js/napi/socket/async_work/include/socket_async_work.h @@ -29,6 +29,8 @@ public: static void ExecUdpSend(napi_env env, void *data); + static void ExecUdpSendWithDelayTime(napi_env env, void *data); + static void ExecUdpAddMembership(napi_env env, void *data); static void ExecUdpDropMembership(napi_env env, void *data); @@ -47,6 +49,8 @@ public: static void ExecTcpSend(napi_env env, void *data); + static void ExecTcpSendWithDelayTime(napi_env env, void *data); + static void ExecClose(napi_env env, void *data); static void ExecGetState(napi_env env, void *data); diff --git a/frameworks/js/napi/socket/async_work/src/socket_async_work.cpp b/frameworks/js/napi/socket/async_work/src/socket_async_work.cpp index 995d552a1..e8fd503c8 100644 --- a/frameworks/js/napi/socket/async_work/src/socket_async_work.cpp +++ b/frameworks/js/napi/socket/async_work/src/socket_async_work.cpp @@ -48,6 +48,11 @@ void SocketAsyncWork::ExecUdpSend(napi_env env, void *data) BaseAsyncWork::ExecAsyncWork(env, data); } +void SocketAsyncWork::ExecUdpSendWithDelayTime(napi_env env, void *data) +{ + BaseAsyncWork::ExecAsyncWork(env, data); +} + void SocketAsyncWork::ExecUdpAddMembership(napi_env env, void *data) { BaseAsyncWork::ExecAsyncWork(env, data); @@ -98,6 +103,11 @@ void SocketAsyncWork::ExecTcpSend(napi_env env, void *data) BaseAsyncWork::ExecAsyncWork(env, data); } +void SocketAsyncWork::ExecTcpSendWithDelayTime(napi_env env, void *data) +{ + BaseAsyncWork::ExecAsyncWork(env, data); +} + void SocketAsyncWork::ExecGetState(napi_env env, void *data) { BaseAsyncWork::ExecAsyncWork(env, data); -- Gitee From 1752cbf27ca937bb573cd761040d11e4405e34b7 Mon Sep 17 00:00:00 2001 From: PQBUG Date: Mon, 12 May 2025 11:51:37 +0000 Subject: [PATCH 07/14] =?UTF-8?q?=E9=80=9A=E4=BF=A1=E7=94=9F=E6=80=81?= =?UTF-8?q?=E7=AE=A1=E6=8E=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: PQBUG --- .../socket/socket_exec/src/socket_exec.cpp | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/frameworks/js/napi/socket/socket_exec/src/socket_exec.cpp b/frameworks/js/napi/socket/socket_exec/src/socket_exec.cpp index 3b2f5e25d..3cc481774 100644 --- a/frameworks/js/napi/socket/socket_exec/src/socket_exec.cpp +++ b/frameworks/js/napi/socket/socket_exec/src/socket_exec.cpp @@ -2434,6 +2434,36 @@ void HandleCtrlStatusChanged(bool ctrlStatus) lock.unlock(); } +void SubscribeCommonEvent() +{ + EventFwk::MatchingSkills matchingSkills; + matchingSkills.AddEvent(COMMON_EVENT_CONTROL_STATUS); + EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills); + controlEventSubscriber_ = std::make_shared(subscribeInfo); + bool ret = EventFwk::CommonEventManager::SubscribeCommonEvent(controlEventSubscriber_); + if (!ret) { + NETSTACK_LOGE("Subscribe control event fail:%{public}d", ret); + } +} + +void ControlEventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &eventData) +{ + const auto &action = eventData.GetWant().GetAction(); + if (action != COMMON_EVENT_CONTROL_STATUS) { + return; + } + + const auto ctrlStatus = eventData.GetWant().GetBoolParam("ctrlStatus", false); + HandleCtrlStatusChanged(ctrlStatus); +} + +int64_t CalEarlyExecTime(int64_t delayTime) +{ + auto earlyExecTimePoint = std::chrono::system_clock::now() + std::chrono::seconds(delayTime); + auto earlyExecTimeMillisecond = std::chrono::time_point_cast(earlyExecTimePoint); + return earlyExecTimeMillisecond.time_since_epoch().count(); +} + napi_value BindCallback(BindContext *context) { context->EmitSharedManager(EVENT_LISTENING, std::make_pair(NapiUtils::GetUndefined(context->GetEnv()), -- Gitee From b41a85aadde19197e2c265eb4ff2e95d9f22d7c5 Mon Sep 17 00:00:00 2001 From: PQBUG Date: Mon, 12 May 2025 11:54:30 +0000 Subject: [PATCH 08/14] =?UTF-8?q?=E9=80=9A=E4=BF=A1=E7=94=9F=E6=80=81?= =?UTF-8?q?=E7=AE=A1=E6=8E=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: PQBUG --- frameworks/js/napi/http/async_context/include/request_context.h | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/js/napi/http/async_context/include/request_context.h b/frameworks/js/napi/http/async_context/include/request_context.h index b96a0e468..357e69299 100644 --- a/frameworks/js/napi/http/async_context/include/request_context.h +++ b/frameworks/js/napi/http/async_context/include/request_context.h @@ -164,6 +164,7 @@ public: private: uint32_t magicNumber_ = MAGIC_NUMBER; int32_t taskId_ = -1; + int64_t delayTime_; bool usingCache_ = true; bool requestInStream_ = false; std::mutex dlLenLock_; -- Gitee From 0dbc02ae93cf80c479197d84a24c8e2adbe37ff0 Mon Sep 17 00:00:00 2001 From: PQBUG Date: Mon, 26 May 2025 02:29:03 +0000 Subject: [PATCH 09/14] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: PQBUG --- .../async_context/include/request_context.h | 2 +- .../napi/http/http_exec/include/http_exec.h | 6 +---- .../js/napi/http/http_exec/src/http_exec.cpp | 27 ++++++++++--------- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/frameworks/js/napi/http/async_context/include/request_context.h b/frameworks/js/napi/http/async_context/include/request_context.h index 357e69299..31d9db952 100644 --- a/frameworks/js/napi/http/async_context/include/request_context.h +++ b/frameworks/js/napi/http/async_context/include/request_context.h @@ -164,7 +164,7 @@ public: private: uint32_t magicNumber_ = MAGIC_NUMBER; int32_t taskId_ = -1; - int64_t delayTime_; + int64_t delayTime_ = 0L; bool usingCache_ = true; bool requestInStream_ = false; std::mutex dlLenLock_; diff --git a/frameworks/js/napi/http/http_exec/include/http_exec.h b/frameworks/js/napi/http/http_exec/include/http_exec.h index b7ad073b0..e09524ae9 100644 --- a/frameworks/js/napi/http/http_exec/include/http_exec.h +++ b/frameworks/js/napi/http/http_exec/include/http_exec.h @@ -252,11 +252,7 @@ private: int64_t delayTime_; RequestTask(RequestContext* context, int64_t earlyExecTime, int64_t delayTime) - { - context_ = context; - this->earlyExecTime_ = earlyExecTime; - this->delayTime_ = delayTime; - } + : context_(context), earlyExecTime_(earlyExecTime), delayTime_(delayTime) {} }; struct ControlCompare { diff --git a/frameworks/js/napi/http/http_exec/src/http_exec.cpp b/frameworks/js/napi/http/http_exec/src/http_exec.cpp index ed93c2413..d155edf0f 100755 --- a/frameworks/js/napi/http/http_exec/src/http_exec.cpp +++ b/frameworks/js/napi/http/http_exec/src/http_exec.cpp @@ -1802,18 +1802,16 @@ void HttpExec::RunRequestWithDelayTime(RequestContext *context) auto curEarlyExecTime = CalEarlyExecTime(delayTime); RequestTask reqTask(context, curEarlyExecTime, delayTime); - std::unique_lock lock(mtx); - if (controlQueue_.empty()) { + { + if (controlQueue_.empty()) { + controlQueue_.push(reqTask); + SendNewEarlyExecTime(curEarlyExecTime, delayTime); + return; + } + + auto earlyExecTime = controlQueue_.top().earlyExecTime_; controlQueue_.push(reqTask); - SendNewEarlyExecTime(curEarlyExecTime, delayTime); - lock.unlock(); - return; } - - auto earlyExecTime = controlQueue_.top().earlyExecTime_; - controlQueue_.push(reqTask); - lock.unlock(); - if (curEarlyExecTime >= earlyExecTime) { return; } @@ -1840,10 +1838,13 @@ void HttpExec::HandleCtrlStatusChanged(bool ctrlStatus) } std::unique_lock lock(mtx); - while (!controlQueue_.empty()) { - AsyncRunRequest(controlQueue_.top().context_); - controlQueue_.pop(); + std::priority_queue, ControlCompare> ctrlQueueCopied + = controlQueue_; + while (!ctrlQueueCopied.empty()) { + AsyncRunRequest(ctrlQueueCopied.top().context_); + ctrlQueueCopied.pop(); } + ctrlQueueCopied.clear(); lock.unlock(); } -- Gitee From 73f317530749a62172157ba3a2c9dd441f363d7f Mon Sep 17 00:00:00 2001 From: PQBUG Date: Mon, 26 May 2025 02:29:20 +0000 Subject: [PATCH 10/14] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: PQBUG --- .../js/napi/socket/socket_exec/include/socket_exec.h | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/frameworks/js/napi/socket/socket_exec/include/socket_exec.h b/frameworks/js/napi/socket/socket_exec/include/socket_exec.h index 2e877db1c..0835d5698 100644 --- a/frameworks/js/napi/socket/socket_exec/include/socket_exec.h +++ b/frameworks/js/napi/socket/socket_exec/include/socket_exec.h @@ -290,18 +290,10 @@ struct DataSendTask { int64_t delayTime_; DataSendTask(TcpSendContext* context, int64_t earlyExecTime, int64_t delayTime) - { - tcpContext_ = context; - this->earlyExecTime_ = earlyExecTime; - this->delayTime_ = delayTime; - } + : tcpContext_(context), earlyExecTime_(earlyExecTime), delayTime_(delayTime) {} DataSendTask(UdpSendContext* context, int64_t earlyExecTime, int64_t delayTime) - { - udpContext_ = context; - this->earlyExecTime_ = earlyExecTime; - this->delayTime_ = delayTime; - } + : udpContext_(context), earlyExecTime_(earlyExecTime), delayTime_(delayTime) {} }; struct ControlCompare { -- Gitee From f11b1f9a12b32a678b08d26cfac0ba536a4a714e Mon Sep 17 00:00:00 2001 From: PQBUG Date: Thu, 29 May 2025 11:33:18 +0000 Subject: [PATCH 11/14] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: PQBUG --- .../js/napi/http/http_exec/src/http_exec.cpp | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/frameworks/js/napi/http/http_exec/src/http_exec.cpp b/frameworks/js/napi/http/http_exec/src/http_exec.cpp index d155edf0f..1a5c4defd 100755 --- a/frameworks/js/napi/http/http_exec/src/http_exec.cpp +++ b/frameworks/js/napi/http/http_exec/src/http_exec.cpp @@ -1802,16 +1802,17 @@ void HttpExec::RunRequestWithDelayTime(RequestContext *context) auto curEarlyExecTime = CalEarlyExecTime(delayTime); RequestTask reqTask(context, curEarlyExecTime, delayTime); - { - if (controlQueue_.empty()) { - controlQueue_.push(reqTask); - SendNewEarlyExecTime(curEarlyExecTime, delayTime); - return; - } - - auto earlyExecTime = controlQueue_.top().earlyExecTime_; + std::unique_lock lock(mtx); + if (controlQueue_.empty()) { controlQueue_.push(reqTask); + SendNewEarlyExecTime(curEarlyExecTime, delayTime); + return; } + + auto earlyExecTime = controlQueue_.top().earlyExecTime_; + controlQueue_.push(reqTask); + mtx.unlock(); + if (curEarlyExecTime >= earlyExecTime) { return; } @@ -1838,14 +1839,10 @@ void HttpExec::HandleCtrlStatusChanged(bool ctrlStatus) } std::unique_lock lock(mtx); - std::priority_queue, ControlCompare> ctrlQueueCopied - = controlQueue_; - while (!ctrlQueueCopied.empty()) { - AsyncRunRequest(ctrlQueueCopied.top().context_); - ctrlQueueCopied.pop(); - } - ctrlQueueCopied.clear(); - lock.unlock(); + while (!controlQueue_.empty()) { + AsyncRunRequest(controlQueue_.top().context_); + controlQueue_.pop(); + } } void HttpExec::SubscribeCommonEvent() -- Gitee From 3d03653085b2af50ec29211e0dede205e44cdcda Mon Sep 17 00:00:00 2001 From: PQBUG Date: Thu, 29 May 2025 11:55:50 +0000 Subject: [PATCH 12/14] =?UTF-8?q?=E7=BD=91=E7=BB=9C=E7=94=9F=E6=80=81?= =?UTF-8?q?=E7=AE=A1=E6=8E=A7=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: PQBUG --- frameworks/js/napi/http/http_exec/src/http_exec.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/js/napi/http/http_exec/src/http_exec.cpp b/frameworks/js/napi/http/http_exec/src/http_exec.cpp index 1a5c4defd..93d9e5eca 100755 --- a/frameworks/js/napi/http/http_exec/src/http_exec.cpp +++ b/frameworks/js/napi/http/http_exec/src/http_exec.cpp @@ -1811,7 +1811,7 @@ void HttpExec::RunRequestWithDelayTime(RequestContext *context) auto earlyExecTime = controlQueue_.top().earlyExecTime_; controlQueue_.push(reqTask); - mtx.unlock(); + lock.unlock(); if (curEarlyExecTime >= earlyExecTime) { return; -- Gitee From 2f98466760601a7c23dcb9636620e48852e72b4b Mon Sep 17 00:00:00 2001 From: PQBUG Date: Thu, 29 May 2025 12:04:50 +0000 Subject: [PATCH 13/14] =?UTF-8?q?=E9=80=9A=E4=BF=A1=E7=94=9F=E6=80=81?= =?UTF-8?q?=E7=AE=A1=E6=8E=A7=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: PQBUG --- .../js/napi/socket/socket_exec/src/socket_exec.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/frameworks/js/napi/socket/socket_exec/src/socket_exec.cpp b/frameworks/js/napi/socket/socket_exec/src/socket_exec.cpp index 3cc481774..5fa1b4e0a 100644 --- a/frameworks/js/napi/socket/socket_exec/src/socket_exec.cpp +++ b/frameworks/js/napi/socket/socket_exec/src/socket_exec.cpp @@ -1072,6 +1072,9 @@ bool ExecUdpSend(UdpSendContext *context) bool ExecUdpSendWithDelayTime(UdpSendContext *context) { + if (context == nullptr) { + return false; + } if (context->GetDelayTime() == 0 || !isControl_) { ExecUdpSend(context); return true; @@ -1085,7 +1088,6 @@ bool ExecUdpSendWithDelayTime(UdpSendContext *context) if (controlQueue_.empty()) { controlQueue_.push(dataSendTask); SendNewEarlyExecTime(curEarlyExecTime, delayTime); - lock.unlock(); return true; } @@ -1235,6 +1237,9 @@ bool ExecTcpSend(TcpSendContext *context) bool ExecTcpSendWithDelayTime(TcpSendContext *context) { + if (context == nullptr) { + return false; + } if (context->GetDelayTime() == 0 || !isControl_) { ExecTcpSend(context); return true; @@ -1248,7 +1253,6 @@ bool ExecTcpSendWithDelayTime(TcpSendContext *context) if (controlQueue_.empty()) { controlQueue_.push(dataSendTask); SendNewEarlyExecTime(curEarlyExecTime, delayTime); - lock.unlock(); return true; } @@ -2431,7 +2435,6 @@ void HandleCtrlStatusChanged(bool ctrlStatus) } controlQueue_.pop(); } - lock.unlock(); } void SubscribeCommonEvent() -- Gitee From 17b15cb5d0f2e163f91f30fc4bd72e25bcf12743 Mon Sep 17 00:00:00 2001 From: j00939401 Date: Tue, 19 Aug 2025 09:26:14 +0800 Subject: [PATCH 14/14] format modification --- frameworks/js/napi/socket/socket_exec/src/socket_exec.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/js/napi/socket/socket_exec/src/socket_exec.cpp b/frameworks/js/napi/socket/socket_exec/src/socket_exec.cpp index 830286dd5..decb9f64f 100644 --- a/frameworks/js/napi/socket/socket_exec/src/socket_exec.cpp +++ b/frameworks/js/napi/socket/socket_exec/src/socket_exec.cpp @@ -2524,7 +2524,7 @@ void HandleCtrlStatusChanged(bool ctrlStatus) auto data = controlQueue_.top(); if (data.tcpContext_ != nullptr) { ExecTcpSend(data.tcpContext_); - } else if (data.udpContext_ != nullptr){ + } else if (data.udpContext_ != nullptr) { ExecUdpSend(data.udpContext_); } controlQueue_.pop(); -- Gitee