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<Channel *>(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;
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
this_ptr->cl_payload_size = 0;
this_ptr->is_header_parsed = false;
this_ptr->eventType.clear();
+ this_ptr->data.clear();
}
}
} else {
this_ptr->cl_payload_size = 0;
this_ptr->is_header_parsed = false;
this_ptr->eventType.clear();
+ this_ptr->data.clear();
}
}
}
this_ptr->cl_data = NULL;
this_ptr->cl_data_size = 0;
this_ptr->eventType.clear();
+ this_ptr->data.clear();
}
}
}
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);
}
}
{
if (!isCommunicated) {
closeRequest = true;
- if (Context) {
- lws_cancel_service(Context);
- }
MSF_ERR("wsi destroyed with no communication");
if (onErrorListener) {