From b3dcf42c77efc7df1649e9f727b426d402fe9e2b Mon Sep 17 00:00:00 2001 From: hhchinasoft Date: Thu, 2 Dec 2021 14:38:45 +0800 Subject: [PATCH 1/2] socket code check clean Signed-off-by: hhchinasoft --- .../js/napi/http/include/http_enum_define.h | 1 - frameworks/js/napi/http/src/http_napi.cpp | 6 ++-- frameworks/js/napi/http/src/http_request.cpp | 10 +++---- frameworks/js/napi/http/src/napi_util.cpp | 1 - frameworks/js/napi/socket/src/socket_napi.cpp | 29 +++++++++---------- 5 files changed, 21 insertions(+), 26 deletions(-) diff --git a/frameworks/js/napi/http/include/http_enum_define.h b/frameworks/js/napi/http/include/http_enum_define.h index 802ffd358..e61b2dc19 100644 --- a/frameworks/js/napi/http/include/http_enum_define.h +++ b/frameworks/js/napi/http/include/http_enum_define.h @@ -18,7 +18,6 @@ namespace OHOS { namespace NetManagerStandard { - enum RequestMethod { OPTIONS = 0, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT }; enum ResponseCode { diff --git a/frameworks/js/napi/http/src/http_napi.cpp b/frameworks/js/napi/http/src/http_napi.cpp index 676ed49c0..56e378e6b 100644 --- a/frameworks/js/napi/http/src/http_napi.cpp +++ b/frameworks/js/napi/http/src/http_napi.cpp @@ -21,7 +21,6 @@ namespace OHOS { namespace NetManagerStandard { - static int32_t FindMethodIndex(const std::string &key) { std::vector methodVector = { @@ -250,7 +249,7 @@ napi_value Request(napi_env env, napi_callback_info info) &(asyncContext->work_))); napi_status resultStatus = napi_queue_async_work(env, asyncContext->work_); if (resultStatus == napi_ok) { - NETMGR_LOGD("Queue Async Work Successful"); + NETMGR_LOGI("Queue Async Work Successful"); } return result; } @@ -361,7 +360,6 @@ napi_value On(napi_env env, napi_callback_info info) if (eventType != NONE_EVENT_TYPE) { g_eventListenerList.push_back(listener); result = thisVar; - NETMGR_LOGD("ON Finish = %{public}d", (int32_t)g_eventListenerList.size()); } return thisVar; @@ -575,7 +573,7 @@ napi_value HttpPropertyInit(napi_env env, napi_value exports) DECLARE_NAPI_STATIC_PROPERTY("VERSION", version)}; NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc)); - NETMGR_LOGD("HttpPropertyInit End"); + return exports; } diff --git a/frameworks/js/napi/http/src/http_request.cpp b/frameworks/js/napi/http/src/http_request.cpp index 332981bd3..f5fe44c5a 100644 --- a/frameworks/js/napi/http/src/http_request.cpp +++ b/frameworks/js/napi/http/src/http_request.cpp @@ -94,7 +94,7 @@ void HttpRequest::SetHeader(CURL *curl) void HttpRequest::SetOptionURL(CURL *curl, HttpRequestOptionsContext *asyncContext) { if (curl == nullptr || asyncContext == nullptr) { - NETMGR_LOGE("curl or asyncContext pointer address is empty"); + NETMGR_LOGE("The parameter of curl or asyncContext is nullptr"); return; } std::string url(asyncContext->GetUrl()); @@ -145,7 +145,7 @@ void HttpRequest::SetOptionURL(CURL *curl, HttpRequestOptionsContext *asyncConte void HttpRequest::SetMethod(CURL *curl, HttpRequestOptionsContext *asyncContext) { if (curl == nullptr || asyncContext == nullptr) { - NETMGR_LOGE("SetMethod failed"); + NETMGR_LOGE("The parameter of curl or asyncContext is nullptr"); return; } RequestMethod method = asyncContext->GetRequestMethod(); @@ -162,7 +162,7 @@ void HttpRequest::SetMethod(CURL *curl, HttpRequestOptionsContext *asyncContext) bool HttpRequest::SetOptionForPost(CURL *curl, HttpRequestOptionsContext *asyncContext) { if (curl == nullptr || asyncContext == nullptr) { - NETMGR_LOGE("set curl url option, pointer address in null"); + NETMGR_LOGE("The parameter of curl or asyncContext is nullptr"); return false; } HTTP_CURL_EASY_SET_OPTION(curl, CURLOPT_URL, asyncContext->GetUrl().c_str()); @@ -173,7 +173,7 @@ bool HttpRequest::SetOptionForPost(CURL *curl, HttpRequestOptionsContext *asyncC bool HttpRequest::SetOptionForGet(CURL *curl, HttpRequestOptionsContext *asyncContext) { if (curl == nullptr || asyncContext == nullptr) { - NETMGR_LOGE("set curl url option, pointer address in null"); + NETMGR_LOGE("The parameter of curl or asyncContext is nullptr"); return false; } @@ -220,7 +220,7 @@ bool HttpRequest::GetCurlWriteData(HttpRequestOptionsContext *asyncContext) CURL *curl = curl_easy_init(); if (curl == nullptr) { - NETMGR_LOGE("curl easy init failed"); + NETMGR_LOGE("The parameter of curl is nullptr"); return false; } SetOptionURL(curl, asyncContext); diff --git a/frameworks/js/napi/http/src/napi_util.cpp b/frameworks/js/napi/http/src/napi_util.cpp index f06920058..1ec592534 100644 --- a/frameworks/js/napi/http/src/napi_util.cpp +++ b/frameworks/js/napi/http/src/napi_util.cpp @@ -22,7 +22,6 @@ namespace OHOS { namespace NetManagerStandard { - std::string NapiUtil::ToUtf8(std::u16string str16) { return std::wstring_convert, char16_t> {}.to_bytes(str16); diff --git a/frameworks/js/napi/socket/src/socket_napi.cpp b/frameworks/js/napi/socket/src/socket_napi.cpp index 001b07659..33011416a 100644 --- a/frameworks/js/napi/socket/src/socket_napi.cpp +++ b/frameworks/js/napi/socket/src/socket_napi.cpp @@ -544,7 +544,7 @@ napi_value UdpBind(napi_env env, napi_callback_info info) &(asyncContext->work_))); napi_status resultStatus = napi_queue_async_work(env, asyncContext->work_); if (resultStatus == napi_ok) { - NETMGR_LOGD("Udp bind Async Work Successful"); + NETMGR_LOGI("Udp bind Async Work Successful"); } return result; } @@ -612,7 +612,7 @@ napi_value UdpConnect(napi_env env, napi_callback_info info) &(asyncContext->work_))); napi_status resultStatus = napi_queue_async_work(env, asyncContext->work_); if (resultStatus == napi_ok) { - NETMGR_LOGD("Udp connect Async Work Successful"); + NETMGR_LOGI("Udp connect Async Work Successful"); } return result; } @@ -682,7 +682,7 @@ napi_value UdpSend(napi_env env, napi_callback_info info) &(asyncContext->work_))); napi_status resultStatus = napi_queue_async_work(env, asyncContext->work_); if (resultStatus == napi_ok) { - NETMGR_LOGD("Udp send Async Work Successful"); + NETMGR_LOGI("Udp send Async Work Successful"); } return result; } @@ -749,7 +749,7 @@ napi_value UdpClose(napi_env env, napi_callback_info info) &(asyncContext->work_))); napi_status resultStatus = napi_queue_async_work(env, asyncContext->work_); if (resultStatus == napi_ok) { - NETMGR_LOGD("Udp send Async Work Successful"); + NETMGR_LOGI("Udp send Async Work Successful"); } return result; } @@ -797,7 +797,6 @@ napi_value UdpGetState(napi_env env, napi_callback_info info) napi_valuetype valuetype1; NAPI_CALL(env, napi_typeof(env, parameters[0], &valuetype1)); if (NapiUtil::MatchValueType(env, parameters[0], napi_function)) { - NETMGR_LOGD("MatchValueType is true"); NAPI_CALL(env, napi_create_reference(env, parameters[0], 1, &(asyncContext->callbackRef_))); } } @@ -817,7 +816,7 @@ napi_value UdpGetState(napi_env env, napi_callback_info info) &(asyncContext->work_))); napi_status resultStatus = napi_queue_async_work(env, asyncContext->work_); if (resultStatus == napi_ok) { - NETMGR_LOGD("Udp GetState Async Work Successful"); + NETMGR_LOGI("Udp GetState Async Work Successful"); } return result; @@ -886,7 +885,7 @@ napi_value UdpSetExtraOptions(napi_env env, napi_callback_info info) (void *)asyncContext, &(asyncContext->work_))); napi_status resultStatus = napi_queue_async_work(env, asyncContext->work_); if (resultStatus == napi_ok) { - NETMGR_LOGD("Udp SetExtraOptions Async Work Successful"); + NETMGR_LOGI("Udp SetExtraOptions Async Work Successful"); } return result; } @@ -1160,7 +1159,7 @@ static void NativeTcpConnect(napi_env env, void *data) } if (asyncContext->errorCode_ >= 0) { asyncContext->isConnected = true; - asyncContext->isClose = false; // Once Connect Success ,the close state must false + asyncContext->isClose = false; std::string connect("connect"); EmitTcpEvent(asyncContext->tcpSocket_, "connect", connect); } else { @@ -1603,7 +1602,7 @@ napi_value TcpBind(napi_env env, napi_callback_info info) &(asyncContext->work_))); napi_status resultStatus = napi_queue_async_work(env, asyncContext->work_); if (resultStatus == napi_ok) { - NETMGR_LOGD("Tcp bind Async Work Successful"); + NETMGR_LOGI("Tcp bind Async Work Successful"); } return result; @@ -1657,7 +1656,7 @@ napi_value TcpConnect(napi_env env, napi_callback_info info) &(asyncContext->work_))); napi_status resultStatus = napi_queue_async_work(env, asyncContext->work_); if (resultStatus == napi_ok) { - NETMGR_LOGD("Tcp connect Async Work Successful"); + NETMGR_LOGI("Tcp connect Async Work Successful"); } return result; @@ -1711,7 +1710,7 @@ napi_value TcpSend(napi_env env, napi_callback_info info) &(asyncContext->work_))); napi_status resultStatus = napi_queue_async_work(env, asyncContext->work_); if (resultStatus == napi_ok) { - NETMGR_LOGD("Udp bind Async Work Successful"); + NETMGR_LOGI("Udp bind Async Work Successful"); } return result; @@ -1768,7 +1767,7 @@ napi_value TcpClose(napi_env env, napi_callback_info info) &(asyncContext->work_))); napi_status resultStatus = napi_queue_async_work(env, asyncContext->work_); if (resultStatus == napi_ok) { - NETMGR_LOGD("Udp close Async Work Successful"); + NETMGR_LOGI("Udp close Async Work Successful"); } return result; @@ -1822,7 +1821,7 @@ napi_value TcpGetRemoteAddress(napi_env env, napi_callback_info info) (void *)asyncContext, &(asyncContext->work_))); napi_status resultStatus = napi_queue_async_work(env, asyncContext->work_); if (resultStatus == napi_ok) { - NETMGR_LOGD("GetRemoteAddress Async Work Successful"); + NETMGR_LOGI("GetRemoteAddress Async Work Successful"); } return result; @@ -1876,7 +1875,7 @@ napi_value TcpGetState(napi_env env, napi_callback_info info) &(asyncContext->work_))); napi_status resultStatus = napi_queue_async_work(env, asyncContext->work_); if (resultStatus == napi_ok) { - NETMGR_LOGD("tcpGetState Async Work Successful"); + NETMGR_LOGI("tcpGetState Async Work Successful"); } return result; @@ -1935,7 +1934,7 @@ napi_value TcpSetExtraOptions(napi_env env, napi_callback_info info) (void *)asyncContext, &(asyncContext->work_))); napi_status resultStatus = napi_queue_async_work(env, asyncContext->work_); if (resultStatus == napi_ok) { - NETMGR_LOGD("tcpSetExtraOptions Async Work Successful"); + NETMGR_LOGI("tcpSetExtraOptions Async Work Successful"); } return result; } -- Gitee From 9cf4db9a05a024fa567f3e8b3497897b311cf012 Mon Sep 17 00:00:00 2001 From: hhchinasoft Date: Thu, 2 Dec 2021 15:46:40 +0800 Subject: [PATCH 2/2] socket code check clean Signed-off-by: hhchinasoft --- frameworks/js/napi/socket/src/socket_napi.cpp | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/frameworks/js/napi/socket/src/socket_napi.cpp b/frameworks/js/napi/socket/src/socket_napi.cpp index 33011416a..08b1785c7 100644 --- a/frameworks/js/napi/socket/src/socket_napi.cpp +++ b/frameworks/js/napi/socket/src/socket_napi.cpp @@ -760,8 +760,6 @@ napi_value UdpGetState(napi_env env, napi_callback_info info) napi_value parameters[1] = {0}; napi_value thisVar = nullptr; void *data = nullptr; - uint32_t flag = 0; - bool isFdExist = false; NAPI_CALL(env, napi_get_cb_info(env, info, ¶meterCount, parameters, &thisVar, &data)); @@ -782,17 +780,6 @@ napi_value UdpGetState(napi_env env, napi_callback_info info) return nullptr; } - for (int i = 0; i < g_onInfoList.size(); i++) { - if (objectInfo->remInfo.socketfd == g_onInfoList.at(i).socketfd) { - flag = i; - isFdExist = true; - break; - } - } - if (!isFdExist) { - return nullptr; - } - if (parameterCount == 1) { napi_valuetype valuetype1; NAPI_CALL(env, napi_typeof(env, parameters[0], &valuetype1)); -- Gitee