[Libwebsockets] Packet size question

Brice Hamon normandviking at gmail.com
Tue May 19 23:53:21 CEST 2020

Hi Andy,

Ok got it. Thank you.

Yes it is withing ws.
So I'll chop the big buffers into MTU size packets and lws_write() them,
first n-1 with the FIN flag, and the last one without.
I'll report.
Thank you

On Tue, May 19, 2020 at 5:33 PM Andy Green <andy at warmcat.com> wrote:

> On 5/19/20 9:52 PM, Brice Hamon wrote:
> > Hi guys,
> >
> > I was wondering about payload size in lws.
> >
> > Is there a maximum size pre-defined, or I can allocate a big buffer and
> > use lws_write() to let lws manage the fragmentation?
> >
> > So far we are hitting around a 273872 chars limit somewhere.
> No, should should definitely chop it up yourself into something
> reasonable.  lws doesn't have any fixed limit but if your connection
> gets choked, space will appear in the tcp window as things are acked, if
> the connection is relatively slow that will manifest itself as the tcp
> stack being willing to send "a bit more" measured in mtu-sized packets.
> Exactly how much it will accept depends on the platform, memory pressure
> and the state of the tcp window, but typically somewhere between 1 and 2
> mtu is a good bet, so chunks of 1.4 .. 2.8KB.
> If you try to send giant buffers it all goes on the heap and it's very
> inefficient in that for every send(), the whole of the giant buffer is
> copied into kernel space each time, even if it ends up the network stack
> only used 2KB of it.
> If it's ws protocol you can mark the writes after the first as not
> having a FIN, so it's a continuation of an existing ws message in its
> own frame.
> If it's eg http body you can just keep sending the next part.
> -Andy
> > Thank you,
> > Brice.
> >
> >
> >
> > _______________________________________________
> > Libwebsockets mailing list
> > Libwebsockets at ml.libwebsockets.org
> > https://libwebsockets.org/mailman/listinfo/libwebsockets
> >
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20200519/e86b6cdb/attachment.htm>

More information about the Libwebsockets mailing list