canonical libwebsockets.org websocket library
Find a file
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
cmake cmake added RPM generation 2013-04-11 08:38:22 +08:00
lib add explicit error for partial send 2013-10-17 08:09:19 +08:00
scripts add CMake find function for libwebsockets 2013-06-29 10:18:52 +08:00
test-server trac 40 client connection properly nonblocking 2013-09-20 20:26:12 +08:00
win32port fix win32helpers gettimeofday epoch 2013-03-05 08:41:47 +08:00
.gitignore add static stack analysis 2013-02-10 10:49:15 +08:00
Android.mk android include gregorys example makefile 2013-03-10 07:34:53 +08:00
changelog trac 40 client connection properly nonblocking 2013-09-20 20:26:12 +08:00
CMakeLists.txt cmake fix for osx 64 bit 2013-09-18 09:00:52 +08:00
config.h.cmake Set the _DEBUG macro for CMake also. 2013-02-22 09:28:13 +08:00
cross-arm-linux-gnueabihf.cmake cmake improve cross documentation 2013-03-30 10:30:03 +08:00
libwebsockets-api-doc.html introduce api for unthrottle all connections of protocol 2013-03-16 12:43:22 +08:00
libwebsockets.spec cmake update specfile 2013-03-10 08:12:12 +08:00
LICENSE add static linking exception to LICENSE 2013-02-07 23:44:21 +08:00
README add README 2013-02-06 16:07:27 +09:00
README.build cmake improve cross documentation 2013-03-30 10:30:03 +08:00
README.coding trac 40 client connection properly nonblocking 2013-09-20 20:26:12 +08:00
README.test-apps introduce test echo 2013-01-30 12:28:44 +08:00

This is the libwebsockets C library for lightweight websocket clients and
servers.  For support, visit

 http://libwebsockets.org

and consider joining the project mailing list at

 http://ml.libwebsockets.org/mailman/listinfo/libwebsockets

You can get the latest version of the library from git

http://git.libwebsockets.org
https://github.com/warmcat/libwebsockets

for more information:

README.build      - information on building the library
README.coding     - information for writing code using the library
README.test-apps  - information about the test apps built with the library