[Libwebsockets] minimal-ws-client with foreign libevent loop

Andy Green andy at warmcat.com
Tue Feb 9 20:25:22 CET 2021



On 2/9/21 6:35 PM, John Dunn wrote:
> I am trying to modify the minimal-ws-client example code to use an externally supplied libevent event loop. I am basing my changes off of the minimal-http-server-eventlib-foreign sample. This is on Windows 10 using VS 2015 if that matters. Here's what I've done

The problem is that your loop doesn't exist before the context is 
created... during the context creation it's making callbacks and 
starting to do things, but there is no loop to attach things to, and 
he's dead in the water.

Afterwards you create the context you create the libevent loop, but 
there is nothing that can have hooked into it, it did not exist until 
too late.

If you create the libevent loop first - which is not something you come 
back from - and move the lws context creation to happen at the libevent 
timer callback inside the libevent context, everything will start 
working without any further changes.

BTW the interval for lws_sul is in us, not seconds.  You can use 
LWS_US_PER_SEC to get one second.

-Andy


More information about the Libwebsockets mailing list