libwebsockets/lib
Andy Green 1f4267bda8 add explicit error for partial send
This patch adds code to handle the situation that a prepared user buffer could not all be sent on the
socket at once.  There are two kinds of situation to handle

1) User code handles it: The connection only has extensions active that do not rewrite the buffer.
In this case, the patch caused libwebsocket_write() to simply return the amount of user buffer that
was consumed (this is specifically the amount of user buffer used in sending what was accepted,
nothing else).  So user code can just advance its buffer that much and resume sending when the socket
is writable again.  This continues the frame rather than starting a new one or new fragment.

2) The connections has extensions active which actually send something quite different than what the
user buffer contains, for example a compression extension.  In this case, libwebsockets will dynamically
malloc a buffer to contain a copy of the remaining unsent data, request notifiction when writeable again,
and automatically spill and free this buffer with the highest priority before passing on the writable
notification to anything else.  For this situation, the call to write will return that it used the
whole user buffer, even though part is still rebuffered.

This patch should enable libwebsockets to detect the two cases and take the appropriate action.

There are also two choices for user code to deal with partial sends.

1) Leave the no_buffer_all_partial_tx member in the protocol struct at zero.  The library will dyamically
buffer anything you send that did not get completely written to the socket, and automatically spill it next
time the socket is writable.  You can use this method if your sent frames are relatvely small and unlikely to get
truncated anyway.

2) Set the no_buffer_all_partial_tx member in the protocol struct.  User code now needs to take care of the
return value from libwebsocket_write() and deal with resending the remainder if not all of the requested amount
got sent.  You should use this method if you are sending large messages and want to maximize throughput and efficiency.

Since the new member no_buffer_all_partial_tx will be zero by default, this patch will auto-rebuffer any
partial sends by default.  That's good for most cases but if you attempt to send large blocks, make sure you
follow option 2) above.

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-10-17 08:09:19 +08:00
..
.gitignore Ignoring linux build files 2013-01-09 15:46:11 +08:00
base64-decode.c remove bae64 decode and selftest 2013-09-18 20:57:59 +08:00
client-handshake.c trac 40 client connection properly nonblocking 2013-09-20 20:26:12 +08:00
client-parser.c reflect send completeness in lws_write return 2013-02-23 10:50:10 +08:00
client.c trac 40 client connection properly nonblocking 2013-09-20 20:26:12 +08:00
daemonize.c Hide private library symbols 2013-03-30 09:52:21 +08:00
extension-deflate-frame.c style cleanup 2013-02-11 17:13:32 +08:00
extension-deflate-frame.h Separate compression levels for server and client, 2013-01-10 12:45:54 +08:00
extension-deflate-stream.c style cleanup 2013-02-11 17:13:32 +08:00
extension-deflate-stream.h remove fixed rx buffer allow definition per protocol 2013-02-08 13:16:07 +08:00
extension.c Hide private library symbols 2013-03-30 09:52:21 +08:00
getifaddrs.c style cleanup 2013-02-11 17:13:32 +08:00
getifaddrs.h style cleanup 2013-02-11 17:13:32 +08:00
handshake.c change LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION user param usage 2013-09-18 08:32:55 +08:00
libwebsockets.c add explicit error for partial send 2013-10-17 08:09:19 +08:00
libwebsockets.h add explicit error for partial send 2013-10-17 08:09:19 +08:00
minilex.c add lexical parser for headers 2013-01-18 01:55:48 +08:00
output.c add explicit error for partial send 2013-10-17 08:09:19 +08:00
parsers.c Hide private library symbols 2013-03-30 09:52:21 +08:00
private-libwebsockets.h add explicit error for partial send 2013-10-17 08:09:19 +08:00
server-handshake.c reflect send completeness in lws_write return 2013-02-23 10:50:10 +08:00
server.c trac 28 - differentiate between http serving and accepted http connection 2013-05-19 14:04:10 +08:00
sha-1.c Declare "sha1_init" statically to avoid naming conflicts if linked statically with other libraries providing a method with the same name (e.g. OpenSSL). 2013-06-23 14:45:15 +08:00