[Libwebsockets] query for InputBuffer in Callback

Andy Green andy at warmcat.com
Wed May 18 05:42:25 CEST 2016

On 05/18/2016 11:30 AM, techi eth wrote:
> Hi,
> I have query regarding inputbuffer in web socket callback.
> Is that buffer is the same which is initialize during
> lws_callback_function registry while context creation ?
> If it is not the same then once it is received in callback how is
> freeing that buffer.

Different buffers are used for 'in' at the user callback depending on 
the callback.  I assume you're really thinking about LWS_CALLBACK_RECEIVE.

There is indeed a per-service-thread (by default, == per context) temp 
buffer that's used for things that will definitely be finished with 
before we finish the current socket service, that's destroyed when the 
context is.  Any service activity can use that as a scratch buffer.

But for ws connections, there is also a per-wsi buffer allocated to be 
the size of the rx_buffer_size member of the negotiated protocol.  This 
is destroyed when the related wsi closes.

The per-wsi rx buffer is needed for, eg, due to an extension like 
permessage-deflate, the whole rx buffer cannot be consumed before 
returning to the event loop... consider the inflated rx is being passed 
onward via another output socket, and the output socket is full.  So it 
must be able to hold the remaining rx associated with the wsi until next 
service for the wsi.


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

More information about the Libwebsockets mailing list