[Libwebsockets] lws_rx_flow_control problem

Andy Green andy at warmcat.com
Tue Oct 10 01:40:41 CEST 2017

On 10/10/2017 07:23 AM, Per Bothner wrote:
> For the sake of discussion, DomTerm uses two kinds of wsi/protocols:
> - a "pty" wsi wraps the pty of a child process (session).
> It is created using lws_adopt_descriptor_vhost.
> - a "tty" wsi [awkward name, historical reasons] manages a websocket
> between the server and a browser.
> Note the "pty" wsi cannot be the "child" of a "tty" wsi, because
> a process may be detached, and so have no connected browser windows.
> There may also be multiple "tty" connections for a given "pty" if
> there are multiple browser windows displaying the same session.
> I'd like to be able to use use flow control to suspend a "pty" when there
> is no ""tty" ready for more output.  Specifically, to stop polling for
> output from the session.  The problem is: how do I reenable output when
> a browser session is created or can handle more data?  I can call
>                lws_rx_flow_control(pty_wsi, 1);
> However, that has no immediate effect - all it does it set
>      rxflow_change_to = LWS_RXFLOW_PENDING_CHANGE|1;

Yes there is a callback helper inside lws, 
user_callback_handle_rxflow(), that handles anything that happened 
during the callback for rx flow state change after the callback has 

> The actual update to the pollfd is done by _lws_rx_flow_control.
> However, that is never called for the pty wsi - since polling
> is suspended and there are no events.  _lws_rx_flow_control
> is called for the "tty" wsi - and that will un-suspend its
> children - but that doesn't help, since the pty wsi is not a child
> and cannot be.

Managing flow control on a wsi from outside a callback on the wsi isn't 
really supported atm... whether it's a child or not doesn't make any 

In the http2 megapatch rx flow control accepts flags now and you can 
individually toggle up to 8 reasons for flow control on the wsi, if any 
reason is active it is suppressed.  It's completely backwards-compatible 
with just giving it 0 or 1 as before.  How about a flag you can give in 
the arg indicating that lws needs to do the _lws_rx_flow_control() in 
the call for that one?


More information about the Libwebsockets mailing list