mirror of
https://gitee.com/openharmony/request_request
synced 2024-11-27 09:01:05 +00:00
修复下载压测crash问题
Signed-off-by: anyueling <anyueling@huawei.com>
This commit is contained in:
parent
364f9544f7
commit
7506c0d989
@ -26,62 +26,67 @@ config("upload_public_config") {
|
||||
]
|
||||
}
|
||||
|
||||
ohos_shared_library("request") {
|
||||
include_dirs = [
|
||||
"${arkui_path}/ace_engine/frameworks/base/utils",
|
||||
"${ability_runtime_napi_path}/featureAbility",
|
||||
"${ability_runtime_napi_path}/inner/napi_common",
|
||||
"${request_path}/frameworks/native/download/include",
|
||||
"${request_path}/frameworks/native/upload/include",
|
||||
"//third_party/libuv/include",
|
||||
]
|
||||
request_src = [
|
||||
"src/download/async_call.cpp",
|
||||
"src/download_base_notify.cpp",
|
||||
"src/download_event.cpp",
|
||||
"src/download_pause.cpp",
|
||||
"src/download_query.cpp",
|
||||
"src/download_query_mimetype.cpp",
|
||||
"src/download_remove.cpp",
|
||||
"src/download_resume.cpp",
|
||||
"src/download_task_napi.cpp",
|
||||
"src/download_task_napi_V9.cpp",
|
||||
"src/header_receive_callback.cpp",
|
||||
"src/js_util.cpp",
|
||||
"src/legacy/download_manager.cpp",
|
||||
"src/legacy/download_task.cpp",
|
||||
"src/napi_utils.cpp",
|
||||
"src/notify_callback.cpp",
|
||||
"src/progress_callback.cpp",
|
||||
"src/request_module.cpp",
|
||||
"src/upload/async_call.cpp",
|
||||
"src/upload_task_napi.cpp",
|
||||
"src/upload_task_napiV5.cpp",
|
||||
"src/upload_task_napiV9.cpp",
|
||||
"src/uv_queue.cpp",
|
||||
]
|
||||
|
||||
request_include = [
|
||||
"${arkui_path}/ace_engine/frameworks/base/utils",
|
||||
"${ability_runtime_napi_path}/featureAbility",
|
||||
"${ability_runtime_napi_path}/inner/napi_common",
|
||||
"${request_path}/frameworks/native/download/include",
|
||||
"${request_path}/frameworks/native/upload/include",
|
||||
"//third_party/libuv/include",
|
||||
]
|
||||
|
||||
request_deps = [
|
||||
"${request_path}/common:request_common_static",
|
||||
"${request_path}/frameworks/native/download:downloadsingle",
|
||||
"//third_party/libuv:uv",
|
||||
]
|
||||
|
||||
request_external_deps = [
|
||||
"ability_base:zuri",
|
||||
"ability_runtime:abilitykit_native",
|
||||
"ability_runtime:data_ability_helper",
|
||||
"ability_runtime:napi_base_context",
|
||||
"c_utils:utils",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_single",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
|
||||
ohos_shared_library("request") {
|
||||
include_dirs = request_include
|
||||
configs = [ "//build/config/gcc:symbol_visibility_hidden" ]
|
||||
public_configs = [ ":upload_public_config" ]
|
||||
sources = request_src
|
||||
|
||||
sources = [
|
||||
"src/download/async_call.cpp",
|
||||
"src/download_base_notify.cpp",
|
||||
"src/download_event.cpp",
|
||||
"src/download_pause.cpp",
|
||||
"src/download_query.cpp",
|
||||
"src/download_query_mimetype.cpp",
|
||||
"src/download_remove.cpp",
|
||||
"src/download_resume.cpp",
|
||||
"src/download_task_napi.cpp",
|
||||
"src/download_task_napi_V9.cpp",
|
||||
"src/header_receive_callback.cpp",
|
||||
"src/js_util.cpp",
|
||||
"src/legacy/download_manager.cpp",
|
||||
"src/legacy/download_task.cpp",
|
||||
"src/napi_utils.cpp",
|
||||
"src/notify_callback.cpp",
|
||||
"src/progress_callback.cpp",
|
||||
"src/request_module.cpp",
|
||||
"src/upload/async_call.cpp",
|
||||
"src/upload_task_napi.cpp",
|
||||
"src/upload_task_napiV5.cpp",
|
||||
"src/upload_task_napiV9.cpp",
|
||||
"src/uv_queue.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"${request_path}/common:request_common_static",
|
||||
"${request_path}/frameworks/native/download:downloadsingle",
|
||||
"${request_path}/frameworks/native/upload:upload_lib",
|
||||
"//third_party/libuv:uv",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:zuri",
|
||||
"ability_runtime:abilitykit_native",
|
||||
"ability_runtime:data_ability_helper",
|
||||
"ability_runtime:napi_base_context",
|
||||
"c_utils:utils",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_single",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
deps = request_deps
|
||||
deps += [ "${request_path}/frameworks/native/upload:upload_lib" ]
|
||||
external_deps = request_external_deps
|
||||
|
||||
relative_install_dir = "module"
|
||||
subsystem_name = "request"
|
||||
@ -89,60 +94,13 @@ ohos_shared_library("request") {
|
||||
}
|
||||
|
||||
ohos_static_library("request_static") {
|
||||
include_dirs = [
|
||||
"${arkui_path}/ace_engine/frameworks/base/utils",
|
||||
"${ability_runtime_napi_path}/featureAbility",
|
||||
"${ability_runtime_napi_path}/inner/napi_common",
|
||||
"${request_path}/frameworks/native/download/include",
|
||||
"${request_path}/frameworks/native/upload/include",
|
||||
"//third_party/libuv/include",
|
||||
"./inlcude",
|
||||
]
|
||||
|
||||
include_dirs = request_include
|
||||
configs = [ "//build/config/gcc:symbol_visibility_hidden" ]
|
||||
public_configs = [ ":upload_public_config" ]
|
||||
sources = request_src
|
||||
|
||||
sources = [
|
||||
"src/download/async_call.cpp",
|
||||
"src/download_base_notify.cpp",
|
||||
"src/download_event.cpp",
|
||||
"src/download_pause.cpp",
|
||||
"src/download_query.cpp",
|
||||
"src/download_query_mimetype.cpp",
|
||||
"src/download_remove.cpp",
|
||||
"src/download_resume.cpp",
|
||||
"src/download_task_napi.cpp",
|
||||
"src/download_task_napi_V9.cpp",
|
||||
"src/header_receive_callback.cpp",
|
||||
"src/js_util.cpp",
|
||||
"src/legacy/download_manager.cpp",
|
||||
"src/legacy/download_task.cpp",
|
||||
"src/napi_utils.cpp",
|
||||
"src/notify_callback.cpp",
|
||||
"src/progress_callback.cpp",
|
||||
"src/request_module.cpp",
|
||||
"src/upload/async_call.cpp",
|
||||
"src/upload_task_napi.cpp",
|
||||
"src/upload_task_napiV9.cpp",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"${request_path}/common:request_common_static",
|
||||
"${request_path}/frameworks/native/download:downloadsingle",
|
||||
"${request_path}/frameworks/native/upload:upload_lib",
|
||||
"//third_party/libuv:uv",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:zuri",
|
||||
"ability_runtime:abilitykit_native",
|
||||
"ability_runtime:data_ability_helper",
|
||||
"ability_runtime:napi_base_context",
|
||||
"c_utils:utils",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_single",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
deps = request_deps
|
||||
external_deps = request_external_deps
|
||||
|
||||
subsystem_name = "request"
|
||||
part_name = "request"
|
||||
|
@ -19,6 +19,8 @@
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
#include "visibility.h"
|
||||
#include <uv.h>
|
||||
#include "uv_queue.h"
|
||||
#include "download/async_call.h"
|
||||
#include "download_notify_stub.h"
|
||||
#include "download_task.h"
|
||||
@ -33,11 +35,10 @@ struct NotifyData {
|
||||
uint32_t paramNumber;
|
||||
std::mutex mutex;
|
||||
std::vector<int64_t> params;
|
||||
};
|
||||
|
||||
struct CallbackData {
|
||||
napi_env env_;
|
||||
napi_ref ref_;
|
||||
~NotifyData()
|
||||
{
|
||||
UvQueue::DeleteRef(env, ref);
|
||||
}
|
||||
};
|
||||
|
||||
struct NotifyDataPtr {
|
||||
|
@ -19,10 +19,16 @@
|
||||
#include "napi/native_api.h"
|
||||
#include "uv.h"
|
||||
|
||||
namespace OHOS::Request::UploadNapi {
|
||||
namespace OHOS::Request {
|
||||
struct CallbackData {
|
||||
napi_env env;
|
||||
napi_ref ref;
|
||||
};
|
||||
class UvQueue {
|
||||
public:
|
||||
static bool Call(napi_env env, void *data, uv_after_work_cb afterCallback);
|
||||
static void DeleteRef(napi_env env, napi_ref ref);
|
||||
static void UvDelete(uv_work_t *work, int status);
|
||||
};
|
||||
} // namespace OHOS::Request::UploadNapi
|
||||
} // namespace OHOS::Request
|
||||
#endif // UV_QUEUE_H
|
||||
|
@ -14,10 +14,8 @@
|
||||
*/
|
||||
|
||||
#include "download_base_notify.h"
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
#include "log.h"
|
||||
#include "uv_queue.h"
|
||||
#include "napi_utils.h"
|
||||
|
||||
namespace OHOS::Request::Download {
|
||||
@ -31,92 +29,43 @@ DownloadBaseNotify::DownloadBaseNotify(napi_env env, uint32_t paramNumber, napi_
|
||||
|
||||
DownloadBaseNotify::~DownloadBaseNotify()
|
||||
{
|
||||
DOWNLOAD_HILOGI("~DownloadBaseNotify()");
|
||||
if (notifyData_ != nullptr) {
|
||||
uv_loop_s *loop = nullptr;
|
||||
napi_get_uv_event_loop(notifyData_->env, &loop);
|
||||
if (loop == nullptr) {
|
||||
DOWNLOAD_HILOGE("Failed to get uv event loop");
|
||||
return;
|
||||
}
|
||||
uv_work_t *work = new (std::nothrow) uv_work_t;
|
||||
if (work == nullptr) {
|
||||
DOWNLOAD_HILOGE("Failed to create uv work");
|
||||
return;
|
||||
}
|
||||
CallbackData *callbackData = new (std::nothrow) CallbackData;
|
||||
if (callbackData == nullptr) {
|
||||
delete work;
|
||||
return;
|
||||
}
|
||||
callbackData->env_ = notifyData_->env;
|
||||
callbackData->ref_ = notifyData_->ref;
|
||||
work->data = reinterpret_cast<void *>(callbackData);
|
||||
int ret = uv_queue_work(
|
||||
loop, work, [](uv_work_t *work) {},
|
||||
[](uv_work_t *work, int statusInt) {
|
||||
CallbackData *callbackDataPtr = reinterpret_cast<CallbackData *>(work->data);
|
||||
if (callbackDataPtr != nullptr) {
|
||||
napi_delete_reference(callbackDataPtr->env_, callbackDataPtr->ref_);
|
||||
delete callbackDataPtr;
|
||||
delete work;
|
||||
}
|
||||
});
|
||||
if (ret != 0) {
|
||||
delete callbackData;
|
||||
delete work;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DownloadBaseNotify::CallBack(const std::vector<int64_t> ¶ms)
|
||||
{
|
||||
DOWNLOAD_HILOGD("Pause callback in");
|
||||
uv_loop_s *loop = nullptr;
|
||||
napi_get_uv_event_loop(notifyData_->env, &loop);
|
||||
if (loop == nullptr) {
|
||||
DOWNLOAD_HILOGE("Failed to get uv event loop");
|
||||
return;
|
||||
}
|
||||
uv_work_t *work = new (std::nothrow) uv_work_t;
|
||||
if (work == nullptr) {
|
||||
DOWNLOAD_HILOGE("Failed to create uv work");
|
||||
return;
|
||||
}
|
||||
NotifyDataPtr *notifyDataPtr = GetNotifyDataPtr();
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(notifyData_->mutex);
|
||||
notifyData_->params = params;
|
||||
}
|
||||
notifyDataPtr->notifyData = notifyData_;
|
||||
work->data = notifyDataPtr;
|
||||
uv_queue_work(
|
||||
loop, work, [](uv_work_t *work) {},
|
||||
[](uv_work_t *work, int statusInt) {
|
||||
NotifyDataPtr *notifyDataPtr = static_cast<NotifyDataPtr *>(work->data);
|
||||
if (notifyDataPtr != nullptr) {
|
||||
napi_handle_scope scope = nullptr;
|
||||
napi_open_handle_scope(notifyDataPtr->notifyData->env, &scope);
|
||||
napi_value undefined = 0;
|
||||
napi_get_undefined(notifyDataPtr->notifyData->env, &undefined);
|
||||
napi_value callbackFunc = nullptr;
|
||||
napi_get_reference_value(notifyDataPtr->notifyData->env, notifyDataPtr->notifyData->ref, &callbackFunc);
|
||||
napi_value callbackResult = nullptr;
|
||||
napi_value callbackValues[Download::TWO_PARAMETER] = { 0 };
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(notifyDataPtr->notifyData->mutex);
|
||||
for (uint32_t i = 0; i < notifyDataPtr->notifyData->paramNumber; i++) {
|
||||
napi_create_int64(notifyDataPtr->notifyData->env, notifyDataPtr->notifyData->params[i],
|
||||
&callbackValues[i]);
|
||||
}
|
||||
uv_after_work_cb afterCallback = [](uv_work_t *work, int status) {
|
||||
NotifyDataPtr *notifyDataPtr = static_cast<NotifyDataPtr *>(work->data);
|
||||
if (notifyDataPtr != nullptr && notifyDataPtr->notifyData != nullptr) {
|
||||
napi_handle_scope scope = nullptr;
|
||||
napi_open_handle_scope(notifyDataPtr->notifyData->env, &scope);
|
||||
napi_value undefined = 0;
|
||||
napi_get_undefined(notifyDataPtr->notifyData->env, &undefined);
|
||||
napi_value callbackFunc = nullptr;
|
||||
napi_get_reference_value(notifyDataPtr->notifyData->env, notifyDataPtr->notifyData->ref, &callbackFunc);
|
||||
napi_value callbackResult = nullptr;
|
||||
napi_value callbackValues[Download::TWO_PARAMETER] = { 0 };
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(notifyDataPtr->notifyData->mutex);
|
||||
for (uint32_t i = 0; i < notifyDataPtr->notifyData->paramNumber; i++) {
|
||||
napi_create_int64(notifyDataPtr->notifyData->env, notifyDataPtr->notifyData->params[i],
|
||||
&callbackValues[i]);
|
||||
}
|
||||
napi_call_function(notifyDataPtr->notifyData->env, nullptr, callbackFunc,
|
||||
notifyDataPtr->notifyData->paramNumber, callbackValues, &callbackResult);
|
||||
napi_close_handle_scope(notifyDataPtr->notifyData->env, scope);
|
||||
delete notifyDataPtr;
|
||||
delete work;
|
||||
}
|
||||
});
|
||||
napi_call_function(notifyDataPtr->notifyData->env, nullptr, callbackFunc,
|
||||
notifyDataPtr->notifyData->paramNumber, callbackValues, &callbackResult);
|
||||
napi_close_handle_scope(notifyDataPtr->notifyData->env, scope);
|
||||
delete notifyDataPtr;
|
||||
delete work;
|
||||
}
|
||||
};
|
||||
UvQueue::Call(notifyData_->env, reinterpret_cast<void *>(notifyDataPtr), afterCallback);
|
||||
}
|
||||
|
||||
NotifyDataPtr *DownloadBaseNotify::GetNotifyDataPtr()
|
||||
|
@ -14,7 +14,7 @@
|
||||
*/
|
||||
#include "uv_queue.h"
|
||||
|
||||
namespace OHOS::Request::UploadNapi {
|
||||
namespace OHOS::Request {
|
||||
bool UvQueue::Call(napi_env env, void *data, uv_after_work_cb afterCallback)
|
||||
{
|
||||
uv_loop_s *loop = nullptr;
|
||||
@ -31,4 +31,25 @@ bool UvQueue::Call(napi_env env, void *data, uv_after_work_cb afterCallback)
|
||||
loop, work, [](uv_work_t *work) {}, afterCallback);
|
||||
return true;
|
||||
}
|
||||
} // namespace OHOS::Request::UploadNapi
|
||||
|
||||
void UvQueue::DeleteRef(napi_env env, napi_ref ref)
|
||||
{
|
||||
CallbackData *callbackData = new (std::nothrow) CallbackData();
|
||||
if (callbackData == nullptr) {
|
||||
return;
|
||||
}
|
||||
callbackData->env = env;
|
||||
callbackData->ref = ref;
|
||||
UvQueue::Call(env, reinterpret_cast<void *>(callbackData), UvDelete);
|
||||
}
|
||||
|
||||
void UvQueue::UvDelete(uv_work_t *work, int status)
|
||||
{
|
||||
CallbackData *callbackData = reinterpret_cast<CallbackData *>(work->data);
|
||||
if (callbackData != nullptr) {
|
||||
napi_delete_reference(callbackData->env, callbackData->ref);
|
||||
delete callbackData;
|
||||
delete work;
|
||||
}
|
||||
}
|
||||
} // namespace OHOS::Request
|
@ -612,6 +612,6 @@ bool DownloadServiceManager::IsSameBundleName(const std::string &sName, const st
|
||||
|
||||
bool DownloadServiceManager::IsSameUid(int32_t sUid, int32_t dUid)
|
||||
{
|
||||
return sUid = dUid;
|
||||
return sUid == dUid;
|
||||
}
|
||||
} // namespace OHOS::Request::Download
|
@ -17,7 +17,6 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include "download_base_notify.h"
|
||||
#include "message_parcel.h"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user