mirror of
https://gitee.com/openharmony/communication_netstack
synced 2024-11-23 15:00:25 +00:00
fix app crash
Signed-off-by: maosiping <maosiping@huawei.com>
This commit is contained in:
parent
fef86ccba0
commit
432fd6a999
@ -44,6 +44,8 @@ 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);
|
||||
|
@ -282,10 +282,19 @@ bool WebSocketExec::ParseUrl(ConnectContext *context, char *protocol, size_t pro
|
||||
return true;
|
||||
}
|
||||
|
||||
void RunService(UserData *userData)
|
||||
void WebSocketExec::RunService(EventManager *manager)
|
||||
{
|
||||
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");
|
||||
@ -297,6 +306,7 @@ void RunService(UserData *userData)
|
||||
lws_context_destroy(context);
|
||||
userData->SetContext(nullptr);
|
||||
delete userData;
|
||||
manager->SetData(nullptr);
|
||||
NETSTACK_LOGI("websocket run service end");
|
||||
}
|
||||
|
||||
@ -813,7 +823,7 @@ bool WebSocketExec::ExecConnect(ConnectContext *context)
|
||||
delete userData;
|
||||
return false;
|
||||
}
|
||||
std::thread serviceThread(RunService, userData);
|
||||
std::thread serviceThread(RunService, manager);
|
||||
|
||||
#if defined(MAC_PLATFORM) || defined(IOS_PLATFORM)
|
||||
pthread_setname_np(WEBSOCKET_CLIENT_THREAD_RUN);
|
||||
|
@ -21,10 +21,10 @@
|
||||
#include <iosfwd>
|
||||
#include <list>
|
||||
#include <mutex>
|
||||
#include <unordered_set>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <queue>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include <utility>
|
||||
|
||||
#include "event_listener.h"
|
||||
#include "napi/native_api.h"
|
||||
@ -104,12 +104,12 @@ public:
|
||||
bool GetReuseAddr();
|
||||
|
||||
private:
|
||||
void *data_;
|
||||
std::mutex mutexForListenersAndEmitByUv_;
|
||||
std::mutex mutexForEmitAndEmitByUv_;
|
||||
std::mutex dataMutex_;
|
||||
std::mutex dataQueueMutex_;
|
||||
std::list<EventListener> listeners_;
|
||||
void *data_;
|
||||
std::queue<void *> dataQueue_;
|
||||
static EventManagerMagic magic_;
|
||||
static std::mutex mutexForManager_;
|
||||
|
@ -13,12 +13,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
|
||||
#include "event_manager.h"
|
||||
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
#include "netstack_log.h"
|
||||
#include "napi_utils.h"
|
||||
#include "netstack_log.h"
|
||||
|
||||
namespace OHOS::NetStack {
|
||||
static constexpr const int CALLBACK_PARAM_NUM = 1;
|
||||
@ -263,9 +264,7 @@ void EventManager::NotifyRcvThdExit()
|
||||
void EventManager::WaitForRcvThdExit()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(sockRcvThdMtx_);
|
||||
sockRcvThdCon_.wait(lock, [this]() {
|
||||
return sockRcvExit_;
|
||||
});
|
||||
sockRcvThdCon_.wait(lock, [this]() { return sockRcvExit_; });
|
||||
}
|
||||
|
||||
void EventManager::SetReuseAddr(bool reuse)
|
||||
|
Loading…
Reference in New Issue
Block a user