Problem
Current code uses sleep() polling loops to wait for connection state changes:
while (!state->connected && !state->failed) {
lws_service(context, 50);
usleep(10000);
}
This wastes CPU cycles and adds latency.
Solution
Use libwebsockets callback-driven model properly:
- Set connection state in
LWS_CALLBACK_CLIENT_ESTABLISHED
- Use
lws_service() with appropriate timeout
- Remove sleep loops entirely
Benefits
- Lower latency on connect
- Reduced CPU usage
- Cleaner event flow
Problem
Current code uses
sleep()polling loops to wait for connection state changes:This wastes CPU cycles and adds latency.
Solution
Use libwebsockets callback-driven model properly:
LWS_CALLBACK_CLIENT_ESTABLISHEDlws_service()with appropriate timeoutBenefits