[Libwebsockets] Clarification about libwebsocket_service and timeouts

"Andy Green (林安廸)" andy at warmcat.com
Sat Feb 2 16:05:12 CET 2013


On 02/02/13 22:12, the mail apparently from Drew Noakes included:
> On test-server.c line 617 a comment suggests that libwebsocket_service
> returns immediately if no sockets require servicing, despite a timeout
> of 50ms being supplied. This seems to disagree with the API documentation.

Yeah the comment is misleading.  It does a poll() either way.

http://git.libwebsockets.org/cgi-bin/cgit/libwebsockets/commit/?id=0d49c8d1a040055b180ccea518b93a6b2e8914df

> Also, in the case of using a timeout and there being work to service,
> will the function return in less time than the timeout specifies? This
> isn't clear to me from the documentation.

Yes immediately something came up, poll() will return immediately.  If 
nothing came up, it will return after 50ms anyway.

You need to use gettimeofday() as is done earlier in that loop, along 
with a smaller poll() timeout than your interval if you want to perform 
timed operations (and again as done in that loop, you need to do it by 
provoking a callback and doing the send when it comes).

-Andy

> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> http://ml.libwebsockets.org/mailman/listinfo/libwebsockets
>




More information about the Libwebsockets mailing list