canonical libwebsockets.org websocket library
![]() 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> |
||
---|---|---|
cmake | ||
lib | ||
scripts | ||
test-server | ||
win32port | ||
.gitignore | ||
Android.mk | ||
changelog | ||
CMakeLists.txt | ||
config.h.cmake | ||
cross-arm-linux-gnueabihf.cmake | ||
libwebsockets-api-doc.html | ||
libwebsockets.spec | ||
LICENSE | ||
README | ||
README.build | ||
README.coding | ||
README.test-apps |
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