Skip to content

Event-driven connection handling #6

Description

@kwsantiago

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:

  1. Set connection state in LWS_CALLBACK_CLIENT_ESTABLISHED
  2. Use lws_service() with appropriate timeout
  3. Remove sleep loops entirely

Benefits

  • Lower latency on connect
  • Reduced CPU usage
  • Cleaner event flow

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    easyQuick winenhancementNew feature or requestp2Medium priority

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions