Commit graph

1880 commits

Author SHA1 Message Date
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
Andy Green
5dc62ead9d trac 40 client connection properly nonblocking
As spotted by JM on Trac#40

http://libwebsockets.org/trac/libwebsockets/ticket/40

client connect didn't do anything about being truly nonblocking.  This patch
should hopefully solve that.

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-09-20 20:26:12 +08:00
Fujii Bunichiroh
e92947680a force failed header parse to act
''...Websocket servers return failure responses other than HTTP Status 101 in the case of
mismatches of WebSocket version or additional header data etc...
It seems that libwebsockets shows "WARN: problems parsing header" error in such cases without
calling any callbacks or returning error code. Is this right?
I modified lib/client.c to handle this.''

Signed-off-by: Fujii Bunichiroh <Bunichiroh.Fujii@jp.sony.com>
2013-09-18 21:01:02 +08:00
Andy Green
8eda4117dd remove bae64 decode and selftest
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-09-18 20:57:59 +08:00
Andy Green
512c246338 trac #39: allow fd 0 for connection
Reported (with fix) by Martijn The http://libwebsockets.org/trac/ticket/39

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-09-18 12:59:33 +08:00
Erland Isaksson
578a24df3d cmake fix for osx 64 bit
AG tested on 64-bit Fedora no problems

Signed-off-by: Erland Isaksson <erland@isaksson.info>
2013-09-18 09:00:52 +08:00
Andy Green
9beedc163c trac 36 make libwebsocket_set_timeout public
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-09-18 08:47:15 +08:00
Andy Green
96d48fdc28 change LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION user param usage
Also audit the bail_nuke_ah usage as Daniel Griscom suggested.

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-09-18 08:32:55 +08:00
David Gauchard
6c58228577 fix http incomplete send handling
Signed-off-by: David Gauchard <gauchard@laas.fr>
2013-06-29 10:24:16 +08:00
Joachim Bauch
8294c1fa4f Request "send" not to trigger SIGPIPE on errors. 2013-06-29 10:22:09 +08:00
Jiri Hnidek
eb51a7a6ef add CMake find function for libwebsockets
Signed-off-by: Jiri Hnidek <jiri.hnidek@tul.cz>
2013-06-29 10:18:52 +08:00
Niall T. Davidson
db761be972 Added additional LWS_CALLBACK_CLOSED_HTTP callback to just_kill_connection branch of close_and_free_session 2013-06-29 10:16:18 +08:00
Joachim Bauch
d727e9f698 Support empty ping and pong packets. 2013-06-23 14:47:26 +08:00
Joachim Bauch
d8b8542d59 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
Andy Green
0c9563bbd2 add LWS_CALLBACK_CLOSED_HTTP
Adds a callback to allow handling HTTP protocol connections
closing.

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-06-10 22:54:40 +08:00
Andy Green
7cf6cb00c2 trac 28 - differentiate between http serving and accepted http connection
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-05-19 14:04:10 +08:00
Simon Wulf
502b9948f2 trac 28 brackets around POLLIN flag test
Signed-off-by: Simon Wulf <simonwulf.lund@bredband.net>
2013-05-06 06:14:03 +08:00
Andy Green
66986b2e85 log err if unable to open http file
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-05-03 21:13:35 +08:00
Andy Green
6c72070fd4 trac 29 convert more snprintf stowaways
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-05-02 08:15:53 +08:00
Andy Green
86aa80509f trac 29 echo remoe mention of syslog constants for win32
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-05-02 07:04:54 +08:00
Andy Green
70d6717afb trac 29 avoid syslog in echo test if win32
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-04-30 06:53:56 +08:00
Andy Green
d91561c2f6 trac 29 eliminate snprintf again
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-04-30 06:51:10 +08:00
Andy Green
4e414e65bb trac 29 win32 EWOULDBLOCK
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-04-27 08:33:26 +08:00
Andy Green
3661d7be53 Trac 29: win32 fix LWS_VISIBLE issue
Reported-by: davetaflin
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-04-26 07:37:16 +08:00
Bob Roberts
ac04911dde cygwin compatibility
Signed-off-by: Bob Roberts <bobroberts177@gmail.com>
2013-04-25 09:16:30 +08:00
thinkski
d34bae15d3 trac 27: use fullpath in OSX dynamic libs
Signed-off-by: thinkski <chiszp@gmail.com>
2013-04-16 19:48:05 +08:00
thinkski
dd93a0c416 pkg config avoid hardcoded prefix
Signed-off-by: thinkski <chiszp@gmail.com>
2013-04-12 10:31:46 +08:00
Tomas Cejka
efda177e80 cmake use existing spec file for RPM generation
Signed-off-by: Tomas Cejka <cejkat@cesnet.cz>
2013-04-11 08:38:22 +08:00
Tomas Cejka
f35fd9789a cmake added RPM generation
Signed-off-by: Tomas Cejka <cejkat@cesnet.cz>
2013-04-11 08:38:22 +08:00
Andy Green
5b479ac2f1 cmake improve cross documentation
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-03-30 10:30:03 +08:00
Peter Pentchev
9a4fef7ed6 Hide private library symbols
Signed-off-by: Peter Pentchev <roam@ringlet.net>
2013-03-30 09:52:21 +08:00
Andy Green
01b206e804 SOL_SNDBUF set to protocol rx size
This tells the OS to reserve a TX buffer at least the size of the biggest RX frame
expected, for both server and client connections.

In Linux, the OS reserves 2 x the requested amount.

This is aimed at reducing the partial large atomic frame send problem to the point
it's only coming at large atomic frames the OS balks at reserving the size for.

If you have a lot of data to send, it is better to split it into multiple writes,
and use the FIN / CONTINUATION websocket stuff to manage it.

See the "fraggle" test app for example code of how to do that.

Signed-off-by: Andy Green <andy.green@linaro.org>
2013-03-23 09:53:17 +08:00
Andy Green
3390efd7c3 test server improve return checking
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-03-23 09:46:18 +08:00
Andy Green
98ba9e01b4 cosmetic debug improvements
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-03-23 09:44:47 +08:00
Joakim Soderberg
9c037c05fb BUGFIX: Properly add libcyassl to the lib list.
This would cause failure to build the test apps with CyaSSL.
2013-03-23 08:55:28 +08:00
Joakim Soderberg
c2012e40ed Check for GCC/G++ explicitly instead of simply Unix.
Since we're setting gcc specific build flags.
2013-03-23 08:55:02 +08:00
Joakim Soderberg
f0ee6696f4 Allow setting the resource path via command line.
It is awfully limiting when you have to set the resource path at compile time.

Instead also allow setting it via the --resource_path command line option.
2013-03-23 08:54:41 +08:00
Andy Green
b55451c6d2 introduce api for unthrottle all connections of protocol
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-03-16 12:43:22 +08:00
Andy Green
5c9fcacd7a test client have u option also reject deflate stream
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-03-16 12:43:22 +08:00
Andy Green
da3f6ffdbf cmake add gcc compile options
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-03-16 12:37:40 +08:00
Andy Green
ca0a129065 rxflow remove recursion and simplify
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-03-16 11:24:23 +08:00
Tobias Maier
37029d9081 replaced last remaining close on wsi->sock with compatible_close
Signed-off-by: Tobias Maier <tobias.maier@netplace.com>
2013-03-15 07:26:19 +08:00
Michel Archambault
e8c00aa47e Fixed read of the jpg in Windows
Windows needs to open things with _O_BINARY

Signed-off-by: Michel Archambault <marchamb@matrox.com>
2013-03-15 07:25:15 +08:00
Andy Green
2577c831f4 update service_fd comment and api docs
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-03-11 20:37:03 +08:00
Andy Green
b2637a3978 cmake update specfile
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-03-10 08:12:12 +08:00
Andy Green
27696f2596 cmake add missing echo test app
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-03-10 08:12:06 +08:00
Andy Green
c8c166221d cmake packageconfig installs to lib dir
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-03-10 08:12:01 +08:00
Andy Green
2aab3f9513 cmake ignore non source things for make dist
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-03-10 08:11:48 +08:00
Gregory Junker
c3872c5fe0 android include gregorys example makefile
Signed-off-by: Gregory Junker <ggjunker@gmail.com>
2013-03-10 07:34:53 +08:00
Andy Green
19c1a99b59 update version 1.3 soname 4
Signed-off-by: Andy Green <andy.green@linaro.org>
2013-03-10 07:34:53 +08:00