2013-01-16 12:21:29 +08:00
|
|
|
/*
|
|
|
|
* libwebsockets - small server side websockets and web server implementation
|
|
|
|
*
|
2018-11-23 08:47:56 +08:00
|
|
|
* Copyright (C) 2010-2018 Andy Green <andy@warmcat.com>
|
2013-01-16 12:21:29 +08:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation:
|
|
|
|
* version 2.1 of the License.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
* MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2018-05-03 10:49:36 +08:00
|
|
|
#include "core/private.h"
|
2013-01-16 12:21:29 +08:00
|
|
|
|
2013-02-23 10:50:10 +08:00
|
|
|
/*
|
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
|
|
|
* notice this returns number of bytes consumed, or -1
|
2013-02-23 10:50:10 +08:00
|
|
|
*/
|
2015-12-04 11:08:32 +08:00
|
|
|
int lws_issue_raw(struct lws *wsi, unsigned char *buf, size_t len)
|
2013-01-16 12:21:29 +08:00
|
|
|
{
|
2015-12-17 18:25:25 +08:00
|
|
|
struct lws_context *context = lws_get_context(wsi);
|
2017-05-07 10:02:03 +08:00
|
|
|
struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi];
|
2013-12-10 21:15:00 +08:00
|
|
|
size_t real_len = len;
|
2018-09-02 14:35:37 +08:00
|
|
|
unsigned int n, m;
|
2015-12-14 08:52:03 +08:00
|
|
|
|
http: compression methods
Add generic http compression layer eanbled at cmake with LWS_WITH_HTTP_STREAM_COMPRESSION.
This is wholly a feature of the HTTP role (used by h1 and h2 roles) and doesn't exist
outside that context.
Currently provides 'deflate' and 'br' compression methods for server side only.
'br' requires also -DLWS_WITH_HTTP_BROTLI=1 at cmake and the brotli libraries (available in
your distro already) and dev package.
Other compression methods can be added nicely using an ops struct.
The built-in file serving stuff will use this is the client says he can handle it, and the
mimetype of the file either starts with "text/" (html and css etc) or is the mimetype of
Javascript.
zlib allocates quite a bit while in use, it seems to be around 256KiB per stream. So this
is only useful on relatively strong servers with lots of memory. However for some usecases
where you are serving a lot of css and js assets, it's a nice help.
The patch performs special treatment for http/1.1 pipelining, since the compression is
performed on the fly the compressed content-length is not known until the end. So for h1
only, chunked transfer-encoding is automatically added so pipelining can continue of the
connection.
For h2 the chunking is neither supported nor required, so it "just works".
User code can also request to add a compression transform before the reply headers were
sent using the new api
LWS_VISIBLE int
lws_http_compression_apply(struct lws *wsi, const char *name,
unsigned char **p, unsigned char *end, char decomp);
... this allows transparent compression of dynamically generated HTTP. The requested
compression (eg, "deflate") is only applied if the client headers indicated it was
supported, otherwise it's a NOP.
Name may be NULL in which case the first compression method in the internal table at
stream.c that is mentioned as acceptable by the client will be used.
NOTE: the compression translation, same as h2 support, relies on the user code using
LWS_WRITE_HTTP and then LWS_WRITE_HTTP_FINAL on the last part written. The internal
lws fileserving code already does this.
2018-09-02 14:43:05 +08:00
|
|
|
// lwsl_notice("%s: len %d\n", __func__, (int)len);
|
2018-11-21 11:16:34 +08:00
|
|
|
// lwsl_hexdump_level(LLL_NOTICE, buf, len);
|
http: compression methods
Add generic http compression layer eanbled at cmake with LWS_WITH_HTTP_STREAM_COMPRESSION.
This is wholly a feature of the HTTP role (used by h1 and h2 roles) and doesn't exist
outside that context.
Currently provides 'deflate' and 'br' compression methods for server side only.
'br' requires also -DLWS_WITH_HTTP_BROTLI=1 at cmake and the brotli libraries (available in
your distro already) and dev package.
Other compression methods can be added nicely using an ops struct.
The built-in file serving stuff will use this is the client says he can handle it, and the
mimetype of the file either starts with "text/" (html and css etc) or is the mimetype of
Javascript.
zlib allocates quite a bit while in use, it seems to be around 256KiB per stream. So this
is only useful on relatively strong servers with lots of memory. However for some usecases
where you are serving a lot of css and js assets, it's a nice help.
The patch performs special treatment for http/1.1 pipelining, since the compression is
performed on the fly the compressed content-length is not known until the end. So for h1
only, chunked transfer-encoding is automatically added so pipelining can continue of the
connection.
For h2 the chunking is neither supported nor required, so it "just works".
User code can also request to add a compression transform before the reply headers were
sent using the new api
LWS_VISIBLE int
lws_http_compression_apply(struct lws *wsi, const char *name,
unsigned char **p, unsigned char *end, char decomp);
... this allows transparent compression of dynamically generated HTTP. The requested
compression (eg, "deflate") is only applied if the client headers indicated it was
supported, otherwise it's a NOP.
Name may be NULL in which case the first compression method in the internal table at
stream.c that is mentioned as acceptable by the client will be used.
NOTE: the compression translation, same as h2 support, relies on the user code using
LWS_WRITE_HTTP and then LWS_WRITE_HTTP_FINAL on the last part written. The internal
lws fileserving code already does this.
2018-09-02 14:43:05 +08:00
|
|
|
|
2017-12-07 07:20:47 +08:00
|
|
|
/*
|
|
|
|
* Detect if we got called twice without going through the
|
2018-08-20 12:02:26 +08:00
|
|
|
* event loop to handle pending. Since that guarantees extending any
|
|
|
|
* existing buflist_out it's inefficient.
|
2017-12-07 07:20:47 +08:00
|
|
|
*/
|
http: compression methods
Add generic http compression layer eanbled at cmake with LWS_WITH_HTTP_STREAM_COMPRESSION.
This is wholly a feature of the HTTP role (used by h1 and h2 roles) and doesn't exist
outside that context.
Currently provides 'deflate' and 'br' compression methods for server side only.
'br' requires also -DLWS_WITH_HTTP_BROTLI=1 at cmake and the brotli libraries (available in
your distro already) and dev package.
Other compression methods can be added nicely using an ops struct.
The built-in file serving stuff will use this is the client says he can handle it, and the
mimetype of the file either starts with "text/" (html and css etc) or is the mimetype of
Javascript.
zlib allocates quite a bit while in use, it seems to be around 256KiB per stream. So this
is only useful on relatively strong servers with lots of memory. However for some usecases
where you are serving a lot of css and js assets, it's a nice help.
The patch performs special treatment for http/1.1 pipelining, since the compression is
performed on the fly the compressed content-length is not known until the end. So for h1
only, chunked transfer-encoding is automatically added so pipelining can continue of the
connection.
For h2 the chunking is neither supported nor required, so it "just works".
User code can also request to add a compression transform before the reply headers were
sent using the new api
LWS_VISIBLE int
lws_http_compression_apply(struct lws *wsi, const char *name,
unsigned char **p, unsigned char *end, char decomp);
... this allows transparent compression of dynamically generated HTTP. The requested
compression (eg, "deflate") is only applied if the client headers indicated it was
supported, otherwise it's a NOP.
Name may be NULL in which case the first compression method in the internal table at
stream.c that is mentioned as acceptable by the client will be used.
NOTE: the compression translation, same as h2 support, relies on the user code using
LWS_WRITE_HTTP and then LWS_WRITE_HTTP_FINAL on the last part written. The internal
lws fileserving code already does this.
2018-09-02 14:43:05 +08:00
|
|
|
if (0 && buf && wsi->could_have_pending) {
|
2018-08-20 12:02:26 +08:00
|
|
|
lwsl_hexdump_level(LLL_INFO, buf, len);
|
|
|
|
lwsl_info("** %p: vh: %s, prot: %s, role %s: "
|
2019-07-16 10:02:37 -07:00
|
|
|
"Inefficient back-to-back write of %lu detected...\n",
|
|
|
|
wsi, wsi->vhost ? wsi->vhost->name : "no vhost",
|
|
|
|
wsi->protocol->name, wsi->role_ops->name,
|
|
|
|
(unsigned long)len);
|
2017-12-07 07:20:47 +08:00
|
|
|
}
|
|
|
|
|
2019-08-10 07:32:32 +01:00
|
|
|
lws_stats_bump(pt, LWSSTATS_C_API_WRITE, 1);
|
2017-05-07 10:02:03 +08:00
|
|
|
|
2014-04-10 14:25:24 +08:00
|
|
|
/* just ignore sends after we cleared the truncation buffer */
|
2018-08-20 12:02:26 +08:00
|
|
|
if (lwsi_state(wsi) == LRS_FLUSHING_BEFORE_CLOSE &&
|
http: compression methods
Add generic http compression layer eanbled at cmake with LWS_WITH_HTTP_STREAM_COMPRESSION.
This is wholly a feature of the HTTP role (used by h1 and h2 roles) and doesn't exist
outside that context.
Currently provides 'deflate' and 'br' compression methods for server side only.
'br' requires also -DLWS_WITH_HTTP_BROTLI=1 at cmake and the brotli libraries (available in
your distro already) and dev package.
Other compression methods can be added nicely using an ops struct.
The built-in file serving stuff will use this is the client says he can handle it, and the
mimetype of the file either starts with "text/" (html and css etc) or is the mimetype of
Javascript.
zlib allocates quite a bit while in use, it seems to be around 256KiB per stream. So this
is only useful on relatively strong servers with lots of memory. However for some usecases
where you are serving a lot of css and js assets, it's a nice help.
The patch performs special treatment for http/1.1 pipelining, since the compression is
performed on the fly the compressed content-length is not known until the end. So for h1
only, chunked transfer-encoding is automatically added so pipelining can continue of the
connection.
For h2 the chunking is neither supported nor required, so it "just works".
User code can also request to add a compression transform before the reply headers were
sent using the new api
LWS_VISIBLE int
lws_http_compression_apply(struct lws *wsi, const char *name,
unsigned char **p, unsigned char *end, char decomp);
... this allows transparent compression of dynamically generated HTTP. The requested
compression (eg, "deflate") is only applied if the client headers indicated it was
supported, otherwise it's a NOP.
Name may be NULL in which case the first compression method in the internal table at
stream.c that is mentioned as acceptable by the client will be used.
NOTE: the compression translation, same as h2 support, relies on the user code using
LWS_WRITE_HTTP and then LWS_WRITE_HTTP_FINAL on the last part written. The internal
lws fileserving code already does this.
2018-09-02 14:43:05 +08:00
|
|
|
!lws_has_buffered_out(wsi)
|
|
|
|
#if defined(LWS_WITH_HTTP_STREAM_COMPRESSION)
|
|
|
|
&& !wsi->http.comp_ctx.may_have_more
|
|
|
|
#endif
|
|
|
|
)
|
2017-10-25 08:00:23 +08:00
|
|
|
return (int)len;
|
2013-12-09 14:16:17 +08:00
|
|
|
|
2018-08-20 12:02:26 +08:00
|
|
|
if (buf && lws_has_buffered_out(wsi)) {
|
|
|
|
lwsl_info("** %p: vh: %s, prot: %s, incr buflist_out by %lu\n",
|
2019-07-16 10:02:37 -07:00
|
|
|
wsi, wsi->vhost ? wsi->vhost->name : "no vhost",
|
|
|
|
wsi->protocol->name, (unsigned long)len);
|
2016-04-14 15:07:44 +08:00
|
|
|
|
2018-08-20 12:02:26 +08:00
|
|
|
/*
|
|
|
|
* already buflist ahead of this, add it on the tail of the
|
|
|
|
* buflist, then ignore it for now and act like we're flushing
|
|
|
|
* the buflist...
|
|
|
|
*/
|
|
|
|
|
2018-12-13 20:05:12 +08:00
|
|
|
if (lws_buflist_append_segment(&wsi->buflist_out, buf, len))
|
|
|
|
return -1;
|
2018-08-20 12:02:26 +08:00
|
|
|
|
|
|
|
buf = NULL;
|
|
|
|
len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wsi->buflist_out) {
|
|
|
|
/* we have to drain the earliest buflist_out stuff first */
|
|
|
|
|
|
|
|
len = lws_buflist_next_segment_len(&wsi->buflist_out, &buf);
|
|
|
|
real_len = len;
|
http: compression methods
Add generic http compression layer eanbled at cmake with LWS_WITH_HTTP_STREAM_COMPRESSION.
This is wholly a feature of the HTTP role (used by h1 and h2 roles) and doesn't exist
outside that context.
Currently provides 'deflate' and 'br' compression methods for server side only.
'br' requires also -DLWS_WITH_HTTP_BROTLI=1 at cmake and the brotli libraries (available in
your distro already) and dev package.
Other compression methods can be added nicely using an ops struct.
The built-in file serving stuff will use this is the client says he can handle it, and the
mimetype of the file either starts with "text/" (html and css etc) or is the mimetype of
Javascript.
zlib allocates quite a bit while in use, it seems to be around 256KiB per stream. So this
is only useful on relatively strong servers with lots of memory. However for some usecases
where you are serving a lot of css and js assets, it's a nice help.
The patch performs special treatment for http/1.1 pipelining, since the compression is
performed on the fly the compressed content-length is not known until the end. So for h1
only, chunked transfer-encoding is automatically added so pipelining can continue of the
connection.
For h2 the chunking is neither supported nor required, so it "just works".
User code can also request to add a compression transform before the reply headers were
sent using the new api
LWS_VISIBLE int
lws_http_compression_apply(struct lws *wsi, const char *name,
unsigned char **p, unsigned char *end, char decomp);
... this allows transparent compression of dynamically generated HTTP. The requested
compression (eg, "deflate") is only applied if the client headers indicated it was
supported, otherwise it's a NOP.
Name may be NULL in which case the first compression method in the internal table at
stream.c that is mentioned as acceptable by the client will be used.
NOTE: the compression translation, same as h2 support, relies on the user code using
LWS_WRITE_HTTP and then LWS_WRITE_HTTP_FINAL on the last part written. The internal
lws fileserving code already does this.
2018-09-02 14:43:05 +08:00
|
|
|
|
|
|
|
lwsl_debug("%s: draining %d\n", __func__, (int)len);
|
2013-12-09 14:16:17 +08:00
|
|
|
}
|
2018-04-20 10:33:23 +08:00
|
|
|
|
2018-08-23 11:48:17 +08:00
|
|
|
if (!len || !buf)
|
2018-08-20 12:02:26 +08:00
|
|
|
return 0;
|
|
|
|
|
2017-10-13 10:33:02 +08:00
|
|
|
if (!wsi->http2_substream && !lws_socket_is_valid(wsi->desc.sockfd))
|
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
|
|
|
lwsl_warn("** error invalid sock but expected to send\n");
|
2013-01-16 12:21:29 +08:00
|
|
|
|
2016-03-18 23:55:59 +08:00
|
|
|
/* limit sending */
|
2017-03-16 10:46:31 +08:00
|
|
|
if (wsi->protocol->tx_packet_size)
|
2017-10-25 08:00:23 +08:00
|
|
|
n = (int)wsi->protocol->tx_packet_size;
|
2017-03-16 10:46:31 +08:00
|
|
|
else {
|
2017-10-25 08:00:23 +08:00
|
|
|
n = (int)wsi->protocol->rx_buffer_size;
|
2017-03-16 10:46:31 +08:00
|
|
|
if (!n)
|
|
|
|
n = context->pt_serv_buf_size;
|
|
|
|
}
|
2016-05-15 08:59:48 +08:00
|
|
|
n += LWS_PRE + 4;
|
2016-03-18 23:55:59 +08:00
|
|
|
if (n > len)
|
2017-10-25 08:00:23 +08:00
|
|
|
n = (int)len;
|
2016-03-18 15:02:27 +08:00
|
|
|
|
2015-12-06 05:52:09 +08:00
|
|
|
/* nope, send it on the socket directly */
|
2013-01-29 12:37:35 +08:00
|
|
|
lws_latency_pre(context, wsi);
|
2018-09-02 14:35:37 +08:00
|
|
|
m = lws_ssl_capable_write(wsi, buf, n);
|
|
|
|
lws_latency(context, wsi, "send lws_issue_raw", n, n == m);
|
|
|
|
|
|
|
|
lwsl_info("%s: ssl_capable_write (%d) says %d\n", __func__, n, m);
|
2014-04-10 14:08:10 +08:00
|
|
|
|
2017-12-07 07:20:47 +08:00
|
|
|
/* something got written, it can have been truncated now */
|
|
|
|
wsi->could_have_pending = 1;
|
|
|
|
|
2018-09-02 14:35:37 +08:00
|
|
|
switch (m) {
|
2014-04-06 06:26:35 +01:00
|
|
|
case LWS_SSL_CAPABLE_ERROR:
|
2014-10-16 08:23:46 +08:00
|
|
|
/* we're going to close, let close know sends aren't possible */
|
|
|
|
wsi->socket_is_permanently_unusable = 1;
|
2014-04-06 06:26:35 +01:00
|
|
|
return -1;
|
|
|
|
case LWS_SSL_CAPABLE_MORE_SERVICE:
|
2017-12-07 07:20:47 +08:00
|
|
|
/*
|
|
|
|
* nothing got sent, not fatal. Retry the whole thing later,
|
|
|
|
* ie, implying treat it was a truncated send so it gets
|
|
|
|
* retried
|
|
|
|
*/
|
2018-09-02 14:35:37 +08:00
|
|
|
m = 0;
|
2014-04-10 14:08:10 +08:00
|
|
|
break;
|
2013-01-16 12:21:29 +08:00
|
|
|
}
|
2018-04-20 10:33:23 +08:00
|
|
|
|
2019-07-13 11:54:40 -07:00
|
|
|
if ((int)m < 0)
|
|
|
|
m = 0;
|
|
|
|
|
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
|
|
|
/*
|
2018-08-20 12:02:26 +08:00
|
|
|
* we were sending this from buflist_out? Then not sending everything
|
|
|
|
* is a small matter of advancing ourselves only by the amount we did
|
|
|
|
* send in the buflist.
|
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
|
|
|
*/
|
2018-08-20 12:02:26 +08:00
|
|
|
if (lws_has_buffered_out(wsi)) {
|
2018-09-02 14:35:37 +08:00
|
|
|
if (m) {
|
|
|
|
lwsl_info("%p partial adv %d (vs %ld)\n", wsi, m,
|
2018-08-25 12:27:00 +08:00
|
|
|
(long)real_len);
|
2018-09-02 14:35:37 +08:00
|
|
|
lws_buflist_use_segment(&wsi->buflist_out, m);
|
2018-08-25 12:27:00 +08:00
|
|
|
}
|
2018-08-20 12:02:26 +08:00
|
|
|
|
|
|
|
if (!lws_has_buffered_out(wsi)) {
|
|
|
|
lwsl_info("%s: wsi %p: buflist_out flushed\n",
|
|
|
|
__func__, wsi);
|
|
|
|
|
2018-09-02 14:35:37 +08:00
|
|
|
m = (int)real_len;
|
2018-04-02 11:55:17 +08:00
|
|
|
if (lwsi_state(wsi) == LRS_FLUSHING_BEFORE_CLOSE) {
|
2018-11-23 08:47:56 +08:00
|
|
|
lwsl_info("*%p signalling to close now\n", wsi);
|
2014-04-10 14:25:24 +08:00
|
|
|
return -1; /* retry closing now */
|
2014-04-10 17:06:59 +08:00
|
|
|
}
|
2018-06-16 10:38:17 +08:00
|
|
|
|
2018-12-01 06:45:23 +08:00
|
|
|
if (wsi->close_when_buffered_out_drained) {
|
|
|
|
wsi->close_when_buffered_out_drained = 0;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-06-16 10:38:17 +08:00
|
|
|
#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)
|
|
|
|
#if !defined(LWS_WITHOUT_SERVER)
|
|
|
|
if (wsi->http.deferred_transaction_completed) {
|
|
|
|
lwsl_notice("%s: partial completed, doing "
|
|
|
|
"deferred transaction completed\n",
|
|
|
|
__func__);
|
|
|
|
wsi->http.deferred_transaction_completed = 0;
|
2018-09-20 07:06:51 +08:00
|
|
|
return lws_http_transaction_completed(wsi) ?
|
|
|
|
-1 : (int)real_len;
|
2018-06-16 10:38:17 +08:00
|
|
|
}
|
|
|
|
#endif
|
2020-03-04 12:51:47 +00:00
|
|
|
#endif
|
|
|
|
#if defined(LWS_ROLE_WS)
|
|
|
|
/* Since buflist_out flushed, we're not inside a frame any more */
|
|
|
|
if (wsi->ws)
|
|
|
|
wsi->ws->inside_frame = 0;
|
2018-06-16 10:38:17 +08:00
|
|
|
#endif
|
2014-04-10 11:23:18 +08:00
|
|
|
}
|
|
|
|
/* always callback on writeable */
|
2015-12-16 18:19:08 +08:00
|
|
|
lws_callback_on_writable(wsi);
|
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
|
|
|
|
2018-09-02 14:35:37 +08:00
|
|
|
return m;
|
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
|
|
|
}
|
|
|
|
|
http: compression methods
Add generic http compression layer eanbled at cmake with LWS_WITH_HTTP_STREAM_COMPRESSION.
This is wholly a feature of the HTTP role (used by h1 and h2 roles) and doesn't exist
outside that context.
Currently provides 'deflate' and 'br' compression methods for server side only.
'br' requires also -DLWS_WITH_HTTP_BROTLI=1 at cmake and the brotli libraries (available in
your distro already) and dev package.
Other compression methods can be added nicely using an ops struct.
The built-in file serving stuff will use this is the client says he can handle it, and the
mimetype of the file either starts with "text/" (html and css etc) or is the mimetype of
Javascript.
zlib allocates quite a bit while in use, it seems to be around 256KiB per stream. So this
is only useful on relatively strong servers with lots of memory. However for some usecases
where you are serving a lot of css and js assets, it's a nice help.
The patch performs special treatment for http/1.1 pipelining, since the compression is
performed on the fly the compressed content-length is not known until the end. So for h1
only, chunked transfer-encoding is automatically added so pipelining can continue of the
connection.
For h2 the chunking is neither supported nor required, so it "just works".
User code can also request to add a compression transform before the reply headers were
sent using the new api
LWS_VISIBLE int
lws_http_compression_apply(struct lws *wsi, const char *name,
unsigned char **p, unsigned char *end, char decomp);
... this allows transparent compression of dynamically generated HTTP. The requested
compression (eg, "deflate") is only applied if the client headers indicated it was
supported, otherwise it's a NOP.
Name may be NULL in which case the first compression method in the internal table at
stream.c that is mentioned as acceptable by the client will be used.
NOTE: the compression translation, same as h2 support, relies on the user code using
LWS_WRITE_HTTP and then LWS_WRITE_HTTP_FINAL on the last part written. The internal
lws fileserving code already does this.
2018-09-02 14:43:05 +08:00
|
|
|
#if defined(LWS_WITH_HTTP_STREAM_COMPRESSION)
|
|
|
|
if (wsi->http.comp_ctx.may_have_more)
|
|
|
|
lws_callback_on_writable(wsi);
|
|
|
|
#endif
|
|
|
|
|
2018-09-02 14:35:37 +08:00
|
|
|
if (m == real_len)
|
2014-04-10 14:08:10 +08:00
|
|
|
/* what we just sent went out cleanly */
|
2018-09-02 14:35:37 +08:00
|
|
|
return m;
|
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
|
|
|
|
2014-04-10 14:08:10 +08:00
|
|
|
/*
|
2018-08-20 12:02:26 +08:00
|
|
|
* We were not able to send everything... and we were not sending from
|
|
|
|
* an existing buflist_out. So we are starting a fresh buflist_out, by
|
|
|
|
* buffering the unsent remainder on it.
|
|
|
|
* (it will get first priority next time the socket is writable).
|
2014-04-10 14:08:10 +08:00
|
|
|
*/
|
2018-09-02 14:35:37 +08:00
|
|
|
lwsl_debug("%p new partial sent %d from %lu total\n", wsi, m,
|
2017-02-04 13:09:00 +01:00
|
|
|
(unsigned long)real_len);
|
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
|
|
|
|
2019-07-13 12:01:39 -07:00
|
|
|
if (lws_buflist_append_segment(&wsi->buflist_out, buf + m,
|
|
|
|
real_len - m) < 0)
|
|
|
|
return -1;
|
2018-08-20 12:02:26 +08:00
|
|
|
|
2019-08-10 07:32:32 +01:00
|
|
|
lws_stats_bump(pt, LWSSTATS_C_WRITE_PARTIALS, 1);
|
|
|
|
lws_stats_bump(pt, LWSSTATS_B_PARTIALS_ACCEPTED_PARTS, m);
|
2017-05-07 10:02:03 +08:00
|
|
|
|
2019-01-11 13:13:19 +08:00
|
|
|
#if !defined(LWS_WITH_ESP32) && !defined(LWS_PLAT_OPTEE)
|
2018-03-24 08:07:00 +08:00
|
|
|
if (lws_wsi_is_udp(wsi)) {
|
|
|
|
/* stash original destination for fulfilling UDP partials */
|
|
|
|
wsi->udp->sa_pending = wsi->udp->sa;
|
|
|
|
wsi->udp->salen_pending = wsi->udp->salen;
|
|
|
|
}
|
2018-04-12 15:56:38 +08:00
|
|
|
#endif
|
2018-03-24 08:07:00 +08:00
|
|
|
|
2014-04-10 14:08:10 +08:00
|
|
|
/* since something buffered, force it to get another chance to send */
|
2015-12-16 18:19:08 +08:00
|
|
|
lws_callback_on_writable(wsi);
|
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
|
|
|
|
2017-10-25 08:00:23 +08:00
|
|
|
return (int)real_len;
|
2013-01-16 12:21:29 +08:00
|
|
|
}
|
|
|
|
|
2016-01-11 11:34:01 +08:00
|
|
|
LWS_VISIBLE int lws_write(struct lws *wsi, unsigned char *buf, size_t len,
|
|
|
|
enum lws_write_protocol wp)
|
2013-01-16 12:21:29 +08:00
|
|
|
{
|
2016-01-19 03:34:24 +08:00
|
|
|
struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi];
|
2013-01-16 12:21:29 +08:00
|
|
|
|
2019-08-10 07:32:32 +01:00
|
|
|
lws_stats_bump(pt, LWSSTATS_C_API_LWS_WRITE, 1);
|
2017-05-07 10:02:03 +08:00
|
|
|
|
2017-05-08 10:49:10 +08:00
|
|
|
if ((int)len < 0) {
|
|
|
|
lwsl_err("%s: suspicious len int %d, ulong %lu\n", __func__,
|
|
|
|
(int)len, (unsigned long)len);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-08-10 07:32:32 +01:00
|
|
|
lws_stats_bump(pt, LWSSTATS_B_WRITE, len);
|
2017-05-07 10:02:03 +08:00
|
|
|
|
2016-04-15 12:00:23 +08:00
|
|
|
#ifdef LWS_WITH_ACCESS_LOG
|
2018-04-27 19:16:50 +08:00
|
|
|
wsi->http.access_log.sent += len;
|
2016-04-15 12:00:23 +08:00
|
|
|
#endif
|
2016-04-15 14:01:29 +08:00
|
|
|
if (wsi->vhost)
|
2016-12-12 13:36:25 +08:00
|
|
|
wsi->vhost->conn_stats.tx += len;
|
2016-04-15 12:00:23 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
assert(wsi->role_ops);
|
|
|
|
if (!wsi->role_ops->write_role_protocol)
|
|
|
|
return lws_issue_raw(wsi, buf, len);
|
2013-01-16 12:21:29 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
return wsi->role_ops->write_role_protocol(wsi, buf, len, &wp);
|
2013-01-16 12:21:29 +08:00
|
|
|
}
|
|
|
|
|
2014-04-06 06:26:35 +01:00
|
|
|
LWS_VISIBLE int
|
2015-12-15 21:15:58 +08:00
|
|
|
lws_ssl_capable_read_no_ssl(struct lws *wsi, unsigned char *buf, int len)
|
2014-04-06 06:26:35 +01:00
|
|
|
{
|
2017-05-07 10:02:03 +08:00
|
|
|
struct lws_context *context = wsi->context;
|
|
|
|
struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi];
|
2018-04-12 15:56:38 +08:00
|
|
|
int n = 0;
|
2014-04-06 06:26:35 +01:00
|
|
|
|
2019-08-10 07:32:32 +01:00
|
|
|
lws_stats_bump(pt, LWSSTATS_C_API_READ, 1);
|
2017-05-07 10:02:03 +08:00
|
|
|
|
2019-03-21 06:47:54 +08:00
|
|
|
errno = 0;
|
2018-03-24 08:07:00 +08:00
|
|
|
if (lws_wsi_is_udp(wsi)) {
|
2019-01-11 13:13:19 +08:00
|
|
|
#if !defined(LWS_WITH_ESP32) && !defined(LWS_PLAT_OPTEE)
|
2018-03-24 08:07:00 +08:00
|
|
|
wsi->udp->salen = sizeof(wsi->udp->sa);
|
|
|
|
n = recvfrom(wsi->desc.sockfd, (char *)buf, len, 0,
|
|
|
|
&wsi->udp->sa, &wsi->udp->salen);
|
2018-04-12 15:56:38 +08:00
|
|
|
#endif
|
2018-03-24 08:07:00 +08:00
|
|
|
} else
|
|
|
|
n = recv(wsi->desc.sockfd, (char *)buf, len, 0);
|
|
|
|
|
2016-05-05 09:06:09 +08:00
|
|
|
if (n >= 0) {
|
2018-09-04 08:06:46 +08:00
|
|
|
|
|
|
|
if (!n && wsi->unix_skt)
|
|
|
|
return LWS_SSL_CAPABLE_ERROR;
|
|
|
|
|
2019-03-21 06:47:54 +08:00
|
|
|
/*
|
|
|
|
* See https://libwebsockets.org/
|
|
|
|
* pipermail/libwebsockets/2019-March/007857.html
|
|
|
|
*/
|
|
|
|
if (!n)
|
|
|
|
return LWS_SSL_CAPABLE_ERROR;
|
|
|
|
|
2016-04-15 14:01:29 +08:00
|
|
|
if (wsi->vhost)
|
2016-12-12 13:36:25 +08:00
|
|
|
wsi->vhost->conn_stats.rx += n;
|
2019-08-10 07:32:32 +01:00
|
|
|
lws_stats_bump(pt, LWSSTATS_B_READ, n);
|
2018-03-24 08:07:00 +08:00
|
|
|
|
2014-04-10 14:08:10 +08:00
|
|
|
return n;
|
2016-04-15 14:01:29 +08:00
|
|
|
}
|
2018-04-11 13:39:42 +08:00
|
|
|
|
2015-10-15 21:21:06 +08:00
|
|
|
if (LWS_ERRNO == LWS_EAGAIN ||
|
|
|
|
LWS_ERRNO == LWS_EWOULDBLOCK ||
|
|
|
|
LWS_ERRNO == LWS_EINTR)
|
|
|
|
return LWS_SSL_CAPABLE_MORE_SERVICE;
|
2018-04-11 13:39:42 +08:00
|
|
|
|
2018-11-15 10:00:54 +08:00
|
|
|
lwsl_info("error on reading from skt : %d\n", LWS_ERRNO);
|
2014-04-10 14:08:10 +08:00
|
|
|
return LWS_SSL_CAPABLE_ERROR;
|
2014-04-06 06:26:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
LWS_VISIBLE int
|
2015-12-04 11:08:32 +08:00
|
|
|
lws_ssl_capable_write_no_ssl(struct lws *wsi, unsigned char *buf, int len)
|
2014-04-06 06:26:35 +01:00
|
|
|
{
|
2015-11-08 12:10:26 +08:00
|
|
|
int n = 0;
|
2019-01-11 17:14:04 +08:00
|
|
|
#if defined(LWS_PLAT_OPTEE)
|
2019-01-11 13:14:32 +08:00
|
|
|
ssize_t send(int sockfd, const void *buf, size_t len, int flags);
|
2019-01-11 17:14:04 +08:00
|
|
|
#endif
|
2015-11-02 20:34:12 +08:00
|
|
|
|
2018-03-24 08:07:00 +08:00
|
|
|
if (lws_wsi_is_udp(wsi)) {
|
2019-01-11 13:13:19 +08:00
|
|
|
#if !defined(LWS_WITH_ESP32) && !defined(LWS_PLAT_OPTEE)
|
2018-08-20 12:02:26 +08:00
|
|
|
if (lws_has_buffered_out(wsi))
|
2018-05-16 08:13:59 +08:00
|
|
|
n = sendto(wsi->desc.sockfd, (const char *)buf,
|
|
|
|
len, 0, &wsi->udp->sa_pending,
|
|
|
|
wsi->udp->salen_pending);
|
2018-03-24 08:07:00 +08:00
|
|
|
else
|
2018-05-16 08:13:59 +08:00
|
|
|
n = sendto(wsi->desc.sockfd, (const char *)buf,
|
|
|
|
len, 0, &wsi->udp->sa, wsi->udp->salen);
|
2018-04-12 15:56:38 +08:00
|
|
|
#endif
|
2018-03-24 08:07:00 +08:00
|
|
|
} else
|
|
|
|
n = send(wsi->desc.sockfd, (char *)buf, len, MSG_NOSIGNAL);
|
2016-01-27 08:50:31 +08:00
|
|
|
// lwsl_info("%s: sent len %d result %d", __func__, len, n);
|
2014-04-10 14:08:10 +08:00
|
|
|
if (n >= 0)
|
|
|
|
return n;
|
|
|
|
|
|
|
|
if (LWS_ERRNO == LWS_EAGAIN ||
|
|
|
|
LWS_ERRNO == LWS_EWOULDBLOCK ||
|
|
|
|
LWS_ERRNO == LWS_EINTR) {
|
2017-02-18 17:26:40 +08:00
|
|
|
if (LWS_ERRNO == LWS_EWOULDBLOCK) {
|
2014-04-10 14:08:10 +08:00
|
|
|
lws_set_blocking_send(wsi);
|
2017-02-18 17:26:40 +08:00
|
|
|
}
|
2014-04-06 06:26:35 +01:00
|
|
|
|
2014-04-10 14:08:10 +08:00
|
|
|
return LWS_SSL_CAPABLE_MORE_SERVICE;
|
|
|
|
}
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2017-09-23 12:55:21 +08:00
|
|
|
lwsl_debug("ERROR writing len %d to skt fd %d err %d / errno %d\n",
|
2018-11-23 08:47:56 +08:00
|
|
|
len, wsi->desc.sockfd, n, LWS_ERRNO);
|
2018-03-11 11:26:06 +08:00
|
|
|
|
2014-04-10 14:08:10 +08:00
|
|
|
return LWS_SSL_CAPABLE_ERROR;
|
2014-04-06 06:26:35 +01:00
|
|
|
}
|
2018-04-11 13:39:42 +08:00
|
|
|
|
2015-08-19 16:23:33 +02:00
|
|
|
LWS_VISIBLE int
|
2015-12-04 11:08:32 +08:00
|
|
|
lws_ssl_pending_no_ssl(struct lws *wsi)
|
2015-08-19 16:23:33 +02:00
|
|
|
{
|
2015-11-02 13:10:33 +08:00
|
|
|
(void)wsi;
|
2017-05-07 08:19:55 +08:00
|
|
|
#if defined(LWS_WITH_ESP32)
|
|
|
|
return 100;
|
|
|
|
#else
|
2017-05-03 21:28:26 +08:00
|
|
|
return 0;
|
2017-05-07 08:19:55 +08:00
|
|
|
#endif
|
2015-08-19 16:23:33 +02:00
|
|
|
}
|