[Libwebsockets] lws_service_adjust_timeout & lws_service_flag_pending

Andy Green andy at warmcat.com
Mon Mar 15 13:02:21 CET 2021

On 3/15/21 11:19 AM, Bram Peeters wrote:
> Hi,
> TLDR: In cases where lws_service_adjust_timeout returns 0, should 
> lws_service_flag_pending always return a nonzero value (set forced = 1)?
> I get a zero from lws_service_adjust_timeout  because of 
> __lws_sul_service_ripe returning a time < 1000 us 

Getting a zero from lws_service_adjust_timeout() is valid, it's saying 
the next scheduled thing either in the past, or happening inside the 
underlying resolution of the wait, either way we don't have any time to 
spend in the wait.

> And in  lws_service_flag_pending none  of the 2 tested conditions are 
> triggered by the __lws_sul_service_ripe condition so forced stays 0.

lws_service_flag_pending() is a different kind of animal unrelated to 
scheduler situation, it's OK if he doesn't feel he should get involved.

> Under those conditions, it seems in freertos-service.c , function 
> *_lws_plat_service_tsi* will use an n that is either the initialization 
> value -1 or the current free heap  value (if the timeout for checking 
> that expired) to determine whether to exit with an error (if errno is 
> not EINTR ,  eg errno=0 in my case) or check up to ‘current free heap 
>   value’ nb of fd’s for servicing.

uh... what version are you looking at?  On main I don't see it using 'n' 
for anything like that.

> Since that does not seem to be correct, I take it this means it is 
> unexpected lws_service_flag_pending returns 0 and something is going 
> wrong there (is it always the same condition that should trigger for the 
> __lws_sul_service_ripe case ?)?
> Or is the explanation completely different ?

Maybe I am just having a rough day but I don't see what you describe in 
the code.


Also, I would not use EXTERNAL_POLL if I could at all avoid it.


More information about the Libwebsockets mailing list