[Libwebsockets] lws_service and lws_cancel_service questions
cooperrf at yahoo.com
Thu May 19 16:14:15 CEST 2016
I built a broker that transfers messages back and forth between ZMQ sockets and web sockets. Everything is working as expected, but I'm not sure I completely understand how lws_service works.
Here is my experience when I set the lws_service timeout relatively high (an hour):- I start a thread that calls lws_service from within a loop.
- lws_service blocks while waiting for something to happen.
- Actions that originate "within" the context (client connects, client sends a message, client disconnects) are processed immediately.
- Actions that originate "outside" the context (a message from ZMQ is sent to the clients) are not processed immediately, they wait for lws_service to stop blocking.
- When lws_service returns, it then processes an action, returns, processes the next action, etc. ...until all the queued actions are processed.
Because of this experience, I set the lws_service timeout relatively low (100ms), so not to introduce too much lag to the user.
By the way, I am calling lws_callback_on_writable for each client I want to send a message to.
I just discovered the lws_cancel_service method (I just switched to libwebsockets 2.0 from 1.6.3...) and it got me thinking:- Can I set the timeout to a high value, but call lws_cancel_service to stop blocking and return from lws_service after calling lws_callback_on_writable?
Actually, I've already answered my question above. Yes, it does work.
But *should* I do it that way?
Does lws_cancel_service cause unprocessed actions to be dropped or does it prevent complete processing of a current action?Is this a reasonable implementation? Or would it be better to go back to a very short timeout?Is there some performance penalty one way or the other?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Libwebsockets