[Libwebsockets] Return value of libwebsocket_write(): how use?

Daniel Griscom griscom at suitable.com
Tue May 14 22:32:03 CEST 2013


I'm still investigating when libwebsocket_write() might not send all 
of the data I'm trying to send, and how to detect it. (FYI, I'm not 
using any extensions, so I'm avoiding that confusion.)

The doc on the return value says "Return may be -1 for a fatal error 
needing connection close, or a positive number reflecting the amount 
of bytes actually sent.  This can be less than the requested number 
of bytes due to OS memory pressure at any given time."

Tests reveal that the return value is always be a few greater than 
the requested number of characters. For message lengths up to 125 
characters I always see a return value of 4 greater than requested; 
longer messages give me a return value of 8 greater than requested. I 
presume this is the framing characters, with different sizes of 
length fields. (I believe I'd see an even larger difference for 
messages longer than around 64kB, but I won't be hitting that.)

So, this leads to two questions:

1) Do I have the rules right on how the return value is calculated?

2) Would testing the actual values against these rules tell me if a 
message wasn't completely sent?


And finally a suggestion: it seems critical to know whether a _write 
fully or only partially succeeded. If this is a real possibility, 
then it would be great if the return value did a better job of 
indicating when the _write partially succeeded (and partially failed).


Thanks,
Dan

-- 
Daniel T. Griscom             griscom at suitable.com
Suitable Systems              http://www.suitable.com/
1 Centre Street, Suite 204    (781) 665-0053
Wakefield, MA  01880-2400



More information about the Libwebsockets mailing list