[Libwebsockets] client never connects if lws_service timeout is zero

Denis Osvald denis.osvald at sartura.hr
Fri Oct 7 18:43:40 CEST 2016


On 2016-10-07 18:19, Rob Agar wrote:
> Hi all

Hi,

> 
> I've just come across an odd problem when updating to 2.1.  If I pass
> zero as the timeout to /lws_service/, my client never connects to the
> server, but if I set it to 1ms, it works as it did before when it used 1.7
> 
> I'll try and replicate with a minimal test case & raise an issue if I
> can, but in the mean time has anyone else found this behaviour? Or am I
> forgetting to do something?
> 
> cheers
> 
> Rob 
> 

I think the bug is here in lws-plat-unix.c :

lws_plat_service_tsi( ... )

	timeout_ms = lws_service_adjust_timeout(context, timeout_ms, tsi);
	/*
	 * is there anybody with pending stuff that needs service forcing?
	 */
----->	if (!timeout_ms) {
		/* -1 timeout means just do forced service */
		lws_plat_service_tsi(context, -1, pt->tid);
		/* still somebody left who wants forced service? */
		if (!lws_service_adjust_timeout(context, 1, pt->tid)) {
			/* yes... come back again later */
			lwsl_debug("%s: done again\n", __func__);
		}
		return 0;
	}

	n = poll(pt->fds, pt->fds_count, timeout_ms);


After call to adjust_timeout, timeout_ms can be 0 for 2 reasons:
- we were asked to poll with timeout 0 = non-blocking
- don't poll but only force service old input data (because new timeout
returned by adjust_timeout was 0)

The code probably shouldn't overwrite timeout_ms, but use both old and
new one to make the correct decision.


Andy, feel free to correct me.


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



More information about the Libwebsockets mailing list