!1514 fix web crash

Merge pull request !1514 from maosiping/master
This commit is contained in:
openharmony_ci 2024-08-31 05:39:33 +00:00 committed by Gitee
commit 2885cda4c6
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 2 additions and 14 deletions

View File

@ -44,8 +44,6 @@ private:
static bool ParseUrl(ConnectContext *context, char *prefix, size_t prefixLen, char *address, size_t addressLen,
char *path, size_t pathLen, int *port);
static void RunService(EventManager *manager);
static int RaiseError(EventManager *manager, uint32_t httpResponse);
static int HttpDummy(lws *wsi, lws_callback_reasons reason, void *user, void *in, size_t len);

View File

@ -282,19 +282,10 @@ bool WebSocketExec::ParseUrl(ConnectContext *context, char *protocol, size_t pro
return true;
}
void WebSocketExec::RunService(EventManager *manager)
void RunService(UserData *userData)
{
NETSTACK_LOGI("websocket run service start");
int res = 0;
if (!EventManager::IsManagerValid(manager)) {
NETSTACK_LOGE("manager is invalid");
return;
}
if (manager == nullptr || manager->GetData() == nullptr) {
NETSTACK_LOGE("RunService para error");
return;
}
auto userData = reinterpret_cast<UserData *>(manager->GetData());
lws_context *context = userData->GetContext();
if (context == nullptr) {
NETSTACK_LOGE("context is null");
@ -306,7 +297,6 @@ void WebSocketExec::RunService(EventManager *manager)
lws_context_destroy(context);
userData->SetContext(nullptr);
delete userData;
manager->SetData(nullptr);
NETSTACK_LOGI("websocket run service end");
}
@ -823,7 +813,7 @@ bool WebSocketExec::ExecConnect(ConnectContext *context)
delete userData;
return false;
}
std::thread serviceThread(RunService, manager);
std::thread serviceThread(RunService, userData);
#if defined(MAC_PLATFORM) || defined(IOS_PLATFORM)
pthread_setname_np(WEBSOCKET_CLIENT_THREAD_RUN);