From fcd4bdb79989a0542d457efddd94f7fd3049db1c Mon Sep 17 00:00:00 2001 From: kmook Date: Thu, 29 Dec 2016 21:39:29 +0900 Subject: [PATCH] Fixed crash issue on destroying websocket and applied exception codes Change-Id: I551f4347ed8ccfa9b2f62bbe3723c6b9dacd6682 Signed-off-by: kmook (cherry picked from commit c690e5e589bae8f34de120252307db154d82bb32) --- msf_tizen_client/src/Application.cpp | 2 +- msf_tizen_client/src/Channel.cpp | 35 +++++++++++++++++++++-------------- msf_tizen_client/src/Clients.cpp | 9 +++++++-- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/msf_tizen_client/src/Application.cpp b/msf_tizen_client/src/Application.cpp index f4521b9..a4f7152 100755 --- a/msf_tizen_client/src/Application.cpp +++ b/msf_tizen_client/src/Application.cpp @@ -185,7 +185,7 @@ void Application::start() { Clients *clientstemp = Channel::getclients(); - if (clientstemp->getHost() == NULL) { + if (!clientstemp || clientstemp->getHost() == NULL) { waitForOnReady = true; } diff --git a/msf_tizen_client/src/Channel.cpp b/msf_tizen_client/src/Channel.cpp index 814fd74..a233859 100755 --- a/msf_tizen_client/src/Channel.cpp +++ b/msf_tizen_client/src/Channel.cpp @@ -880,12 +880,25 @@ int Channel::writeSocket(Channel* ch_p) int Channel::callback_lws_mirror(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len) { - void *user_data; + void *user_data = NULL; Channel *this_ptr = NULL; + if (wsi == NULL) { + MSF_DBG("wsi is NULL"); + return -1; + } struct lws_context *context = lws_get_context(wsi); - user_data = lws_context_user(context); + + if (context != NULL) { + user_data = lws_context_user(context); + } + this_ptr = static_cast(user_data); + if (this_ptr == NULL) { + // it means Channel object was deleted + return -1; + } + if (channel_alive_map.find(this_ptr) != channel_alive_map.end()) { if (channel_alive_map[this_ptr] == 0) { return -1; @@ -909,11 +922,6 @@ int Channel::callback_lws_mirror(struct lws *wsi, break; case LWS_CALLBACK_CLIENT_RECEIVE: - if (this_ptr == NULL) { - // it means Channel object was deleted - return -1; - } - if (lws_frame_is_binary(wsi)) { MSF_DBG("BINARY MESSAGE ARRIVED. len:%d", len); // header needs to be parsed on first chunk @@ -961,6 +969,7 @@ int Channel::callback_lws_mirror(struct lws *wsi, this_ptr->cl_payload_size = 0; this_ptr->is_header_parsed = false; this_ptr->eventType.clear(); + this_ptr->data.clear(); } } } else { @@ -989,6 +998,7 @@ int Channel::callback_lws_mirror(struct lws *wsi, this_ptr->cl_payload_size = 0; this_ptr->is_header_parsed = false; this_ptr->eventType.clear(); + this_ptr->data.clear(); } } } @@ -1025,6 +1035,7 @@ int Channel::callback_lws_mirror(struct lws *wsi, this_ptr->cl_data = NULL; this_ptr->cl_data_size = 0; this_ptr->eventType.clear(); + this_ptr->data.clear(); } } } @@ -1432,10 +1443,9 @@ void Channel::createWebsocket(void *att) { void Channel::writeRequest() { - lws_callback_on_writable(wsi_mirror); - if (pthread_self() != socketThreadId) { - MSF_DBG("current thread is different from websocket thread => lws_cancel_service()"); - lws_cancel_service(lws_get_context(wsi_mirror)); // to exit from poll() inside of lws_service() + MSF_DBG("writeRequest start"); + if (wsi_mirror != NULL) { + lws_callback_on_writable(wsi_mirror); } } @@ -1744,9 +1754,6 @@ void Channel::handleWsiDestroy() { if (!isCommunicated) { closeRequest = true; - if (Context) { - lws_cancel_service(Context); - } MSF_ERR("wsi destroyed with no communication"); if (onErrorListener) { diff --git a/msf_tizen_client/src/Clients.cpp b/msf_tizen_client/src/Clients.cpp index 69b3762..8322294 100755 --- a/msf_tizen_client/src/Clients.cpp +++ b/msf_tizen_client/src/Clients.cpp @@ -30,8 +30,13 @@ Clients::Clients(Channel *channel) Client Clients::get(string clientId) { - Client cl = clients.find(clientId)->second; - return cl; + if (clients.find(clientId) != clients.end()) { + Client cl = clients.find(clientId)->second; + return cl; + } else { + Client empty; + return empty; + } } Client* Clients::getHost() -- 2.7.4