[Libwebsockets] Recovering from partial frame writes

Nick Sonneveld nick at sonneveld.name
Sun May 26 03:12:03 CEST 2013


I was just wondering what the best way was to recover from partial frame writes.

Looking in test-server.c, the LWS_CALLBACK_HTTP_WRITEABLE callback
will gracefully handle when the entire file is not sent.  However,
when sending websockets frames in LWS_CALLBACK_SERVER_WRITEABLE, you
simply fail if you detect that the entire frame was not written.  I'm
not sure that manually fragmenting the message will help as I assume
it's still possible to get partial writes with small frames too?

Would a simple solution be to pass an offset to lws_write() to send
the remaining packet?  Or perhaps a function to prepare the frame
first, then send it via several calls to lws_write?

I guess I don't know enough about the "writability" of a socket. I
always assumed that if a socket was writable it meant you could write
more than 1 byte without blocking, but with no guarantees as to the
maximum number of bytes it would write.  I am happy to be corrected on


More information about the Libwebsockets mailing list