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 74ed9eca473d8a4868626fbd99d6fa5a851d7368..2dd1810af7744d577aee3cb0a76521d7f5f040b0 100644 --- a/frameworks/js/napi/http/async_context/include/request_context.h +++ b/frameworks/js/napi/http/async_context/include/request_context.h @@ -28,6 +28,9 @@ #include "netstack_network_profiler.h" #endif #include "request_tracer.h" +#ifdef HTTP_HANDOVER_FEATURE +struct HttpHandoverInfo; +#endif namespace OHOS::NetStack::Http { static constexpr const uint32_t MAGIC_NUMBER = 0x86161616; @@ -50,17 +53,6 @@ struct CertsPath { std::string certFile; }; -#ifdef HTTP_HANDOVER_FEATURE -struct RequestHandoverInfo { - RequestHandoverInfo() = default; - ~RequestHandoverInfo() = default; - int32_t handoverNum = 0; - int32_t handoverReason = 0; - double flowControlTime = 0; - int32_t readFlag = 0; -}; -#endif - class RequestContext final : public BaseContext { public: friend class HttpExec; @@ -170,7 +162,7 @@ public: std::string GetPinnedPubkey() const; #ifdef HTTP_HANDOVER_FEATURE - void SetRequestHandoverInfo(int32_t handoverNum, int32_t handoverReason, double flowControlTime, int32_t readFlag); + void SetRequestHandoverInfo(const HttpHandoverInfo &httpHandoverInfo); std::string GetRequestHandoverInfo(); #endif @@ -203,7 +195,7 @@ private: #endif CURL *curlHandle_ = nullptr; #ifdef HTTP_HANDOVER_FEATURE - RequestHandoverInfo requestHandoverInfo_; + std::string httpHandoverInfoStr_ = "no handover"; #endif RequestTracer::Trace trace_; 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 9fbfb8a7c6c8bbc7c87edf87f7d6c7d689f50cf8..1f0e887adc8a81ddd6ba1059cf3c72b582dbac08 100755 --- a/frameworks/js/napi/http/async_context/src/request_context.cpp +++ b/frameworks/js/napi/http/async_context/src/request_context.cpp @@ -36,6 +36,7 @@ #endif #ifdef HTTP_HANDOVER_FEATURE #include "http_handover_handler.h" +#include "http_handover_info.h" #endif static constexpr const int PARAM_JUST_URL = 1; @@ -1048,46 +1049,42 @@ std::string RequestContext::GetPinnedPubkey() const } #ifdef HTTP_HANDOVER_FEATURE -void RequestContext::SetRequestHandoverInfo(int32_t handoverNum, int32_t handoverReason, double flowControlTime, - int32_t readFlag) +void RequestContext::SetRequestHandoverInfo(const HttpHandoverInfo &httpHandoverInfo) { - requestHandoverInfo_.handoverNum = handoverNum; - requestHandoverInfo_.handoverReason = handoverReason; - requestHandoverInfo_.flowControlTime = flowControlTime; - requestHandoverInfo_.readFlag = readFlag; -} - -std::string RequestContext::GetRequestHandoverInfo() -{ - std::string requestHandoverInfo; - if (requestHandoverInfo_.handoverNum <= 0) { - requestHandoverInfo = "no handover"; - return requestHandoverInfo; + if (httpHandoverInfo.handOverNum <= 0) { + httpHandoverInfoStr_ = "no handover"; } - int32_t readFlag = requestHandoverInfo_.readFlag; - requestHandoverInfo += "HandoverNum:"; - requestHandoverInfo += std::to_string(requestHandoverInfo_.handoverNum); - requestHandoverInfo += ", handoverReason:"; - switch (requestHandoverInfo_.handoverReason) { + httpHandoverInfoStr_ = "HandoverNum:"; + httpHandoverInfoStr_ += std::to_string(httpHandoverInfo.handOverNum); + httpHandoverInfoStr_ += ", handverReason:"; + switch (httpHandoverInfo.handOverReason) { case HandoverRequestType::INCOMING: - requestHandoverInfo += "flowControl, flowControlTime:"; + httpHandoverInfoStr_ += "flowControl, flowControlTime:"; break; case HandoverRequestType::NETWORKERROR: - requestHandoverInfo += "netErr, retransTime:"; + httpHandoverInfoStr_ += "netErr, retransTime:"; break; case HandoverRequestType::UNDONE: - requestHandoverInfo += "undone, retransTime:"; + httpHandoverInfoStr_ += "undone, retransTime:"; break; default: - requestHandoverInfo += "unknown type"; + httpHandoverInfoStr_ += "unknown type"; break; } - requestHandoverInfo += std::to_string(requestHandoverInfo_.flowControlTime); - requestHandoverInfo += ", isRead:"; - requestHandoverInfo += readFlag == 1 ? "true" : (readFlag == 0 ? "false" : "error"); - requestHandoverInfo += ", isStream:"; - requestHandoverInfo += this->IsRequestInStream() ? "true" : "false"; - return requestHandoverInfo; + httpHandoverInfoStr_ += std::to_string(httpHandoverInfo.flowControlTime); + httpHandoverInfoStr_ += ", isRead:"; + httpHandoverInfoStr_ += + httpHandoverInfo.readFlag == 1 ? "true" : (httpHandoverInfo.readFlag == 0 ? "false" : "error"); + httpHandoverInfoStr_ += ", isInQueue:"; + httpHandoverInfoStr_ += + httpHandoverInfo.inQueueFlag == 1 ? "true" : (httpHandoverInfo.inQueueFlag == 0 ? "false" : "error"); + httpHandoverInfoStr_ += ", isStream:"; + httpHandoverInfoStr_ += this->IsRequestInStream() ? "true" : "false"; +} + +std::string RequestContext::GetRequestHandoverInfo() +{ + return httpHandoverInfoStr_; } #endif 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 000e882c244286de49811f621a8392f00e74d9fe..0751b2ee74ac61114be3e2defdb3239913ff3ffa 100755 --- a/frameworks/js/napi/http/http_exec/src/http_exec.cpp +++ b/frameworks/js/napi/http/http_exec/src/http_exec.cpp @@ -215,10 +215,7 @@ void HttpExec::SetRequestInfoCallbacks(HttpOverCurl::TransferCallbacks &callback NETSTACK_LOGE("setHandoverInfoCallback context is nullptr, error!"); return; } - context->SetRequestHandoverInfo(httpHandoverInfo.handoverNum, - httpHandoverInfo.handoverReason, - httpHandoverInfo.flowControlTime, - httpHandoverInfo.readFlag); + context->SetRequestHandoverInfo(httpHandoverInfo); }; callbacks.handoverInfoCallback = handoverInfoCallback; callbacks.setHandoverInfoCallback = setHandoverInfoCallback; diff --git a/frameworks/native/http/http_client/http_client.cpp b/frameworks/native/http/http_client/http_client.cpp index 58954c896a5dcd30906b90f697747b61eb723164..62fc184d5a6b92a9d5ade4cf5a69d8577ffd021b 100644 --- a/frameworks/native/http/http_client/http_client.cpp +++ b/frameworks/native/http/http_client/http_client.cpp @@ -113,10 +113,7 @@ void HttpSession::SetRequestInfoCallbacks( return httpHandoverStackInfo; }; static auto setHandoverInfoCallback = [ptr](HttpHandoverInfo httpHandoverInfo, void *) { - ptr->SetRequestHandoverInfo(httpHandoverInfo.handoverNum, - httpHandoverInfo.handoverReason, - httpHandoverInfo.flowControlTime, - httpHandoverInfo.readFlag); + ptr->SetRequestHandoverInfo(httpHandoverInfo); }; callbacks.handoverInfoCallback = handoverInfoCallback; callbacks.setHandoverInfoCallback = setHandoverInfoCallback; diff --git a/frameworks/native/http/http_client/http_client_task.cpp b/frameworks/native/http/http_client/http_client_task.cpp index 4dabf9d9f6d06855f5bd2389dfbd038d953a6186..88d2377d7bdd30a06328069625b65a34a80bedbb 100644 --- a/frameworks/native/http/http_client/http_client_task.cpp +++ b/frameworks/native/http/http_client/http_client_task.cpp @@ -956,45 +956,42 @@ void HttpClientTask::SetSuccess(bool isSuccess) isSuccess_ = isSuccess; } -void HttpClientTask::SetRequestHandoverInfo( - int32_t handoverNum, int32_t handoverReason, double flowControlTime, int32_t readFlag) +void HttpClientTask::SetRequestHandoverInfo(const HttpHandoverInfo &httpHandoverInfo) { - handoverNum_ = handoverNum; - handoverReason_ = handoverReason; - flowControlTime_ = flowControlTime; - readFlag_ = readFlag; -} - -std::string HttpClientTask::GetRequestHandoverInfo() -{ - std::string requestHandoverInfo; - if (handoverNum_ <= 0) { - requestHandoverInfo = "no handover"; - return requestHandoverInfo; + if (httpHandoverInfo.handOverNum <= 0) { + httpHandoverInfoStr_ = "no handover"; } - requestHandoverInfo += "HandoverNum:"; - requestHandoverInfo += std::to_string(handoverNum_); - requestHandoverInfo += ", handoverReason:"; - switch (handoverReason_) { + httpHandoverInfoStr_ = "HandoverNum:"; + httpHandoverInfoStr_ += std::to_string(httpHandoverInfo.handOverNum); + httpHandoverInfoStr_ += ", handoverReason:"; + switch (httpHandoverInfo.handOverReason) { case HandoverRequestType::INCOMING: - requestHandoverInfo += "flowControl, flowControlTime:"; + httpHandoverInfoStr_ += "flowControl, flowControlTime:"; break; case HandoverRequestType::NETWORKERROR: - requestHandoverInfo += "netErr, retransTime:"; + httpHandoverInfoStr_ += "netErr, retransTime:"; break; case HandoverRequestType::UNDONE: - requestHandoverInfo += "undone, retransTime:"; + httpHandoverInfoStr_ += "undone, retransTime:"; break; default: - requestHandoverInfo += "unkown type"; + httpHandoverInfoStr_ += "unkown type"; break; } - requestHandoverInfo += std::to_string(flowControlTime_); - requestHandoverInfo += ", isRead:"; - requestHandoverInfo += readFlag_ == 1 ? "true" : (readFlag_ == 0 ? "false" : "error"); - requestHandoverInfo += ", isStream:"; - requestHandoverInfo += onDataReceive_ ? "true" : "false"; - return requestHandoverInfo; + httpHandoverInfoStr_ += std::to_string(httpHandoverInfo.flowControlTime); + httpHandoverInfoStr_ += ", isRead:"; + httpHandoverInfoStr_ += + httpHandoverInfo.readFlag == 1 ? "true" : (httpHandoverInfo.readFlag == 0 ? "false" : "error"); + httpHandoverInfoStr_ += ", isIInQueue:"; + httpHandoverInfoStr_ += + httpHandoverInfo.inQueueFlag == 1 ? "true" : (httpHandoverInfo.inQueueFlag == 0 ? "false" : "error"); + httpHandoverInfoStr_ += ", isStream:"; + httpHandoverInfoStr_ += onDataReceive_ ? "true" : "false"; +} + +std::string HttpClientTask::GetRequestHandoverInfo() +{ + return httpHandoverInfoStr_; } #endif diff --git a/interfaces/innerkits/http_client/include/http_client_task.h b/interfaces/innerkits/http_client/include/http_client_task.h index 797c33c0a53010387eb5af4261391c1b4535e888..f62c8d7d836abc4a55b34e01def03f90043186c3 100644 --- a/interfaces/innerkits/http_client/include/http_client_task.h +++ b/interfaces/innerkits/http_client/include/http_client_task.h @@ -30,6 +30,9 @@ #if HAS_NETMANAGER_BASE #include "netstack_network_profiler.h" #endif +#ifdef HTTP_HANDOVER_FEATURE +struct HttpHandoverInfo; +#endif namespace OHOS { namespace NetStack { @@ -386,8 +389,7 @@ private: /** * Set the request information and print it to the log. */ - void SetRequestHandoverInfo(int32_t handoverNum, int32_t handoverReason, double flowControlTime, - int32_t readFlag); + void SetRequestHandoverInfo(const HttpHandoverInfo &httpHandoverInfo); #endif /** @@ -424,10 +426,7 @@ private: HttpClientError error_; #ifdef HTTP_HANDOVER_FEATURE bool isSuccess_ = false; - int32_t handoverNum_ = -1; - int32_t handoverReason_ = -1; - double flowControlTime_ = 0.0; - int32_t readFlag_ = -1; + std::string httpHandoverInfoStr_ = "no handover"; #endif TaskType type_; diff --git a/test/unittest/http_client/BUILD.gn b/test/unittest/http_client/BUILD.gn index 02847e32e318c1f99f7c13fd4b85720dd9ea772a..c56a7add772584e68d0cf699ae87dcf64f949d81 100644 --- a/test/unittest/http_client/BUILD.gn +++ b/test/unittest/http_client/BUILD.gn @@ -71,6 +71,7 @@ ohos_unittest("http_client_unittest") { "HAS_NETMANAGER_BASE=1", "HTTP_HANDOVER_FEATURE", ] + include_dirs += [ "$SUBSYSTEM_DIR/netstack/utils/http_over_curl/include" ] } part_name = "netstack" diff --git a/test/unittest/http_client/HttpClientTaskTest.cpp b/test/unittest/http_client/HttpClientTaskTest.cpp index ba667156272c05879382c858998705ac7079c8ad..03dff51e7f10d85f6330338caf6f20f5f9a5d04f 100644 --- a/test/unittest/http_client/HttpClientTaskTest.cpp +++ b/test/unittest/http_client/HttpClientTaskTest.cpp @@ -33,6 +33,9 @@ #include "net_conn_client.h" #include "network_security_config.h" #endif +#ifdef HTTP_HANDOVER_FEATURE +#include "http_handover_info.h" +#endif using namespace OHOS::NetStack::HttpClient; using namespace testing; @@ -1345,6 +1348,7 @@ HWTEST_F(HttpClientTaskTest, ProcessErrorTest001, TestSize.Level1) EXPECT_FALSE(error.GetErrorMessage().empty()); } +#ifdef HTTP_HANDOVER_FEATURE HWTEST_F(HttpClientTaskTest, HandoverInfoTest, TestSize.Level1) { HttpClientRequest httpReq; @@ -1354,28 +1358,26 @@ HWTEST_F(HttpClientTaskTest, HandoverInfoTest, TestSize.Level1) HttpSession &session = HttpSession::GetInstance(); auto task = session.CreateTask(httpReq); - int32_t handoverNum = 1; - int32_t handoverReason = 0; - double flowControlTime = 1.0; - int32_t readFlag = 0; - task->SetRequestHandoverInfo(handoverNum, handoverReason, flowControlTime, readFlag); + HttpHandoverInfo httpHandoverInfo; + task->SetRequestHandoverInfo(httpHandoverInfo); std::string handoverInfo = task->GetRequestHandoverInfo(); - handoverReason = 1; - readFlag = 1; - task->SetRequestHandoverInfo(handoverNum, handoverReason, flowControlTime, readFlag); + httpHandoverInfo.handOverReason = 1; + httpHandoverInfo.readFlag = 1; + task->SetRequestHandoverInfo(httpHandoverInfo); handoverInfo = task->GetRequestHandoverInfo(); - handoverReason = 2; - readFlag = 2; - task->SetRequestHandoverInfo(handoverNum, handoverReason, flowControlTime, readFlag); + httpHandoverInfo.handOverReason = 2; + httpHandoverInfo.readFlag = 2; + task->SetRequestHandoverInfo(httpHandoverInfo); handoverInfo = task->GetRequestHandoverInfo(); - handoverReason = 3; - task->SetRequestHandoverInfo(handoverNum, handoverReason, flowControlTime, readFlag); + httpHandoverInfo.handOverReason = 3; + task->SetRequestHandoverInfo(httpHandoverInfo); handoverInfo = task->GetRequestHandoverInfo(); EXPECT_TRUE(task->Start()); } +#endif HWTEST_F(HttpClientTaskTest, SetSslTypeAndClientEncCertTest001, TestSize.Level1) { diff --git a/test/unittest/utils/http_handover_handler/http_handover_handler_test.cpp b/test/unittest/utils/http_handover_handler/http_handover_handler_test.cpp index 4a074002e403a5494fd5a98d6c3a3371aa441297..e1eb7ac716a8ca1d136660c977783ec01bec86bf 100644 --- a/test/unittest/utils/http_handover_handler/http_handover_handler_test.cpp +++ b/test/unittest/utils/http_handover_handler/http_handover_handler_test.cpp @@ -158,6 +158,7 @@ HWTEST_F(HttpHandoverHandlerTest, HttpHandoverHandlerTestCallbackEvent, TestSize CURL *handle = GetCurlHandle(); EXPECT_EQ(SingletonHttpHandoverHandler::GetInstance()->IsRequestRead(handle), 0); + EXPECT_EQ(SingletonHttpHandoverHandler::GetInstance()->IsRequestInQueue(handle), 1); } HWTEST_F(HttpHandoverHandlerTest, HttpHandoverHandlerTestHandoverQuery, TestSize.Level2) diff --git a/utils/http_over_curl/include/http_handover_handler.h b/utils/http_over_curl/include/http_handover_handler.h index 7e9866e531d191f433f23c90eeb37dc6e4cfdd5a..f60779b9d08b42d1e6e5a630f340b0c8ecb3ea76 100644 --- a/utils/http_over_curl/include/http_handover_handler.h +++ b/utils/http_over_curl/include/http_handover_handler.h @@ -33,18 +33,18 @@ namespace OHOS::NetStack::HttpOverCurl { struct RequestInfo; -typedef void *(*HTTP_HAND_OVER_INIT)(void *user, void (*HMS_NetworkBoost_HandoverEventCallback)(void *), - void (*HMS_NetworkBoost_HandoverTimerCallback)(void *, long), const char* stackName); -typedef int32_t (*HTTP_HAND_OVER_UNINIT)(void *handle); -typedef void (*HTTP_HAND_OVER_QUERY)(void *handle, int32_t *status, int32_t *netId); -typedef void (*HTTP_HAND_OVER_ADD)(void *handle, void *userp, int32_t type, int32_t readFlag); -typedef void (*HTTP_HAND_OVER_DEL)(void *handle, void *userp, bool isSuccess); -typedef int32_t (*HTTP_HAND_OVER_QUERY_REQUEST)(void *handle, void *userp, int32_t *handOverReason, - double *flowControlTime, int32_t *readFlag); -typedef void (*HTTP_HAND_OVER_REPORT_TIMEOUT)(void *handle); +typedef void *(*HTTP_HAND_OVER_INIT)(const void *user, + void (*HMS_NetworkBoost_HandoverEventCallback)(const void *), + void (*HMS_NetworkBoost_HandoverTimerCallback)(const void *, long), const char *stackName); +typedef int32_t (*HTTP_HAND_OVER_UNINIT)(const void *handle); +typedef void (*HTTP_HAND_OVER_QUERY)(const void *handle, int32_t *status, int32_t *netId); +typedef void (*HTTP_HAND_OVER_ADD)(const void *handle, const void *userp, HttpHandoverInfo httpHandoverInfo); +typedef void (*HTTP_HAND_OVER_DEL)(const void *handle, const void *userp, bool isSuccess); +typedef HttpHandoverInfo (*HTTP_HAND_OVER_QUERY_REQUEST)(const void *handle, const void *userp); +typedef void (*HTTP_HAND_OVER_REPORT_TIMEOUT)(const void *handle); -void HandoverCallback(void *user); -void HandoverTimerCallback(void *user, long timeoutMs); +void HandoverCallback(const void *user); +void HandoverTimerCallback(const void *user, long timeoutMs); bool CheckSocketTime(void *user, curl_socket_t fd); curl_socket_t OpenSocket(void *user, curlsocktype purpose, struct curl_sockaddr *addr); int CloseSocketCallback(void *user, curl_socket_t fd); @@ -76,18 +76,19 @@ public: bool RetransRequest(std::map &ongoingRequests, CURLM *multi, RequestInfo *request); bool CheckRequestCanRetrans(RequestInfo *request, int32_t requestType, CURLcode result); void UndoneRequestHandle(std::map &ongoingRequests, CURLM *multi); + int32_t IsRequestInQueue(CURL *easyHandle); int32_t IsRequestRead(CURL *easyHandle); int32_t IsRequestRead(CURL *easyHandle, time_t &recvtime, time_t &sendtime); bool IsNetworkErrorTypeCorrect(CURLcode result); bool ProcessRequestNetError(std::map &ongoingRequests, CURLM *multi, RequestInfo *requestInfo, CURLMsg *msg); - void AddRequest(RequestInfo *requestInfo, int32_t type); + void AddRequest(RequestInfo *requestInfo, int32_t handoverReason); void DelRequest(RequestInfo *requestInfo); - int32_t QueryRequest(void *userp, int32_t &handOverReason, double &flowControlTime, int32_t &readFlag); int32_t GetStatus(); void SetStatus(int32_t status); int32_t GetNetId(); void SetNetId(int32_t netId); + private: void *netHandoverHandler_ = nullptr; void *httpHandoverManager_ = nullptr; diff --git a/utils/http_over_curl/include/http_handover_info.h b/utils/http_over_curl/include/http_handover_info.h index 09f1b6615f45ce4a13a7df0153b4fb6c734bd00d..5eb96770d648c88bd2448aacb7057180be7da249 100644 --- a/utils/http_over_curl/include/http_handover_info.h +++ b/utils/http_over_curl/include/http_handover_info.h @@ -26,10 +26,14 @@ struct HttpHandoverStackInfo { }; struct HttpHandoverInfo { - int32_t handoverNum = 0; - int32_t handoverReason = 0; + uint32_t handOverId = 0; + uint32_t handOverNum = 0; // 0 means no handover or query failed. + int32_t handOverReason = 0; + uint64_t startTime = 0; double flowControlTime = 0.0; int32_t readFlag = 0; + int32_t inQueueFlag = 0; + bool isHistory = false; }; enum HandoverRequestType { diff --git a/utils/http_over_curl/src/http_handover_handler.cpp b/utils/http_over_curl/src/http_handover_handler.cpp index 9cdd69121fd16284b7435a6907cadec4dbd3c313..918f2c9735acf12302c6a6a7480e04d0582c0fb1 100644 --- a/utils/http_over_curl/src/http_handover_handler.cpp +++ b/utils/http_over_curl/src/http_handover_handler.cpp @@ -34,18 +34,18 @@ HttpHandoverHandler::HttpHandoverHandler() initsuccess_ = Initialize(); } -void HandoverCallback(void *user) +void HandoverCallback(const void *user) { if (user == nullptr) { NETSTACK_LOGE("handover callback user is nullptr"); return; } - HttpHandoverHandler* const handoverhandler = reinterpret_cast(user); + HttpHandoverHandler* const handoverhandler = reinterpret_cast(const_cast(user)); handoverhandler->SetHandoverEvent(); } -void HandoverTimerCallback(void *user, long timeoutMs) +void HandoverTimerCallback(const void *user, long timeoutMs) { NETSTACK_LOGD("HandoverTimerCallback enter, set timeout %{public}ld ms.", timeoutMs); if (user == nullptr) { @@ -53,14 +53,14 @@ void HandoverTimerCallback(void *user, long timeoutMs) return; } - HttpHandoverHandler* const handoverHandler = reinterpret_cast(user); + HttpHandoverHandler* const handoverHandler = reinterpret_cast(const_cast(user)); handoverHandler->SetHandoverTimeoutEvent(timeoutMs); } bool CheckSocketTime(void *user, curl_socket_t fd) { auto handover = static_cast(user); - if (handover && handover->CheckSocketOpentimeLessThanEndTime(fd)) { + if (handover && handover->CheckSocketOpentimeLessThanEndTime(fd)) { // LCOV_EXCL_LINE return false; } return true; @@ -69,7 +69,7 @@ bool CheckSocketTime(void *user, curl_socket_t fd) curl_socket_t OpenSocket(void *user, curlsocktype purpose, struct curl_sockaddr *addr) { curl_socket_t sockfd = socket(addr->family, addr->socktype, addr->protocol); - if (sockfd < 0) { + if (sockfd < 0) { // LCOV_EXCL_LINE NETSTACK_LOGE("Failed to open socket: %{public}d, errno: %{public}d", sockfd, errno); return -1; } @@ -87,7 +87,7 @@ int CloseSocketCallback(void *user, curl_socket_t fd) handover->EraseFd(fd); } int ret = close(fd); - if (ret < 0) { + if (ret < 0) { // LCOV_EXCL_LINE NETSTACK_LOGE("Failed to close socket: %{public}d, errno: %{public}d", fd, errno); return ret; } @@ -128,7 +128,7 @@ bool HttpHandoverHandler::Initialize() { const std::string HTTP_HANDOVER_WRAPPER_PATH = "/system/lib64/libhttp_handover.z.so"; netHandoverHandler_ = dlopen(HTTP_HANDOVER_WRAPPER_PATH.c_str(), RTLD_NOW); - if (netHandoverHandler_ == nullptr) { + if (netHandoverHandler_ == nullptr) { // LCOV_EXCL_LINE NETSTACK_LOGE("libhttp_handover.z.so was not loaded, error: %{public}s", dlerror()); return false; } @@ -145,9 +145,11 @@ bool HttpHandoverHandler::Initialize() (HTTP_HAND_OVER_QUERY_REQUEST)dlsym(netHandoverHandler_, "HMS_NetworkBoost_HttpHandoverManagerQueryRequest"); httpHandoverReportTimeout_ = (HTTP_HAND_OVER_REPORT_TIMEOUT)dlsym(netHandoverHandler_, "HMS_NetworkBoost_HttpHandoverManagerReportTimeout"); + // LCOV_EXCL_START bool hasFuncNull = (httpHandoverInit_ == nullptr || httpHandoverUninit_ == nullptr || httpHandoverQuery_ == nullptr || httpHandoverAddRequest_ == nullptr || httpHandoverDelRequest_ == nullptr || httpHandoverQueryRequest_ == nullptr || httpHandoverReportTimeout_ == nullptr); + // LCOV_EXCL_STOP if (hasFuncNull) { NETSTACK_LOGE("http handover wrapper symbol failed, error: %{public}s", dlerror()); return false; @@ -164,10 +166,10 @@ bool HttpHandoverHandler::Initialize() HttpHandoverHandler::~HttpHandoverHandler() { NETSTACK_LOGD("start httpHandoverUninit_"); - if (httpHandoverManager_ != nullptr) { + if (httpHandoverManager_ != nullptr) { // LCOV_EXCL_LINE httpHandoverUninit_(httpHandoverManager_); } - if (netHandoverHandler_ != nullptr) { + if (netHandoverHandler_ != nullptr) { // LCOV_EXCL_LINE dlclose(netHandoverHandler_); } httpHandoverManager_ = nullptr; @@ -215,11 +217,11 @@ void HttpHandoverHandler::SetHandoverTimeoutEvent(long timeoutMs) void HttpHandoverHandler::HandoverQuery() { - if (httpHandoverQuery_ == nullptr || httpHandoverManager_ == nullptr) { + if (httpHandoverQuery_ == nullptr || httpHandoverManager_ == nullptr) { // LCOV_EXCL_LINE NETSTACK_LOGE("nullptr param error"); return; } - httpHandoverQuery_(httpHandoverManager_, &status_, &netId_); + httpHandoverQuery_(httpHandoverManager_, &status_, &netId_); // LCOV_EXCL_LINE } bool HttpHandoverHandler::CheckSocketOpentimeLessThanEndTime(curl_socket_t fd) @@ -228,7 +230,7 @@ bool HttpHandoverHandler::CheckSocketOpentimeLessThanEndTime(curl_socket_t fd) return false; } bool ret = socketopentime_[fd] < endTime_; - if (ret) { + if (ret) { // LCOV_EXCL_LINE NETSTACK_LOGD("Old fd:%{public}d fdtime:%{public}d endTime:%{public}d", (int)fd, socketopentime_[fd], endTime_); } return ret; @@ -300,22 +302,25 @@ bool HttpHandoverHandler::RetransRequest(std::map &ongoin bool HttpHandoverHandler::CheckRequestCanRetrans(RequestInfo *request, int32_t requestType, CURLcode result) { - if (request == nullptr) { + if (request == nullptr) { // LCOV_EXCL_LINE return false; } time_t recvtime = 0; time_t sendtime = 0; int32_t readFlag = IsRequestRead(request->easyHandle, recvtime, sendtime); - if (readFlag == -1) { + if (readFlag == -1) { // LCOV_EXCL_LINE return false; } + HttpHandoverStackInfo httpHandoverStackInfo = request->callbacks.handoverInfoCallback(request->opaqueData); + // LCOV_EXCL_START bool isSafe = (httpHandoverStackInfo.method == METHOD_GET || httpHandoverStackInfo.method == METHOD_HEAD || httpHandoverStackInfo.method == METHOD_OPTIONS || httpHandoverStackInfo.method == METHOD_TRACE); bool ret = false; if (IsConnectError(result) || sendtime == 0 || (isSafe && (!httpHandoverStackInfo.isInStream || readFlag == 0))) { ret = true; } + // LCOV_EXCL_STOP if (requestType == HandoverRequestType::INCOMING || requestType == HandoverRequestType::NETWORKERROR) { return ret; } @@ -348,6 +353,7 @@ void HttpHandoverHandler::UndoneRequestHandle(std::map &o ++it; continue; } + // LCOV_EXCL_START if (requestInfo != nullptr && requestInfo->callbacks.doneCallback) { CURLMsg message; message.msg = CURLMSG_DONE; @@ -355,6 +361,7 @@ void HttpHandoverHandler::UndoneRequestHandle(std::map &o requestInfo->callbacks.doneCallback(&message, requestInfo->opaqueData); } it = ongoingRequests.erase(it); + // LCOV_EXCL_STOP } else { ++it; } @@ -365,7 +372,7 @@ void HttpHandoverHandler::HandoverRequestCallback(std::mapReset(); HandoverQuery(); - NETSTACK_LOGD("Enter HandoverRequestCallback status %{public}d", GetStatus()); + NETSTACK_LOGD("Enter HandoverRequestCallback status %{public}d", GetStatus()); // LCOV_EXCL_START if (GetStatus() == HttpHandoverHandler::START) { NETSTACK_LOGD("start ongoingRequests:%{public}d", (int)ongoingRequests.size()); for (auto &request : ongoingRequests) { @@ -389,7 +396,7 @@ void HttpHandoverHandler::HandoverRequestCallback(std::map &ong void HttpHandoverHandler::SetHandoverInfo(RequestInfo *requestInfo) { - if (requestInfo != nullptr) { - int32_t handoverReason = 0; - double flowControlTime = 0; - int32_t readFlag = 0; - int32_t handOverNum = - QueryRequest(requestInfo->opaqueData, handoverReason, flowControlTime, readFlag); - HttpHandoverInfo httpHandoverInfo; - httpHandoverInfo.handoverNum = handOverNum; - httpHandoverInfo.handoverReason = handoverReason; - httpHandoverInfo.flowControlTime = flowControlTime; - httpHandoverInfo.readFlag = readFlag; - requestInfo->callbacks.setHandoverInfoCallback(httpHandoverInfo, requestInfo->opaqueData); - DelRequest(requestInfo); + if (requestInfo == nullptr || requestInfo->opaqueData == nullptr) { + NETSTACK_LOGE("handover requestInfo nullptr error"); + return; } + HttpHandoverInfo httpHandoverInfo = httpHandoverQueryRequest_(httpHandoverManager_, requestInfo->opaqueData); + requestInfo->callbacks.setHandoverInfoCallback(httpHandoverInfo, requestInfo->opaqueData); + DelRequest(requestInfo); } bool HttpHandoverHandler::ProcessRequestNetError(std::map &ongoingRequests, CURLM *multi, @@ -463,7 +474,7 @@ bool HttpHandoverHandler::ProcessRequestNetError(std::map { if (!requestInfo || requestEndtime_.count(requestInfo) == 0) { return false; - } + } // LCOV_EXCL_START int endTime = requestEndtime_[requestInfo]; requestEndtime_.erase(requestInfo); if (!msg || !IsNetworkErrorTypeCorrect(msg->data.result)) { @@ -480,18 +491,21 @@ bool HttpHandoverHandler::ProcessRequestNetError(std::map NETSTACK_LOGD("networkerror after end status"); AddRequest(requestInfo, HandoverRequestType::NETWORKERROR); return RetransRequest(ongoingRequests, multi, requestInfo); - } + } // LCOV_EXCL_STOP return false; } void HttpHandoverHandler::AddRequest(RequestInfo *requestInfo, int32_t type) { - if (httpHandoverManager_ == nullptr) { + if (httpHandoverManager_ == nullptr) { // LCOV_EXCL_LINE NETSTACK_LOGE("httpHandoverManager_ nullptr error"); return; } - httpHandoverAddRequest_(httpHandoverManager_, requestInfo->opaqueData, type, - IsRequestRead(requestInfo->easyHandle)); + HttpHandoverInfo httpHandoverInfo; + httpHandoverInfo.handOverReason = type; + httpHandoverInfo.readFlag = IsRequestRead(requestInfo->easyHandle); + httpHandoverInfo.inQueueFlag = IsRequestInQueue(requestInfo->easyHandle); + httpHandoverAddRequest_(httpHandoverManager_, requestInfo->opaqueData, httpHandoverInfo); // LCOV_EXCL_LINE } void HttpHandoverHandler::DelRequest(RequestInfo *requestInfo) @@ -499,19 +513,11 @@ void HttpHandoverHandler::DelRequest(RequestInfo *requestInfo) if (httpHandoverManager_ == nullptr) { NETSTACK_LOGE("httpHandoverManager_ nullptr error"); return; + // LCOV_EXCL_START } HttpHandoverStackInfo httpHandoverStackInfo = requestInfo->callbacks.handoverInfoCallback(requestInfo->opaqueData); httpHandoverDelRequest_(httpHandoverManager_, requestInfo->opaqueData, httpHandoverStackInfo.isSuccess); -} - -int32_t HttpHandoverHandler::QueryRequest(void *userp, int32_t &handOverReason, double &flowControlTime, - int32_t &readFlag) -{ - if (httpHandoverManager_ == nullptr) { - NETSTACK_LOGE("httpHandoverManager_ nullptr error"); - return -1; - } - return httpHandoverQueryRequest_(httpHandoverManager_, userp, &handOverReason, &flowControlTime, &readFlag); + // LCOV_EXCL_STOP } int32_t HttpHandoverHandler::GetStatus()