diff --git a/lib/lws-plat-unix.c b/lib/lws-plat-unix.c index c972a365..23c11b09 100644 --- a/lib/lws-plat-unix.c +++ b/lib/lws-plat-unix.c @@ -112,8 +112,16 @@ lws_plat_service(struct lws_context *context, int timeout_ms) lws_libev_run(context); - context->service_tid = context->protocols[0].callback(NULL, - LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0); + if (!context->service_tid_detected) { + struct lws _lws; + + memset(&_lws, 0, sizeof(_lws)); + _lws.context = context; + + context->service_tid_detected = context->protocols[0].callback( + &_lws, LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0); + } + context->service_tid = context->service_tid_detected; #ifdef LWS_OPENSSL_SUPPORT /* if we know we have non-network pending data, do not wait in poll */ diff --git a/lib/lws-plat-win.c b/lib/lws-plat-win.c index ccbe47a5..eac500b2 100644 --- a/lib/lws-plat-win.c +++ b/lib/lws-plat-win.c @@ -149,8 +149,16 @@ lws_plat_service(struct lws_context *context, int timeout_ms) if (context == NULL) return 1; - context->service_tid = context->protocols[0].callback(NULL, - LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0); + if (!context->service_tid_detected) { + struct lws _lws; + + memset(&_lws, 0, sizeof(_lws)); + _lws.context = context; + + context->service_tid_detected = context->protocols[0].callback( + &_lws, LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0); + } + context->service_tid = context->service_tid_detected; for (i = 0; i < context->fds_count; ++i) { pfd = &context->fds[i]; diff --git a/lib/pollfd.c b/lib/pollfd.c index 46417c8c..319abbd5 100644 --- a/lib/pollfd.c +++ b/lib/pollfd.c @@ -174,7 +174,7 @@ lws_change_pollfd(struct lws *wsi, int _and, int _or) sampled_tid = context->service_tid; if (sampled_tid) { - tid = context->protocols[0].callback(NULL, + tid = context->protocols[0].callback(wsi, LWS_CALLBACK_GET_THREAD_ID, NULL, NULL, 0); if (tid == -1) return -1; diff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h index 62a3646d..731deb23 100644 --- a/lib/private-libwebsockets.h +++ b/lib/private-libwebsockets.h @@ -502,6 +502,7 @@ struct lws_context { * for pollfd event change. */ volatile int service_tid; + int service_tid_detected; #ifndef _WIN32 int dummy_pipe_fds[2]; #endif