[Libwebsockets] how is partial write handled

"Andy Green (林安廸)" andy at warmcat.com
Thu Oct 17 01:32:23 CEST 2013

On 17/10/13 04:53, the mail apparently from LANGLOIS Olivier PIS -EXT
> Hi,
> I'm evaluating libwebsockets or Boost::WebSocket++ for developping. I
> am not a big fan of ASIO because I like being able to understand what
> the framework is doing under the hood and with its convoluted use of
> OO design and heavy template use, I just find doing that plain hard.

Personally I liked C++ for a couple of years and then realized all my 
code was descending into an impenetrable thicket.

> However, there is one small detail that stops me adopting
> libwebsockets:
> I have just looked the code of lwsl_write() and partial writes appear
> to not be supported at all.

Yes that's right.

> With non blocking i/o, partial writes are inevitable for numerous
> reasons. Maybe a server will try to send few MBs one shot or the
> socket send buffer get full temporarily because some clients are slow
> to send back ACKs or it could be some other reasons.

Normally that would be correct.

But for lws I don't believe that's the case.  We use SO_SNDBUF to 
reserve an amount of buffer space on the socket set by the protocol 
struct definition.  Although it's not well documented what the effect of 
SO_SNDBUF is I understand this to mean we won't get signalled by poll() 
the socket is writeable until that amount of packet data is writeable in 
one hit.  I have been unable to reproduce partial sends since adding this.

For websocket messages that are larger than the maximum buffer 
reservation the kernel would accept, you must use websocket fragments. 
But at some point with multi-MB messages you have to use websocket 
fragments anyway.

> I'm currently using 1.22. Is the situation better in the git head
> version?
> If not, is this enhancement in the short-term roadmap?

If you can demonstrate the truncated send issue exists under the 
conditions above I will add support for dealing with it.


> ________________________________ CONFIDENTIALITY : This e-mail and
> any attachments are confidential and may be privileged. If you are
> not a named recipient, please notify the sender immediately and do
> not disclose the contents to another person, use it for any purpose
> or store or copy the information in any medium.
> _______________________________________________ Libwebsockets mailing
> list Libwebsockets at ml.libwebsockets.org
> http://ml.libwebsockets.org/mailman/listinfo/libwebsockets

More information about the Libwebsockets mailing list