Timeout issue with the lws_service interface
Calling the function lws_service(context, 50), it is expected to end in 50ms, but in reality, this function waited for 30 seconds before returning. What is the reason for this and how can it be resolved?
struct lws_context_creation_info info; info.timeout_secs = 0;
context = lws_create_context(&info);
lws_service(context, 50)
No that's not "expected" since a few versions ago (v3.2 IIRC).
The event loop will just wait until something to do. If any network events come, it will wake immediately and deal with them. If you need to schedule something, use lws_sul to cause lws to wake and call your sul callback at the right time, and you can have as many of those as you need.
Otherwise, nothing to do -> do nothing at 0% CPU.
The version of libwebsockets that I am using is v4.3.6.
commit e83ed4eb88b77039d69189327482263f6fdf5fef (HEAD, tag: v4.3.6, origin/v4.3-stable) Author: Jeongik Cha [email protected] Date: Fri Jul 18 12:33:30 2025 +0900
cmake ..
-DCMAKE_TOOLCHAIN_FILE=$ANDRIOD_NDK/build/cmake/android.toolchain.cmake
-DANDROID_ABI=arm64-v8a
-DANDROID_NATIVE_API_LEVEL=21
-DLWS_WITH_SSL=ON
-DLWS_WITH_MBEDTLS=ON
-DMBEDTLS_INCLUDE_DIRS=$MBEDTLS_ROOT/include
-DMBEDTLS_LIBRARY=$MBEDTLS_ROOT/library/libmbedtls.a
-DMBEDX509_LIBRARY=$MBEDTLS_ROOT/library/libmbedx509.a
-DMBEDCRYPTO_LIBRARY=$MBEDTLS_ROOT/library/libmbedcrypto.a
-DLWS_WITH_SHARED=ON
Sure, the behaviour you are seeing has been the same since v3.2.
See https://github.com/warmcat/libwebsockets/blob/main/READMEs/README.lws_sul.md for more info. Make sure you call lws_sul_cancel() on any suls in a memory area before you destroy it.
Thank you very much.
x86 linux: normal
arm64 Android: abnormal issue is that when calling lws_sul_schedule, sometimes a callback can be triggered immediately after the operation, sometimes a coredump occurs, and sometimes the callback is generated only 30 seconds later. (there is only one WebSocket thread and one WebSocket context).
thread1 { context = lws_create_context(&info); while(1) { lws_service(context, 50); } }
static void connect_client_callback(struct lws_sorted_usec_list *sul) { }
thread2 { memset(&g_sul, 0, sizeof(struct lws_sorted_usec_list)); lws_sul_schedule(context, 0, &g_sul, connect_client_callback, 0); }
Could you provide me with a dynamic library of libwebsockets for Android (ARM64) for me to test?