2014-04-03 07:36:41 +08:00
|
|
|
/*
|
|
|
|
* libwebsockets - small server side websockets and web server implementation
|
|
|
|
*
|
2018-04-11 13:39:42 +08:00
|
|
|
* Copyright (C) 2010-2018 Andy Green <andy@warmcat.com>
|
2014-04-03 07:36:41 +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"
|
2014-04-03 07:36:41 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
int
|
|
|
|
lws_callback_as_writeable(struct lws *wsi)
|
2014-10-22 15:37:28 +08:00
|
|
|
{
|
2017-05-07 10:02:03 +08:00
|
|
|
struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi];
|
2017-12-07 07:20:47 +08:00
|
|
|
int n, m;
|
2014-10-22 15:37:28 +08:00
|
|
|
|
2017-05-07 10:02:03 +08:00
|
|
|
lws_stats_atomic_bump(wsi->context, pt, LWSSTATS_C_WRITEABLE_CB, 1);
|
|
|
|
#if defined(LWS_WITH_STATS)
|
2017-09-14 13:59:45 +08:00
|
|
|
if (wsi->active_writable_req_us) {
|
2018-10-14 06:15:36 +08:00
|
|
|
uint64_t ul = lws_time_in_microseconds() -
|
2017-09-23 12:55:21 +08:00
|
|
|
wsi->active_writable_req_us;
|
2017-05-07 10:02:03 +08:00
|
|
|
|
2017-09-23 12:55:21 +08:00
|
|
|
lws_stats_atomic_bump(wsi->context, pt,
|
|
|
|
LWSSTATS_MS_WRITABLE_DELAY, ul);
|
|
|
|
lws_stats_atomic_max(wsi->context, pt,
|
|
|
|
LWSSTATS_MS_WORST_WRITABLE_DELAY, ul);
|
2017-05-07 10:02:03 +08:00
|
|
|
wsi->active_writable_req_us = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
n = wsi->role_ops->writeable_cb[lwsi_role_server(wsi)];
|
2017-07-17 10:11:17 +08:00
|
|
|
|
2017-12-07 07:20:47 +08:00
|
|
|
m = user_callback_handle_rxflow(wsi->protocol->callback,
|
2018-04-11 13:39:42 +08:00
|
|
|
wsi, (enum lws_callback_reasons) n,
|
|
|
|
wsi->user_space, NULL, 0);
|
2017-12-07 07:20:47 +08:00
|
|
|
|
|
|
|
return m;
|
2014-10-22 15:37:28 +08:00
|
|
|
}
|
|
|
|
|
2017-07-17 10:11:17 +08:00
|
|
|
LWS_VISIBLE int
|
2015-12-15 21:15:58 +08:00
|
|
|
lws_handle_POLLOUT_event(struct lws *wsi, struct lws_pollfd *pollfd)
|
2014-04-03 07:36:41 +08:00
|
|
|
{
|
2017-11-12 09:16:46 +08:00
|
|
|
volatile struct lws *vwsi = (volatile struct lws *)wsi;
|
2018-04-11 13:39:42 +08:00
|
|
|
int n;
|
2018-03-27 09:17:19 +08:00
|
|
|
|
2018-11-29 08:29:48 +08:00
|
|
|
// lwsl_notice("%s: %p\n", __func__, wsi);
|
2018-03-27 09:17:19 +08:00
|
|
|
|
2017-11-12 09:16:46 +08:00
|
|
|
vwsi->leave_pollout_active = 0;
|
|
|
|
vwsi->handling_pollout = 1;
|
2017-04-05 08:30:55 +08:00
|
|
|
/*
|
|
|
|
* if another thread wants POLLOUT on us, from here on while
|
|
|
|
* handling_pollout is set, he will only set leave_pollout_active.
|
|
|
|
* If we are going to disable POLLOUT, we will check that first.
|
|
|
|
*/
|
2018-04-11 13:39:42 +08:00
|
|
|
wsi->could_have_pending = 0; /* clear back-to-back write detection */
|
2017-04-05 08:30:55 +08:00
|
|
|
|
2016-01-11 11:34:01 +08:00
|
|
|
/*
|
|
|
|
* user callback is lowest priority to get these notifications
|
|
|
|
* actually, since other pending things cannot be disordered
|
2018-04-11 13:39:42 +08:00
|
|
|
*
|
|
|
|
* Priority 1: pending truncated sends are incomplete ws fragments
|
2016-01-11 11:34:01 +08:00
|
|
|
* If anything else sent first the protocol would be
|
|
|
|
* corrupted.
|
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
|
|
|
*
|
|
|
|
* These are post- any compression transform
|
2016-01-11 11:34:01 +08:00
|
|
|
*/
|
2018-04-11 13:39:42 +08:00
|
|
|
|
2018-08-20 12:02:26 +08:00
|
|
|
if (lws_has_buffered_out(wsi)) {
|
2017-10-13 10:33:02 +08:00
|
|
|
//lwsl_notice("%s: completing partial\n", __func__);
|
2018-08-20 12:02:26 +08:00
|
|
|
if (lws_issue_raw(wsi, NULL, 0) < 0) {
|
2015-12-15 21:15:58 +08:00
|
|
|
lwsl_info("%s signalling to close\n", __func__);
|
2017-04-05 08:30:55 +08:00
|
|
|
goto bail_die;
|
2014-04-10 14:25:24 +08:00
|
|
|
}
|
2014-04-03 07:36:41 +08:00
|
|
|
/* leave POLLOUT active either way */
|
2017-04-05 08:30:55 +08:00
|
|
|
goto bail_ok;
|
2014-04-10 17:06:59 +08:00
|
|
|
} else
|
2018-04-02 11:55:17 +08:00
|
|
|
if (lwsi_state(wsi) == LRS_FLUSHING_BEFORE_CLOSE) {
|
2017-05-07 08:19:55 +08:00
|
|
|
wsi->socket_is_permanently_unusable = 1;
|
2017-04-05 08:30:55 +08:00
|
|
|
goto bail_die; /* retry closing now */
|
2017-05-07 08:19:55 +08:00
|
|
|
}
|
2015-12-15 21:15:58 +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
|
|
|
/* Priority 2: pre- compression transform */
|
|
|
|
|
|
|
|
#if defined(LWS_WITH_HTTP_STREAM_COMPRESSION)
|
|
|
|
if (wsi->http.comp_ctx.buflist_comp ||
|
|
|
|
wsi->http.comp_ctx.may_have_more) {
|
|
|
|
enum lws_write_protocol wp = LWS_WRITE_HTTP;
|
|
|
|
|
2018-09-02 14:35:37 +08:00
|
|
|
lwsl_info("%s: completing comp partial (buflist_comp %p, may %d)\n",
|
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
|
|
|
__func__, wsi->http.comp_ctx.buflist_comp,
|
|
|
|
wsi->http.comp_ctx.may_have_more
|
|
|
|
);
|
|
|
|
|
|
|
|
if (wsi->role_ops->write_role_protocol(wsi, NULL, 0, &wp) < 0) {
|
|
|
|
lwsl_info("%s signalling to close\n", __func__);
|
|
|
|
goto bail_die;
|
|
|
|
}
|
|
|
|
lws_callback_on_writable(wsi);
|
|
|
|
|
|
|
|
goto bail_ok;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
#ifdef LWS_WITH_CGI
|
2017-09-23 12:55:21 +08:00
|
|
|
/*
|
2018-04-11 13:39:42 +08:00
|
|
|
* A cgi master's wire protocol remains h1 or h2. He is just getting
|
|
|
|
* his data from his child cgis.
|
2016-01-11 11:34:01 +08:00
|
|
|
*/
|
2018-04-27 19:16:50 +08:00
|
|
|
if (wsi->http.cgi) {
|
2017-03-22 20:15:01 +08:00
|
|
|
/* also one shot */
|
|
|
|
if (pollfd)
|
|
|
|
if (lws_change_pollfd(wsi, LWS_POLLOUT, 0)) {
|
|
|
|
lwsl_info("failed at set pollfd\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2016-04-13 11:42:53 +08:00
|
|
|
goto user_service_go_again;
|
2017-03-22 20:15:01 +08:00
|
|
|
}
|
2016-04-13 11:42:53 +08:00
|
|
|
#endif
|
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
/* if we got here, we should have wire protocol ops set on the wsi */
|
|
|
|
assert(wsi->role_ops);
|
2016-07-15 13:41:38 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
if (!wsi->role_ops->handle_POLLOUT)
|
2017-04-05 08:30:55 +08:00
|
|
|
goto bail_ok;
|
2015-12-14 08:52:03 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
switch ((wsi->role_ops->handle_POLLOUT)(wsi)) {
|
|
|
|
case LWS_HP_RET_BAIL_OK:
|
2017-04-05 08:30:55 +08:00
|
|
|
goto bail_ok;
|
2018-04-11 13:39:42 +08:00
|
|
|
case LWS_HP_RET_BAIL_DIE:
|
2017-04-05 08:30:55 +08:00
|
|
|
goto bail_die;
|
2018-04-11 13:39:42 +08:00
|
|
|
case LWS_HP_RET_USER_SERVICE:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
2014-04-03 07:36:41 +08:00
|
|
|
}
|
2018-03-19 08:10:32 +08:00
|
|
|
|
2014-04-03 07:36:41 +08:00
|
|
|
/* one shot */
|
|
|
|
|
2017-04-05 08:30:55 +08:00
|
|
|
if (pollfd) {
|
2017-11-12 09:16:46 +08:00
|
|
|
int eff = vwsi->leave_pollout_active;
|
2017-04-05 08:30:55 +08:00
|
|
|
|
2018-04-17 11:43:20 +08:00
|
|
|
if (!eff) {
|
2017-04-05 08:30:55 +08:00
|
|
|
if (lws_change_pollfd(wsi, LWS_POLLOUT, 0)) {
|
|
|
|
lwsl_info("failed at set pollfd\n");
|
|
|
|
goto bail_die;
|
|
|
|
}
|
2018-04-17 11:43:20 +08:00
|
|
|
}
|
2017-04-05 08:30:55 +08:00
|
|
|
|
2017-11-12 09:16:46 +08:00
|
|
|
vwsi->handling_pollout = 0;
|
2017-04-05 08:30:55 +08:00
|
|
|
|
|
|
|
/* cannot get leave_pollout_active set after the above */
|
2018-02-20 12:07:10 +08:00
|
|
|
if (!eff && wsi->leave_pollout_active) {
|
|
|
|
/*
|
|
|
|
* got set inbetween sampling eff and clearing
|
|
|
|
* handling_pollout, force POLLOUT on
|
|
|
|
*/
|
|
|
|
lwsl_debug("leave_pollout_active\n");
|
|
|
|
if (lws_change_pollfd(wsi, 0, LWS_POLLOUT)) {
|
|
|
|
lwsl_info("failed at set pollfd\n");
|
|
|
|
goto bail_die;
|
|
|
|
}
|
|
|
|
}
|
2017-04-05 08:30:55 +08:00
|
|
|
|
2017-11-12 09:16:46 +08:00
|
|
|
vwsi->leave_pollout_active = 0;
|
2017-04-05 08:30:55 +08:00
|
|
|
}
|
2014-04-11 13:14:37 +08:00
|
|
|
|
2018-11-29 08:29:48 +08:00
|
|
|
if (lwsi_role_client(wsi) && !wsi->hdr_parsing_completed &&
|
2018-04-17 11:43:20 +08:00
|
|
|
lwsi_state(wsi) != LRS_H2_WAITING_TO_SEND_HEADERS &&
|
2018-11-29 08:29:48 +08:00
|
|
|
lwsi_state(wsi) != LRS_ISSUE_HTTP_BODY)
|
2017-04-05 08:30:55 +08:00
|
|
|
goto bail_ok;
|
|
|
|
|
2016-02-27 11:42:22 +08:00
|
|
|
|
2016-04-13 11:42:53 +08:00
|
|
|
#ifdef LWS_WITH_CGI
|
|
|
|
user_service_go_again:
|
|
|
|
#endif
|
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
if (wsi->role_ops->perform_user_POLLOUT) {
|
|
|
|
if (wsi->role_ops->perform_user_POLLOUT(wsi) == -1)
|
|
|
|
goto bail_die;
|
2017-10-13 10:33:02 +08:00
|
|
|
else
|
2018-04-11 13:39:42 +08:00
|
|
|
goto bail_ok;
|
2017-10-13 10:33:02 +08:00
|
|
|
}
|
|
|
|
|
2019-06-07 11:11:46 +01:00
|
|
|
lwsl_debug("%s: %p: non mux: wsistate 0x%lx, ops %s\n", __func__, wsi,
|
|
|
|
(unsigned long)wsi->wsistate, wsi->role_ops->name);
|
2018-03-11 11:26:06 +08:00
|
|
|
|
2017-11-12 09:16:46 +08:00
|
|
|
vwsi = (volatile struct lws *)wsi;
|
|
|
|
vwsi->leave_pollout_active = 0;
|
2017-04-05 08:30:55 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
n = lws_callback_as_writeable(wsi);
|
2017-11-12 09:16:46 +08:00
|
|
|
vwsi->handling_pollout = 0;
|
2017-11-05 07:03:13 +08:00
|
|
|
|
2017-11-12 09:16:46 +08:00
|
|
|
if (vwsi->leave_pollout_active)
|
2017-11-05 07:03:13 +08:00
|
|
|
lws_change_pollfd(wsi, 0, LWS_POLLOUT);
|
|
|
|
|
|
|
|
return n;
|
2017-04-05 08:30:55 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* since these don't disable the POLLOUT, they are always doing the
|
|
|
|
* right thing for leave_pollout_active whether it was set or not.
|
|
|
|
*/
|
|
|
|
|
|
|
|
bail_ok:
|
2017-11-12 09:16:46 +08:00
|
|
|
vwsi->handling_pollout = 0;
|
|
|
|
vwsi->leave_pollout_active = 0;
|
2017-04-05 08:30:55 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
bail_die:
|
2017-11-12 09:16:46 +08:00
|
|
|
vwsi->handling_pollout = 0;
|
|
|
|
vwsi->leave_pollout_active = 0;
|
2017-04-05 08:30:55 +08:00
|
|
|
|
|
|
|
return -1;
|
2014-04-03 07:36:41 +08:00
|
|
|
}
|
|
|
|
|
2018-03-05 16:49:28 +08:00
|
|
|
static int
|
|
|
|
__lws_service_timeout_check(struct lws *wsi, time_t sec)
|
2014-04-03 07:36:41 +08:00
|
|
|
{
|
2016-01-26 20:56:56 +08:00
|
|
|
struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi];
|
2018-10-10 13:54:43 +08:00
|
|
|
#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)
|
2016-06-03 22:21:14 +08:00
|
|
|
int n = 0;
|
2018-10-10 13:54:43 +08:00
|
|
|
#endif
|
2016-07-23 14:18:25 +08:00
|
|
|
|
|
|
|
(void)n;
|
2016-01-26 20:56:56 +08:00
|
|
|
|
2014-04-03 07:36:41 +08:00
|
|
|
/*
|
|
|
|
* if we went beyond the allowed time, kill the
|
|
|
|
* connection
|
|
|
|
*/
|
2019-03-20 07:39:55 +08:00
|
|
|
if (lws_compare_time_t(wsi->context, sec, wsi->pending_timeout_set) >
|
2018-03-05 16:49:28 +08:00
|
|
|
wsi->pending_timeout_limit) {
|
2017-09-23 12:55:21 +08:00
|
|
|
|
2018-10-10 13:54:43 +08:00
|
|
|
#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)
|
2017-09-23 12:55:21 +08:00
|
|
|
if (wsi->desc.sockfd != LWS_SOCK_INVALID &&
|
|
|
|
wsi->position_in_fds_table >= 0)
|
2016-07-23 14:18:25 +08:00
|
|
|
n = pt->fds[wsi->position_in_fds_table].events;
|
2018-10-10 13:54:43 +08:00
|
|
|
#endif
|
2016-06-03 22:21:14 +08:00
|
|
|
|
2017-05-07 10:02:03 +08:00
|
|
|
lws_stats_atomic_bump(wsi->context, pt, LWSSTATS_C_TIMEOUTS, 1);
|
|
|
|
|
2016-04-23 07:14:03 +08:00
|
|
|
/* no need to log normal idle keepalive timeout */
|
2019-04-05 21:19:09 +08:00
|
|
|
// if (wsi->pending_timeout != PENDING_TIMEOUT_HTTP_KEEPALIVE_IDLE)
|
2018-04-27 19:16:50 +08:00
|
|
|
#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)
|
2017-09-23 12:55:21 +08:00
|
|
|
lwsl_info("wsi %p: TIMEDOUT WAITING on %d "
|
|
|
|
"(did hdr %d, ah %p, wl %d, pfd "
|
|
|
|
"events %d) %llu vs %llu\n",
|
|
|
|
(void *)wsi, wsi->pending_timeout,
|
2018-04-27 15:20:56 +08:00
|
|
|
wsi->hdr_parsing_completed, wsi->http.ah,
|
|
|
|
pt->http.ah_wait_list_length, n,
|
2017-09-23 12:55:21 +08:00
|
|
|
(unsigned long long)sec,
|
|
|
|
(unsigned long long)wsi->pending_timeout_limit);
|
2018-01-04 12:07:56 +08:00
|
|
|
#if defined(LWS_WITH_CGI)
|
2018-04-27 19:16:50 +08:00
|
|
|
if (wsi->http.cgi)
|
|
|
|
lwsl_notice("CGI timeout: %s\n", wsi->http.cgi->summary);
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
lwsl_info("wsi %p: TIMEDOUT WAITING on %d ", (void *)wsi,
|
|
|
|
wsi->pending_timeout);
|
2018-01-04 12:07:56 +08:00
|
|
|
#endif
|
2017-09-23 12:55:21 +08:00
|
|
|
|
2019-01-29 12:25:20 +08:00
|
|
|
/* cgi timeout */
|
|
|
|
if (wsi->pending_timeout != PENDING_TIMEOUT_HTTP_KEEPALIVE_IDLE)
|
|
|
|
/*
|
|
|
|
* Since he failed a timeout, he already had a chance to
|
|
|
|
* do something and was unable to... that includes
|
|
|
|
* situations like half closed connections. So process
|
|
|
|
* this "failed timeout" close as a violent death and
|
|
|
|
* don't try to do protocol cleanup like flush partials.
|
|
|
|
*/
|
|
|
|
wsi->socket_is_permanently_unusable = 1;
|
2018-04-02 11:55:17 +08:00
|
|
|
if (lwsi_state(wsi) == LRS_WAITING_SSL && wsi->protocol)
|
2018-03-14 17:36:02 +08:00
|
|
|
wsi->protocol->callback(wsi,
|
2016-05-03 07:26:10 +08:00
|
|
|
LWS_CALLBACK_CLIENT_CONNECTION_ERROR,
|
2017-09-23 12:55:21 +08:00
|
|
|
wsi->user_space,
|
|
|
|
(void *)"Timed out waiting SSL", 21);
|
2016-05-03 07:26:10 +08:00
|
|
|
|
2018-03-05 16:49:28 +08:00
|
|
|
__lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS, "timeout");
|
2015-12-15 21:15:58 +08:00
|
|
|
|
2014-04-03 07:36:41 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-04-19 07:13:40 +01:00
|
|
|
int
|
|
|
|
lws_rxflow_cache(struct lws *wsi, unsigned char *buf, int n, int len)
|
2014-10-08 12:00:53 +08:00
|
|
|
{
|
2018-04-13 16:01:38 +08:00
|
|
|
struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi];
|
|
|
|
uint8_t *buffered;
|
|
|
|
size_t blen;
|
2019-04-19 07:13:40 +01:00
|
|
|
int ret = LWSRXFC_CACHED, m;
|
2018-04-13 16:01:38 +08:00
|
|
|
|
2014-10-08 12:00:53 +08:00
|
|
|
/* his RX is flowcontrolled, don't send remaining now */
|
2018-04-17 15:35:15 +08:00
|
|
|
blen = lws_buflist_next_segment_len(&wsi->buflist, &buffered);
|
2018-04-13 16:01:38 +08:00
|
|
|
if (blen) {
|
2019-07-01 05:53:08 +01:00
|
|
|
if (buf >= buffered && buf + len <= buffered + blen &&
|
|
|
|
blen != (size_t)len) {
|
2019-04-19 07:13:40 +01:00
|
|
|
/*
|
|
|
|
* rxflow while we were spilling prev rxflow
|
|
|
|
*
|
|
|
|
* len indicates how much was unused, then... so trim
|
|
|
|
* the head buflist to match that situation
|
|
|
|
*/
|
|
|
|
|
|
|
|
lws_buflist_use_segment(&wsi->buflist, blen - len);
|
|
|
|
lwsl_debug("%s: trim existing rxflow %d -> %d\n",
|
|
|
|
__func__, (int)blen, (int)len);
|
2018-04-13 16:01:38 +08:00
|
|
|
|
2019-04-19 07:13:40 +01:00
|
|
|
return LWSRXFC_TRIMMED;
|
2017-10-13 10:33:02 +08:00
|
|
|
}
|
2019-04-19 07:13:40 +01:00
|
|
|
ret = LWSRXFC_ADDITIONAL;
|
2014-10-08 12:00:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* a new rxflow, buffer it and warn caller */
|
2017-09-23 12:55:21 +08:00
|
|
|
|
2018-04-17 15:35:15 +08:00
|
|
|
m = lws_buflist_append_segment(&wsi->buflist, buf + n, len - n);
|
2018-04-17 11:43:20 +08:00
|
|
|
|
2018-04-13 16:01:38 +08:00
|
|
|
if (m < 0)
|
2019-04-19 07:13:40 +01:00
|
|
|
return LWSRXFC_ERROR;
|
2018-04-17 11:43:20 +08:00
|
|
|
if (m) {
|
|
|
|
lwsl_debug("%s: added %p to rxflow list\n", __func__, wsi);
|
2019-04-21 06:24:05 +01:00
|
|
|
lws_dll2_add_head(&wsi->dll_buflist, &pt->dll_buflist_owner);
|
2018-04-17 11:43:20 +08:00
|
|
|
}
|
2014-10-08 12:00:53 +08:00
|
|
|
|
2018-04-13 16:01:38 +08:00
|
|
|
return ret;
|
2014-10-08 12:00:53 +08:00
|
|
|
}
|
|
|
|
|
ah owns rxbuf
This is intended to solve a longstanding problem with the
relationship between http/1.1 keep-alive and the service
loop.
Ah now contain an rx buffer which is used during header
processing, and the ah may not be detached from the wsi
until the rx buffer is exhausted.
Having the rx buffer in the ah means we can delay using the
rx until a later service loop.
Ah which have pending rx force POLLIN service on the wsi
they are attached to automatically, so we can interleave
general service / connections with draining each ah rx
buffer.
The possible http/1.1 situations and their dispositions are:
1) exactly one set of http headers come. After processing,
the ah is detached since no pending rx left. If more
headers come later, a fresh ah is aqcuired when available
and the rx flow control blocks the read until then.
2) more that one whole set of headers come and we remain in
http mode (no upgrade). The ah is left attached and
returns to the service loop after the first set of headers.
We will get forced service due to the ah having pending
content (respecting flowcontrol) and process the pending
rx in the ah. If we use it all up, we will detach the
ah.
3) one set of http headers come with ws traffic appended.
We service the headers, do the upgrade, and keep the ah
until the remaining ws content is used. When we
exhausted the ws traffix in the ah rx buffer, we
detach the ah.
Since there can be any amount of http/1.1 pipelining on a
connection, and each may be expensive to service, it's now
enforced there is a return to the service loop after each
header set is serviced on a connection.
When I added the forced service for ah with pending buffering,
I added support for it to the windows plat code. However this
is untested.
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-02-15 12:37:04 +08:00
|
|
|
/* this is used by the platform service code to stop us waiting for network
|
|
|
|
* activity in poll() when we have something that already needs service
|
|
|
|
*/
|
|
|
|
|
2016-10-07 03:19:17 +08:00
|
|
|
LWS_VISIBLE LWS_EXTERN int
|
ah owns rxbuf
This is intended to solve a longstanding problem with the
relationship between http/1.1 keep-alive and the service
loop.
Ah now contain an rx buffer which is used during header
processing, and the ah may not be detached from the wsi
until the rx buffer is exhausted.
Having the rx buffer in the ah means we can delay using the
rx until a later service loop.
Ah which have pending rx force POLLIN service on the wsi
they are attached to automatically, so we can interleave
general service / connections with draining each ah rx
buffer.
The possible http/1.1 situations and their dispositions are:
1) exactly one set of http headers come. After processing,
the ah is detached since no pending rx left. If more
headers come later, a fresh ah is aqcuired when available
and the rx flow control blocks the read until then.
2) more that one whole set of headers come and we remain in
http mode (no upgrade). The ah is left attached and
returns to the service loop after the first set of headers.
We will get forced service due to the ah having pending
content (respecting flowcontrol) and process the pending
rx in the ah. If we use it all up, we will detach the
ah.
3) one set of http headers come with ws traffic appended.
We service the headers, do the upgrade, and keep the ah
until the remaining ws content is used. When we
exhausted the ws traffix in the ah rx buffer, we
detach the ah.
Since there can be any amount of http/1.1 pipelining on a
connection, and each may be expensive to service, it's now
enforced there is a return to the service loop after each
header set is serviced on a connection.
When I added the forced service for ah with pending buffering,
I added support for it to the windows plat code. However this
is untested.
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-02-15 12:37:04 +08:00
|
|
|
lws_service_adjust_timeout(struct lws_context *context, int timeout_ms, int tsi)
|
|
|
|
{
|
|
|
|
struct lws_context_per_thread *pt = &context->pt[tsi];
|
|
|
|
|
2018-09-02 14:35:37 +08:00
|
|
|
/*
|
|
|
|
* Figure out if we really want to wait in poll()... we only need to
|
|
|
|
* wait if really nothing already to do and we have to wait for
|
|
|
|
* something from network
|
ah owns rxbuf
This is intended to solve a longstanding problem with the
relationship between http/1.1 keep-alive and the service
loop.
Ah now contain an rx buffer which is used during header
processing, and the ah may not be detached from the wsi
until the rx buffer is exhausted.
Having the rx buffer in the ah means we can delay using the
rx until a later service loop.
Ah which have pending rx force POLLIN service on the wsi
they are attached to automatically, so we can interleave
general service / connections with draining each ah rx
buffer.
The possible http/1.1 situations and their dispositions are:
1) exactly one set of http headers come. After processing,
the ah is detached since no pending rx left. If more
headers come later, a fresh ah is aqcuired when available
and the rx flow control blocks the read until then.
2) more that one whole set of headers come and we remain in
http mode (no upgrade). The ah is left attached and
returns to the service loop after the first set of headers.
We will get forced service due to the ah having pending
content (respecting flowcontrol) and process the pending
rx in the ah. If we use it all up, we will detach the
ah.
3) one set of http headers come with ws traffic appended.
We service the headers, do the upgrade, and keep the ah
until the remaining ws content is used. When we
exhausted the ws traffix in the ah rx buffer, we
detach the ah.
Since there can be any amount of http/1.1 pipelining on a
connection, and each may be expensive to service, it's now
enforced there is a return to the service loop after each
header set is serviced on a connection.
When I added the forced service for ah with pending buffering,
I added support for it to the windows plat code. However this
is untested.
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-02-15 12:37:04 +08:00
|
|
|
*/
|
2018-04-25 08:42:18 +08:00
|
|
|
#if defined(LWS_ROLE_WS) && !defined(LWS_WITHOUT_EXTENSIONS)
|
ah owns rxbuf
This is intended to solve a longstanding problem with the
relationship between http/1.1 keep-alive and the service
loop.
Ah now contain an rx buffer which is used during header
processing, and the ah may not be detached from the wsi
until the rx buffer is exhausted.
Having the rx buffer in the ah means we can delay using the
rx until a later service loop.
Ah which have pending rx force POLLIN service on the wsi
they are attached to automatically, so we can interleave
general service / connections with draining each ah rx
buffer.
The possible http/1.1 situations and their dispositions are:
1) exactly one set of http headers come. After processing,
the ah is detached since no pending rx left. If more
headers come later, a fresh ah is aqcuired when available
and the rx flow control blocks the read until then.
2) more that one whole set of headers come and we remain in
http mode (no upgrade). The ah is left attached and
returns to the service loop after the first set of headers.
We will get forced service due to the ah having pending
content (respecting flowcontrol) and process the pending
rx in the ah. If we use it all up, we will detach the
ah.
3) one set of http headers come with ws traffic appended.
We service the headers, do the upgrade, and keep the ah
until the remaining ws content is used. When we
exhausted the ws traffix in the ah rx buffer, we
detach the ah.
Since there can be any amount of http/1.1 pipelining on a
connection, and each may be expensive to service, it's now
enforced there is a return to the service loop after each
header set is serviced on a connection.
When I added the forced service for ah with pending buffering,
I added support for it to the windows plat code. However this
is untested.
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-02-15 12:37:04 +08:00
|
|
|
/* 1) if we know we are draining rx ext, do not wait in poll */
|
2018-04-25 08:42:18 +08:00
|
|
|
if (pt->ws.rx_draining_ext_list)
|
2016-04-06 08:36:30 +08:00
|
|
|
return 0;
|
2018-04-19 12:53:53 +08:00
|
|
|
#endif
|
ah owns rxbuf
This is intended to solve a longstanding problem with the
relationship between http/1.1 keep-alive and the service
loop.
Ah now contain an rx buffer which is used during header
processing, and the ah may not be detached from the wsi
until the rx buffer is exhausted.
Having the rx buffer in the ah means we can delay using the
rx until a later service loop.
Ah which have pending rx force POLLIN service on the wsi
they are attached to automatically, so we can interleave
general service / connections with draining each ah rx
buffer.
The possible http/1.1 situations and their dispositions are:
1) exactly one set of http headers come. After processing,
the ah is detached since no pending rx left. If more
headers come later, a fresh ah is aqcuired when available
and the rx flow control blocks the read until then.
2) more that one whole set of headers come and we remain in
http mode (no upgrade). The ah is left attached and
returns to the service loop after the first set of headers.
We will get forced service due to the ah having pending
content (respecting flowcontrol) and process the pending
rx in the ah. If we use it all up, we will detach the
ah.
3) one set of http headers come with ws traffic appended.
We service the headers, do the upgrade, and keep the ah
until the remaining ws content is used. When we
exhausted the ws traffix in the ah rx buffer, we
detach the ah.
Since there can be any amount of http/1.1 pipelining on a
connection, and each may be expensive to service, it's now
enforced there is a return to the service loop after each
header set is serviced on a connection.
When I added the forced service for ah with pending buffering,
I added support for it to the windows plat code. However this
is untested.
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-02-15 12:37:04 +08:00
|
|
|
|
2019-01-13 06:58:21 +08:00
|
|
|
#if defined(LWS_WITH_TLS)
|
2018-11-23 08:47:56 +08:00
|
|
|
/* 2) if we know we have non-network pending data,
|
|
|
|
* do not wait in poll */
|
2018-05-01 12:41:42 +08:00
|
|
|
|
|
|
|
if (pt->context->tls_ops &&
|
2018-09-02 14:35:37 +08:00
|
|
|
pt->context->tls_ops->fake_POLLIN_for_buffered &&
|
|
|
|
pt->context->tls_ops->fake_POLLIN_for_buffered(pt))
|
2018-05-01 12:41:42 +08:00
|
|
|
return 0;
|
2019-01-13 06:58:21 +08:00
|
|
|
#endif
|
ah owns rxbuf
This is intended to solve a longstanding problem with the
relationship between http/1.1 keep-alive and the service
loop.
Ah now contain an rx buffer which is used during header
processing, and the ah may not be detached from the wsi
until the rx buffer is exhausted.
Having the rx buffer in the ah means we can delay using the
rx until a later service loop.
Ah which have pending rx force POLLIN service on the wsi
they are attached to automatically, so we can interleave
general service / connections with draining each ah rx
buffer.
The possible http/1.1 situations and their dispositions are:
1) exactly one set of http headers come. After processing,
the ah is detached since no pending rx left. If more
headers come later, a fresh ah is aqcuired when available
and the rx flow control blocks the read until then.
2) more that one whole set of headers come and we remain in
http mode (no upgrade). The ah is left attached and
returns to the service loop after the first set of headers.
We will get forced service due to the ah having pending
content (respecting flowcontrol) and process the pending
rx in the ah. If we use it all up, we will detach the
ah.
3) one set of http headers come with ws traffic appended.
We service the headers, do the upgrade, and keep the ah
until the remaining ws content is used. When we
exhausted the ws traffix in the ah rx buffer, we
detach the ah.
Since there can be any amount of http/1.1 pipelining on a
connection, and each may be expensive to service, it's now
enforced there is a return to the service loop after each
header set is serviced on a connection.
When I added the forced service for ah with pending buffering,
I added support for it to the windows plat code. However this
is untested.
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-02-15 12:37:04 +08:00
|
|
|
|
2018-09-02 14:35:37 +08:00
|
|
|
/*
|
2019-06-24 07:15:50 +01:00
|
|
|
* 3) If any pending sequencer events, do not wait in poll
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (pt->seq_pend_owner.count)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 4) If there is any wsi with rxflow buffered and in a state to process
|
2018-04-17 15:35:15 +08:00
|
|
|
* it, we should not wait in poll
|
|
|
|
*/
|
|
|
|
|
2019-04-21 06:24:05 +01:00
|
|
|
lws_start_foreach_dll(struct lws_dll2 *, d, pt->dll_buflist_owner.head) {
|
2018-04-17 15:35:15 +08:00
|
|
|
struct lws *wsi = lws_container_of(d, struct lws, dll_buflist);
|
|
|
|
|
2019-04-21 06:24:05 +01:00
|
|
|
if (!lws_is_flowcontrolled(wsi) &&
|
|
|
|
lwsi_state(wsi) != LRS_DEFERRING_ACTION)
|
2016-04-06 08:36:30 +08:00
|
|
|
return 0;
|
2018-04-17 15:35:15 +08:00
|
|
|
|
2018-09-02 14:35:37 +08:00
|
|
|
/*
|
2019-06-24 07:15:50 +01:00
|
|
|
* 5) If any guys with http compression to spill, we shouldn't wait in
|
2018-09-02 14:35:37 +08:00
|
|
|
* poll but hurry along and service them
|
|
|
|
*/
|
|
|
|
|
2018-04-17 15:35:15 +08:00
|
|
|
} lws_end_foreach_dll(d);
|
ah owns rxbuf
This is intended to solve a longstanding problem with the
relationship between http/1.1 keep-alive and the service
loop.
Ah now contain an rx buffer which is used during header
processing, and the ah may not be detached from the wsi
until the rx buffer is exhausted.
Having the rx buffer in the ah means we can delay using the
rx until a later service loop.
Ah which have pending rx force POLLIN service on the wsi
they are attached to automatically, so we can interleave
general service / connections with draining each ah rx
buffer.
The possible http/1.1 situations and their dispositions are:
1) exactly one set of http headers come. After processing,
the ah is detached since no pending rx left. If more
headers come later, a fresh ah is aqcuired when available
and the rx flow control blocks the read until then.
2) more that one whole set of headers come and we remain in
http mode (no upgrade). The ah is left attached and
returns to the service loop after the first set of headers.
We will get forced service due to the ah having pending
content (respecting flowcontrol) and process the pending
rx in the ah. If we use it all up, we will detach the
ah.
3) one set of http headers come with ws traffic appended.
We service the headers, do the upgrade, and keep the ah
until the remaining ws content is used. When we
exhausted the ws traffix in the ah rx buffer, we
detach the ah.
Since there can be any amount of http/1.1 pipelining on a
connection, and each may be expensive to service, it's now
enforced there is a return to the service loop after each
header set is serviced on a connection.
When I added the forced service for ah with pending buffering,
I added support for it to the windows plat code. However this
is untested.
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-02-15 12:37:04 +08:00
|
|
|
|
|
|
|
return timeout_ms;
|
|
|
|
}
|
|
|
|
|
2018-04-30 19:17:32 +08:00
|
|
|
/*
|
|
|
|
* POLLIN said there is something... we must read it, and either use it; or
|
|
|
|
* if other material already in the buflist append it and return the buflist
|
|
|
|
* head material.
|
|
|
|
*/
|
2018-04-11 13:39:42 +08:00
|
|
|
int
|
2018-04-17 15:35:15 +08:00
|
|
|
lws_buflist_aware_read(struct lws_context_per_thread *pt, struct lws *wsi,
|
|
|
|
struct lws_tokens *ebuf)
|
2018-04-11 13:39:42 +08:00
|
|
|
{
|
2018-04-30 19:17:32 +08:00
|
|
|
int n, prior = (int)lws_buflist_next_segment_len(&wsi->buflist, NULL);
|
|
|
|
|
2019-05-30 08:21:33 +08:00
|
|
|
ebuf->token = pt->serv_buf;
|
2018-04-30 19:17:32 +08:00
|
|
|
ebuf->len = lws_ssl_capable_read(wsi, pt->serv_buf,
|
|
|
|
wsi->context->pt_serv_buf_size);
|
|
|
|
|
|
|
|
if (ebuf->len == LWS_SSL_CAPABLE_MORE_SERVICE && prior)
|
|
|
|
goto get_from_buflist;
|
2018-04-11 13:39:42 +08:00
|
|
|
|
2018-04-30 19:17:32 +08:00
|
|
|
if (ebuf->len <= 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* nothing in buflist already? Then just use what we read */
|
|
|
|
|
|
|
|
if (!prior)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* stash what we read */
|
2018-04-11 13:39:42 +08:00
|
|
|
|
2019-05-30 08:21:33 +08:00
|
|
|
n = lws_buflist_append_segment(&wsi->buflist, ebuf->token,
|
2018-04-30 19:17:32 +08:00
|
|
|
ebuf->len);
|
|
|
|
if (n < 0)
|
|
|
|
return -1;
|
|
|
|
if (n) {
|
|
|
|
lwsl_debug("%s: added %p to rxflow list\n", __func__, wsi);
|
2019-04-21 06:24:05 +01:00
|
|
|
lws_dll2_add_head(&wsi->dll_buflist, &pt->dll_buflist_owner);
|
2018-04-11 13:39:42 +08:00
|
|
|
}
|
|
|
|
|
2018-04-30 19:17:32 +08:00
|
|
|
/* get the first buflist guy in line */
|
|
|
|
|
|
|
|
get_from_buflist:
|
|
|
|
|
|
|
|
ebuf->len = (int)lws_buflist_next_segment_len(&wsi->buflist,
|
2019-05-30 08:21:33 +08:00
|
|
|
&ebuf->token);
|
2018-04-30 19:17:32 +08:00
|
|
|
|
|
|
|
return 1; /* came from buflist */
|
2018-04-17 15:35:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
lws_buflist_aware_consume(struct lws *wsi, struct lws_tokens *ebuf, int used,
|
|
|
|
int buffered)
|
|
|
|
{
|
2018-04-30 19:17:32 +08:00
|
|
|
struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi];
|
2018-04-17 15:35:15 +08:00
|
|
|
int m;
|
2018-04-11 13:39:42 +08:00
|
|
|
|
2018-04-30 19:17:32 +08:00
|
|
|
/* it's in the buflist; we didn't use any */
|
|
|
|
|
|
|
|
if (!used && buffered)
|
|
|
|
return 0;
|
2018-04-11 13:39:42 +08:00
|
|
|
|
2018-04-17 15:35:15 +08:00
|
|
|
if (used && buffered) {
|
|
|
|
m = lws_buflist_use_segment(&wsi->buflist, used);
|
|
|
|
lwsl_info("%s: draining rxflow: used %d, next %d\n",
|
|
|
|
__func__, used, m);
|
|
|
|
if (m)
|
|
|
|
return 0;
|
|
|
|
|
2018-04-20 10:33:23 +08:00
|
|
|
lwsl_info("%s: removed %p from dll_buflist\n", __func__, wsi);
|
2019-04-21 06:24:05 +01:00
|
|
|
lws_dll2_remove(&wsi->dll_buflist);
|
2018-04-17 15:35:15 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-04-17 15:35:15 +08:00
|
|
|
/* any remainder goes on the buflist */
|
2018-04-11 13:39:42 +08:00
|
|
|
|
2018-04-30 19:17:32 +08:00
|
|
|
if (used != ebuf->len) {
|
|
|
|
m = lws_buflist_append_segment(&wsi->buflist,
|
2019-05-30 08:21:33 +08:00
|
|
|
ebuf->token + used,
|
2018-04-30 19:17:32 +08:00
|
|
|
ebuf->len - used);
|
|
|
|
if (m < 0)
|
|
|
|
return 1; /* OOM */
|
|
|
|
if (m) {
|
2018-11-23 08:47:56 +08:00
|
|
|
lwsl_debug("%s: added %p to rxflow list\n",
|
|
|
|
__func__, wsi);
|
2019-04-21 06:24:05 +01:00
|
|
|
lws_dll2_add_head(&wsi->dll_buflist,
|
|
|
|
&pt->dll_buflist_owner);
|
2018-04-30 19:17:32 +08:00
|
|
|
}
|
|
|
|
}
|
2018-04-17 15:35:15 +08:00
|
|
|
|
|
|
|
return 0;
|
2018-04-11 13:39:42 +08:00
|
|
|
}
|
|
|
|
|
2018-04-17 11:43:20 +08:00
|
|
|
void
|
|
|
|
lws_service_do_ripe_rxflow(struct lws_context_per_thread *pt)
|
|
|
|
{
|
|
|
|
struct lws_pollfd pfd;
|
|
|
|
|
2019-04-21 06:24:05 +01:00
|
|
|
if (!pt->dll_buflist_owner.head)
|
2018-04-17 11:43:20 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* service all guys with pending rxflow that reached a state they can
|
|
|
|
* accept the pending data
|
|
|
|
*/
|
|
|
|
|
|
|
|
lws_pt_lock(pt, __func__);
|
|
|
|
|
2019-04-21 06:24:05 +01:00
|
|
|
lws_start_foreach_dll_safe(struct lws_dll2 *, d, d1,
|
|
|
|
pt->dll_buflist_owner.head) {
|
2018-04-17 15:35:15 +08:00
|
|
|
struct lws *wsi = lws_container_of(d, struct lws, dll_buflist);
|
2018-04-17 11:43:20 +08:00
|
|
|
|
2018-04-16 19:52:28 +08:00
|
|
|
pfd.events = LWS_POLLIN;
|
|
|
|
pfd.revents = LWS_POLLIN;
|
2018-04-17 11:43:20 +08:00
|
|
|
pfd.fd = -1;
|
|
|
|
|
2019-06-07 11:11:46 +01:00
|
|
|
lwsl_debug("%s: rxflow processing: %p fc=%d, 0x%lx\n", __func__,
|
|
|
|
wsi, lws_is_flowcontrolled(wsi),
|
|
|
|
(unsigned long)wsi->wsistate);
|
2018-04-17 11:43:20 +08:00
|
|
|
|
|
|
|
if (!lws_is_flowcontrolled(wsi) &&
|
|
|
|
lwsi_state(wsi) != LRS_DEFERRING_ACTION &&
|
|
|
|
(wsi->role_ops->handle_POLLIN)(pt, wsi, &pfd) ==
|
2018-04-17 15:35:15 +08:00
|
|
|
LWS_HPI_RET_PLEASE_CLOSE_ME)
|
2018-04-17 11:43:20 +08:00
|
|
|
lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS,
|
|
|
|
"close_and_handled");
|
|
|
|
|
|
|
|
} lws_end_foreach_dll_safe(d, d1);
|
|
|
|
|
|
|
|
lws_pt_unlock(pt);
|
|
|
|
}
|
2018-04-11 13:39:42 +08:00
|
|
|
|
ah owns rxbuf
This is intended to solve a longstanding problem with the
relationship between http/1.1 keep-alive and the service
loop.
Ah now contain an rx buffer which is used during header
processing, and the ah may not be detached from the wsi
until the rx buffer is exhausted.
Having the rx buffer in the ah means we can delay using the
rx until a later service loop.
Ah which have pending rx force POLLIN service on the wsi
they are attached to automatically, so we can interleave
general service / connections with draining each ah rx
buffer.
The possible http/1.1 situations and their dispositions are:
1) exactly one set of http headers come. After processing,
the ah is detached since no pending rx left. If more
headers come later, a fresh ah is aqcuired when available
and the rx flow control blocks the read until then.
2) more that one whole set of headers come and we remain in
http mode (no upgrade). The ah is left attached and
returns to the service loop after the first set of headers.
We will get forced service due to the ah having pending
content (respecting flowcontrol) and process the pending
rx in the ah. If we use it all up, we will detach the
ah.
3) one set of http headers come with ws traffic appended.
We service the headers, do the upgrade, and keep the ah
until the remaining ws content is used. When we
exhausted the ws traffix in the ah rx buffer, we
detach the ah.
Since there can be any amount of http/1.1 pipelining on a
connection, and each may be expensive to service, it's now
enforced there is a return to the service loop after each
header set is serviced on a connection.
When I added the forced service for ah with pending buffering,
I added support for it to the windows plat code. However this
is untested.
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-02-15 12:37:04 +08:00
|
|
|
/*
|
|
|
|
* guys that need POLLIN service again without waiting for network action
|
|
|
|
* can force POLLIN here if not flowcontrolled, so they will get service.
|
|
|
|
*
|
|
|
|
* Return nonzero if anybody got their POLLIN faked
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
lws_service_flag_pending(struct lws_context *context, int tsi)
|
|
|
|
{
|
|
|
|
struct lws_context_per_thread *pt = &context->pt[tsi];
|
|
|
|
int forced = 0;
|
|
|
|
|
2018-03-02 14:22:49 +08:00
|
|
|
lws_pt_lock(pt, __func__);
|
|
|
|
|
2018-04-17 11:43:20 +08:00
|
|
|
/*
|
2018-04-19 12:53:53 +08:00
|
|
|
* 1) If there is any wsi with a buflist and in a state to process
|
2018-04-17 11:43:20 +08:00
|
|
|
* it, we should not wait in poll
|
|
|
|
*/
|
|
|
|
|
2019-04-21 06:24:05 +01:00
|
|
|
lws_start_foreach_dll(struct lws_dll2 *, d, pt->dll_buflist_owner.head) {
|
2018-04-17 15:35:15 +08:00
|
|
|
struct lws *wsi = lws_container_of(d, struct lws, dll_buflist);
|
2018-04-17 11:43:20 +08:00
|
|
|
|
2019-04-21 06:24:05 +01:00
|
|
|
if (!lws_is_flowcontrolled(wsi) &&
|
|
|
|
lwsi_state(wsi) != LRS_DEFERRING_ACTION) {
|
2018-04-17 11:43:20 +08:00
|
|
|
forced = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} lws_end_foreach_dll(d);
|
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
#if defined(LWS_ROLE_WS)
|
|
|
|
forced |= role_ops_ws.service_flag_pending(context, tsi);
|
|
|
|
#endif
|
ah owns rxbuf
This is intended to solve a longstanding problem with the
relationship between http/1.1 keep-alive and the service
loop.
Ah now contain an rx buffer which is used during header
processing, and the ah may not be detached from the wsi
until the rx buffer is exhausted.
Having the rx buffer in the ah means we can delay using the
rx until a later service loop.
Ah which have pending rx force POLLIN service on the wsi
they are attached to automatically, so we can interleave
general service / connections with draining each ah rx
buffer.
The possible http/1.1 situations and their dispositions are:
1) exactly one set of http headers come. After processing,
the ah is detached since no pending rx left. If more
headers come later, a fresh ah is aqcuired when available
and the rx flow control blocks the read until then.
2) more that one whole set of headers come and we remain in
http mode (no upgrade). The ah is left attached and
returns to the service loop after the first set of headers.
We will get forced service due to the ah having pending
content (respecting flowcontrol) and process the pending
rx in the ah. If we use it all up, we will detach the
ah.
3) one set of http headers come with ws traffic appended.
We service the headers, do the upgrade, and keep the ah
until the remaining ws content is used. When we
exhausted the ws traffix in the ah rx buffer, we
detach the ah.
Since there can be any amount of http/1.1 pipelining on a
connection, and each may be expensive to service, it's now
enforced there is a return to the service loop after each
header set is serviced on a connection.
When I added the forced service for ah with pending buffering,
I added support for it to the windows plat code. However this
is untested.
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-02-15 12:37:04 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
#if defined(LWS_WITH_TLS)
|
ah owns rxbuf
This is intended to solve a longstanding problem with the
relationship between http/1.1 keep-alive and the service
loop.
Ah now contain an rx buffer which is used during header
processing, and the ah may not be detached from the wsi
until the rx buffer is exhausted.
Having the rx buffer in the ah means we can delay using the
rx until a later service loop.
Ah which have pending rx force POLLIN service on the wsi
they are attached to automatically, so we can interleave
general service / connections with draining each ah rx
buffer.
The possible http/1.1 situations and their dispositions are:
1) exactly one set of http headers come. After processing,
the ah is detached since no pending rx left. If more
headers come later, a fresh ah is aqcuired when available
and the rx flow control blocks the read until then.
2) more that one whole set of headers come and we remain in
http mode (no upgrade). The ah is left attached and
returns to the service loop after the first set of headers.
We will get forced service due to the ah having pending
content (respecting flowcontrol) and process the pending
rx in the ah. If we use it all up, we will detach the
ah.
3) one set of http headers come with ws traffic appended.
We service the headers, do the upgrade, and keep the ah
until the remaining ws content is used. When we
exhausted the ws traffix in the ah rx buffer, we
detach the ah.
Since there can be any amount of http/1.1 pipelining on a
connection, and each may be expensive to service, it's now
enforced there is a return to the service loop after each
header set is serviced on a connection.
When I added the forced service for ah with pending buffering,
I added support for it to the windows plat code. However this
is untested.
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-02-15 12:37:04 +08:00
|
|
|
/*
|
|
|
|
* 2) For all guys with buffered SSL read data already saved up, if they
|
|
|
|
* are not flowcontrolled, fake their POLLIN status so they'll get
|
|
|
|
* service to use up the buffered incoming data, even though their
|
|
|
|
* network socket may have nothing
|
|
|
|
*/
|
2019-03-20 07:39:55 +08:00
|
|
|
lws_start_foreach_dll_safe(struct lws_dll *, p, p1,
|
|
|
|
pt->tls.dll_pending_tls_head.next) {
|
2018-11-23 08:47:56 +08:00
|
|
|
struct lws *wsi = lws_container_of(p, struct lws,
|
2019-03-20 07:39:55 +08:00
|
|
|
tls.dll_pending_tls);
|
2018-11-05 14:43:50 +08:00
|
|
|
|
ah owns rxbuf
This is intended to solve a longstanding problem with the
relationship between http/1.1 keep-alive and the service
loop.
Ah now contain an rx buffer which is used during header
processing, and the ah may not be detached from the wsi
until the rx buffer is exhausted.
Having the rx buffer in the ah means we can delay using the
rx until a later service loop.
Ah which have pending rx force POLLIN service on the wsi
they are attached to automatically, so we can interleave
general service / connections with draining each ah rx
buffer.
The possible http/1.1 situations and their dispositions are:
1) exactly one set of http headers come. After processing,
the ah is detached since no pending rx left. If more
headers come later, a fresh ah is aqcuired when available
and the rx flow control blocks the read until then.
2) more that one whole set of headers come and we remain in
http mode (no upgrade). The ah is left attached and
returns to the service loop after the first set of headers.
We will get forced service due to the ah having pending
content (respecting flowcontrol) and process the pending
rx in the ah. If we use it all up, we will detach the
ah.
3) one set of http headers come with ws traffic appended.
We service the headers, do the upgrade, and keep the ah
until the remaining ws content is used. When we
exhausted the ws traffix in the ah rx buffer, we
detach the ah.
Since there can be any amount of http/1.1 pipelining on a
connection, and each may be expensive to service, it's now
enforced there is a return to the service loop after each
header set is serviced on a connection.
When I added the forced service for ah with pending buffering,
I added support for it to the windows plat code. However this
is untested.
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-02-15 12:37:04 +08:00
|
|
|
pt->fds[wsi->position_in_fds_table].revents |=
|
|
|
|
pt->fds[wsi->position_in_fds_table].events & LWS_POLLIN;
|
|
|
|
if (pt->fds[wsi->position_in_fds_table].revents & LWS_POLLIN) {
|
|
|
|
forced = 1;
|
|
|
|
/*
|
|
|
|
* he's going to get serviced now, take him off the
|
|
|
|
* list of guys with buffered SSL. If he still has some
|
|
|
|
* at the end of the service, he'll get put back on the
|
|
|
|
* list then.
|
|
|
|
*/
|
2018-03-05 16:49:28 +08:00
|
|
|
__lws_ssl_remove_wsi_from_buffered_list(wsi);
|
ah owns rxbuf
This is intended to solve a longstanding problem with the
relationship between http/1.1 keep-alive and the service
loop.
Ah now contain an rx buffer which is used during header
processing, and the ah may not be detached from the wsi
until the rx buffer is exhausted.
Having the rx buffer in the ah means we can delay using the
rx until a later service loop.
Ah which have pending rx force POLLIN service on the wsi
they are attached to automatically, so we can interleave
general service / connections with draining each ah rx
buffer.
The possible http/1.1 situations and their dispositions are:
1) exactly one set of http headers come. After processing,
the ah is detached since no pending rx left. If more
headers come later, a fresh ah is aqcuired when available
and the rx flow control blocks the read until then.
2) more that one whole set of headers come and we remain in
http mode (no upgrade). The ah is left attached and
returns to the service loop after the first set of headers.
We will get forced service due to the ah having pending
content (respecting flowcontrol) and process the pending
rx in the ah. If we use it all up, we will detach the
ah.
3) one set of http headers come with ws traffic appended.
We service the headers, do the upgrade, and keep the ah
until the remaining ws content is used. When we
exhausted the ws traffix in the ah rx buffer, we
detach the ah.
Since there can be any amount of http/1.1 pipelining on a
connection, and each may be expensive to service, it's now
enforced there is a return to the service loop after each
header set is serviced on a connection.
When I added the forced service for ah with pending buffering,
I added support for it to the windows plat code. However this
is untested.
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-02-15 12:37:04 +08:00
|
|
|
}
|
|
|
|
|
2018-11-05 14:43:50 +08:00
|
|
|
} lws_end_foreach_dll_safe(p, p1);
|
ah owns rxbuf
This is intended to solve a longstanding problem with the
relationship between http/1.1 keep-alive and the service
loop.
Ah now contain an rx buffer which is used during header
processing, and the ah may not be detached from the wsi
until the rx buffer is exhausted.
Having the rx buffer in the ah means we can delay using the
rx until a later service loop.
Ah which have pending rx force POLLIN service on the wsi
they are attached to automatically, so we can interleave
general service / connections with draining each ah rx
buffer.
The possible http/1.1 situations and their dispositions are:
1) exactly one set of http headers come. After processing,
the ah is detached since no pending rx left. If more
headers come later, a fresh ah is aqcuired when available
and the rx flow control blocks the read until then.
2) more that one whole set of headers come and we remain in
http mode (no upgrade). The ah is left attached and
returns to the service loop after the first set of headers.
We will get forced service due to the ah having pending
content (respecting flowcontrol) and process the pending
rx in the ah. If we use it all up, we will detach the
ah.
3) one set of http headers come with ws traffic appended.
We service the headers, do the upgrade, and keep the ah
until the remaining ws content is used. When we
exhausted the ws traffix in the ah rx buffer, we
detach the ah.
Since there can be any amount of http/1.1 pipelining on a
connection, and each may be expensive to service, it's now
enforced there is a return to the service loop after each
header set is serviced on a connection.
When I added the forced service for ah with pending buffering,
I added support for it to the windows plat code. However this
is untested.
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-02-15 12:37:04 +08:00
|
|
|
#endif
|
2018-04-11 13:39:42 +08:00
|
|
|
|
2018-03-02 14:22:49 +08:00
|
|
|
lws_pt_unlock(pt);
|
|
|
|
|
ah owns rxbuf
This is intended to solve a longstanding problem with the
relationship between http/1.1 keep-alive and the service
loop.
Ah now contain an rx buffer which is used during header
processing, and the ah may not be detached from the wsi
until the rx buffer is exhausted.
Having the rx buffer in the ah means we can delay using the
rx until a later service loop.
Ah which have pending rx force POLLIN service on the wsi
they are attached to automatically, so we can interleave
general service / connections with draining each ah rx
buffer.
The possible http/1.1 situations and their dispositions are:
1) exactly one set of http headers come. After processing,
the ah is detached since no pending rx left. If more
headers come later, a fresh ah is aqcuired when available
and the rx flow control blocks the read until then.
2) more that one whole set of headers come and we remain in
http mode (no upgrade). The ah is left attached and
returns to the service loop after the first set of headers.
We will get forced service due to the ah having pending
content (respecting flowcontrol) and process the pending
rx in the ah. If we use it all up, we will detach the
ah.
3) one set of http headers come with ws traffic appended.
We service the headers, do the upgrade, and keep the ah
until the remaining ws content is used. When we
exhausted the ws traffix in the ah rx buffer, we
detach the ah.
Since there can be any amount of http/1.1 pipelining on a
connection, and each may be expensive to service, it's now
enforced there is a return to the service loop after each
header set is serviced on a connection.
When I added the forced service for ah with pending buffering,
I added support for it to the windows plat code. However this
is untested.
Signed-off-by: Andy Green <andy.green@linaro.org>
2016-02-15 12:37:04 +08:00
|
|
|
return forced;
|
|
|
|
}
|
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
static int
|
|
|
|
lws_service_periodic_checks(struct lws_context *context,
|
|
|
|
struct lws_pollfd *pollfd, int tsi)
|
2014-04-03 07:36:41 +08:00
|
|
|
{
|
2016-01-19 03:34:24 +08:00
|
|
|
struct lws_context_per_thread *pt = &context->pt[tsi];
|
2018-07-30 15:24:16 -05:00
|
|
|
struct lws_timed_vh_protocol *tmr;
|
2016-01-20 17:35:18 +08:00
|
|
|
lws_sockfd_type our_fd = 0, tmp_fd;
|
2018-03-19 16:37:37 +08:00
|
|
|
struct lws *wsi;
|
2015-12-06 05:52:09 +08:00
|
|
|
int timed_out = 0;
|
|
|
|
time_t now;
|
2018-04-27 19:16:50 +08:00
|
|
|
#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)
|
|
|
|
struct allocated_headers *ah;
|
2018-07-30 15:24:16 -05:00
|
|
|
int n, m;
|
2018-04-27 19:16:50 +08:00
|
|
|
#endif
|
2018-03-19 16:37:37 +08:00
|
|
|
|
2016-04-06 16:15:40 +08:00
|
|
|
if (!context->protocol_init_done)
|
2018-07-31 13:21:56 +08:00
|
|
|
if (lws_protocol_init(context)) {
|
|
|
|
lwsl_err("%s: lws_protocol_init failed\n", __func__);
|
2017-11-08 14:21:03 +08:00
|
|
|
return -1;
|
2018-07-31 13:21:56 +08:00
|
|
|
}
|
2016-04-06 16:15:40 +08:00
|
|
|
|
2014-04-03 07:36:41 +08:00
|
|
|
time(&now);
|
|
|
|
|
2016-05-24 17:44:35 +08:00
|
|
|
/*
|
|
|
|
* handle case that system time was uninitialized when lws started
|
|
|
|
* at boot, and got initialized a little later
|
|
|
|
*/
|
|
|
|
if (context->time_up < 1464083026 && now > 1464083026)
|
|
|
|
context->time_up = now;
|
|
|
|
|
2017-11-24 11:00:59 +08:00
|
|
|
if (context->last_timeout_check_s &&
|
|
|
|
now - context->last_timeout_check_s > 100) {
|
|
|
|
/*
|
|
|
|
* There has been a discontiguity. Any stored time that is
|
|
|
|
* less than context->time_discontiguity should have context->
|
|
|
|
* time_fixup added to it.
|
|
|
|
*
|
|
|
|
* Some platforms with no RTC will experience this as a normal
|
|
|
|
* event when ntp sets their clock, but we can have started
|
|
|
|
* long before that with a 0-based unix time.
|
|
|
|
*/
|
|
|
|
|
|
|
|
context->time_discontiguity = now;
|
|
|
|
context->time_fixup = now - context->last_timeout_check_s;
|
|
|
|
|
|
|
|
lwsl_notice("time discontiguity: at old time %llus, "
|
|
|
|
"new time %llus: +%llus\n",
|
|
|
|
(unsigned long long)context->last_timeout_check_s,
|
|
|
|
(unsigned long long)context->time_discontiguity,
|
|
|
|
(unsigned long long)context->time_fixup);
|
|
|
|
|
|
|
|
context->last_timeout_check_s = now - 1;
|
|
|
|
}
|
|
|
|
|
2019-06-24 07:15:50 +01:00
|
|
|
lws_sequencer_timeout_check(pt, now);
|
|
|
|
lws_pt_do_pending_sequencer_events(pt);
|
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
if (!lws_compare_time_t(context, context->last_timeout_check_s, now))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
context->last_timeout_check_s = now;
|
2014-04-03 07:36:41 +08:00
|
|
|
|
2017-05-07 10:02:03 +08:00
|
|
|
#if defined(LWS_WITH_STATS)
|
2018-04-11 13:39:42 +08:00
|
|
|
if (!tsi && now - context->last_dump > 10) {
|
|
|
|
lws_stats_log_dump(context);
|
|
|
|
context->last_dump = now;
|
|
|
|
}
|
2017-05-07 10:02:03 +08:00
|
|
|
#endif
|
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
lws_plat_service_periodic(context);
|
vhost_destroy: use vhost wsi reference counting to trigger destroy
This changes the vhost destroy flow to only hand off the listen
socket if another vhost sharing it, and mark the vhost as
being_destroyed.
Each tsi calls lws_check_deferred_free() once a second, if it sees
any vhost being_destroyed there, it closes all wsi on its tsi on
the same vhost, one time.
As the wsi on the vhost complete close (ie, after libuv async close
if on libuv event loop), they decrement a reference count for all
wsi open on the vhost. The tsi who closes the last one then
completes the destroy flow for the vhost itself... it's random
which tsi completes the vhost destroy but since there are no
wsi left on the vhost, and it holds the context lock, nothing
can conflict.
The advantage of this is that owning tsi do the close for wsi
that are bound to the vhost under destruction, at a time when
they are guaranteed to be idle for service, and they do it with
both vhost and context locks owned, so no other service thread
can conflict for stuff protected by those either.
For the situation the user code may have allocations attached to
the vhost, this adds args to lws_vhost_destroy() to allow destroying
the user allocations just before the vhost is freed.
2018-06-16 09:31:07 +08:00
|
|
|
lws_check_deferred_free(context, tsi, 0);
|
2017-07-15 14:37:04 +08:00
|
|
|
|
2017-09-14 13:14:11 +08:00
|
|
|
#if defined(LWS_WITH_PEER_LIMITS)
|
2018-04-11 13:39:42 +08:00
|
|
|
lws_peer_cull_peer_wait_list(context);
|
2017-09-14 13:14:11 +08:00
|
|
|
#endif
|
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
/* retire unused deprecated context */
|
2017-02-18 17:26:40 +08:00
|
|
|
#if !defined(LWS_PLAT_OPTEE) && !defined(LWS_WITH_ESP32)
|
2018-04-11 13:39:42 +08:00
|
|
|
#if !defined(_WIN32)
|
|
|
|
if (context->deprecated && !context->count_wsi_allocated) {
|
|
|
|
lwsl_notice("%s: ending deprecated context\n", __func__);
|
|
|
|
kill(getpid(), SIGINT);
|
|
|
|
return 0;
|
|
|
|
}
|
2017-01-17 07:01:02 +08:00
|
|
|
#endif
|
2016-12-22 11:32:34 +08:00
|
|
|
#endif
|
2018-04-11 13:39:42 +08:00
|
|
|
/* global timeout check once per second */
|
2014-04-03 07:36:41 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
if (pollfd)
|
|
|
|
our_fd = pollfd->fd;
|
2014-04-03 07:36:41 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
/*
|
2018-11-15 16:33:54 +08:00
|
|
|
* Phase 1: check every wsi on our pt's timeout check list
|
2018-04-11 13:39:42 +08:00
|
|
|
*/
|
2017-08-21 08:55:13 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
lws_pt_lock(pt, __func__);
|
2017-08-21 08:55:13 +08:00
|
|
|
|
2019-03-20 07:39:55 +08:00
|
|
|
lws_start_foreach_dll_safe(struct lws_dll *, d, d1,
|
|
|
|
context->pt[tsi].dll_timeout_head.next) {
|
2018-04-11 13:39:42 +08:00
|
|
|
wsi = lws_container_of(d, struct lws, dll_timeout);
|
2019-03-20 07:39:55 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
tmp_fd = wsi->desc.sockfd;
|
|
|
|
if (__lws_service_timeout_check(wsi, now)) {
|
|
|
|
/* he did time out... */
|
|
|
|
if (tmp_fd == our_fd)
|
|
|
|
/* it was the guy we came to service! */
|
|
|
|
timed_out = 1;
|
|
|
|
/* he's gone, no need to mark as handled */
|
|
|
|
}
|
|
|
|
} lws_end_foreach_dll_safe(d, d1);
|
2017-08-21 08:55:13 +08:00
|
|
|
|
2018-04-27 19:16:50 +08:00
|
|
|
#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)
|
2018-04-11 13:39:42 +08:00
|
|
|
/*
|
|
|
|
* Phase 2: double-check active ah timeouts independent of wsi
|
|
|
|
* timeout status
|
|
|
|
*/
|
2017-10-06 16:07:57 +08:00
|
|
|
|
2018-04-27 15:20:56 +08:00
|
|
|
ah = pt->http.ah_list;
|
2018-04-11 13:39:42 +08:00
|
|
|
while (ah) {
|
|
|
|
int len;
|
|
|
|
char buf[256];
|
|
|
|
const unsigned char *c;
|
|
|
|
|
|
|
|
if (!ah->in_use || !ah->wsi || !ah->assigned ||
|
|
|
|
(ah->wsi->vhost &&
|
|
|
|
lws_compare_time_t(context, now, ah->assigned) <
|
|
|
|
ah->wsi->vhost->timeout_secs_ah_idle + 360)) {
|
|
|
|
ah = ah->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* a single ah session somehow got held for
|
|
|
|
* an unreasonable amount of time.
|
|
|
|
*
|
|
|
|
* Dump info on the connection...
|
|
|
|
*/
|
|
|
|
wsi = ah->wsi;
|
|
|
|
buf[0] = '\0';
|
2017-12-20 10:44:21 +08:00
|
|
|
#if !defined(LWS_PLAT_OPTEE)
|
2018-04-11 13:39:42 +08:00
|
|
|
lws_get_peer_simple(wsi, buf, sizeof(buf));
|
2017-12-20 10:44:21 +08:00
|
|
|
#else
|
2018-04-11 13:39:42 +08:00
|
|
|
buf[0] = '\0';
|
|
|
|
#endif
|
|
|
|
lwsl_notice("ah excessive hold: wsi %p\n"
|
|
|
|
" peer address: %s\n"
|
2019-06-07 11:11:46 +01:00
|
|
|
" ah pos %lu\n",
|
|
|
|
wsi, buf, (unsigned long)ah->pos);
|
2018-04-11 13:39:42 +08:00
|
|
|
buf[0] = '\0';
|
|
|
|
m = 0;
|
|
|
|
do {
|
|
|
|
c = lws_token_to_string(m);
|
|
|
|
if (!c)
|
|
|
|
break;
|
|
|
|
if (!(*c))
|
|
|
|
break;
|
2017-08-21 08:55:13 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
len = lws_hdr_total_length(wsi, m);
|
|
|
|
if (!len || len > (int)sizeof(buf) - 1) {
|
2017-10-06 16:07:57 +08:00
|
|
|
m++;
|
2018-04-11 13:39:42 +08:00
|
|
|
continue;
|
|
|
|
}
|
2017-08-21 08:55:13 +08:00
|
|
|
|
2018-10-26 16:14:30 +08:00
|
|
|
if (lws_hdr_copy(wsi, buf, sizeof buf, m) > 0) {
|
2018-04-11 13:39:42 +08:00
|
|
|
buf[sizeof(buf) - 1] = '\0';
|
2018-01-13 05:14:43 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
lwsl_notice(" %s = %s\n",
|
|
|
|
(const char *)c, buf);
|
|
|
|
}
|
|
|
|
m++;
|
|
|
|
} while (1);
|
2018-01-13 05:14:43 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
/* explicitly detach the ah */
|
|
|
|
lws_header_table_detach(wsi, 0);
|
2017-10-06 16:07:57 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
/* ... and then drop the connection */
|
2017-10-06 16:07:57 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
m = 0;
|
|
|
|
if (wsi->desc.sockfd == our_fd) {
|
|
|
|
m = timed_out;
|
2017-08-21 08:55:13 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
/* it was the guy we came to service! */
|
|
|
|
timed_out = 1;
|
|
|
|
}
|
2018-03-05 16:49:28 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
if (!m) /* if he didn't already timeout */
|
|
|
|
__lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS,
|
|
|
|
"excessive ah");
|
2016-01-26 20:56:56 +08:00
|
|
|
|
2018-04-27 15:20:56 +08:00
|
|
|
ah = pt->http.ah_list;
|
2018-04-11 13:39:42 +08:00
|
|
|
}
|
2018-04-27 19:16:50 +08:00
|
|
|
#endif
|
2018-04-11 13:39:42 +08:00
|
|
|
lws_pt_unlock(pt);
|
2017-12-07 10:16:17 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
#if 0
|
|
|
|
{
|
|
|
|
char s[300], *p = s;
|
2018-03-29 13:32:33 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
for (n = 0; n < context->count_threads; n++)
|
|
|
|
p += sprintf(p, " %7lu (%5d), ",
|
|
|
|
context->pt[n].count_conns,
|
|
|
|
context->pt[n].fds_count);
|
2018-03-29 13:32:33 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
lwsl_notice("load: %s\n", s);
|
2014-04-03 07:36:41 +08:00
|
|
|
}
|
2018-04-11 13:39:42 +08:00
|
|
|
#endif
|
2016-07-15 13:41:38 +08:00
|
|
|
/*
|
2018-04-11 13:39:42 +08:00
|
|
|
* Phase 3: vhost / protocol timer callbacks
|
2016-07-15 13:41:38 +08:00
|
|
|
*/
|
|
|
|
|
2018-07-30 15:24:16 -05:00
|
|
|
/* 3a: lock, collect, and remove vh timers that are pending */
|
|
|
|
|
|
|
|
lws_context_lock(context, "expired vh timers"); /* context ---------- */
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* first, under the context lock, get a count of the number of
|
|
|
|
* expired timers so we can allocate for them (or not, cleanly)
|
|
|
|
*/
|
|
|
|
|
|
|
|
lws_start_foreach_ll(struct lws_vhost *, v, context->vhost_list) {
|
|
|
|
|
|
|
|
if (v->timed_vh_protocol_list) {
|
|
|
|
|
|
|
|
lws_start_foreach_ll_safe(struct lws_timed_vh_protocol *,
|
|
|
|
q, v->timed_vh_protocol_list, next) {
|
2018-11-15 16:33:54 +08:00
|
|
|
if (now >= q->time && q->tsi_req == tsi)
|
2018-07-30 15:24:16 -05:00
|
|
|
n++;
|
|
|
|
} lws_end_foreach_ll_safe(q);
|
|
|
|
}
|
|
|
|
|
|
|
|
} lws_end_foreach_ll(v, vhost_next);
|
|
|
|
|
|
|
|
/* if nothing to do, unlock and move on to the next vhost */
|
|
|
|
|
|
|
|
if (!n) {
|
|
|
|
lws_context_unlock(context); /* ----------- context */
|
|
|
|
goto vh_timers_done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* attempt to do the wsi and timer info allocation
|
|
|
|
* first en bloc. If it fails, we can just skip the rest and
|
|
|
|
* the timers will still be pending next time.
|
|
|
|
*/
|
|
|
|
|
|
|
|
wsi = lws_zalloc(sizeof(*wsi), "cbwsi");
|
|
|
|
if (!wsi) {
|
|
|
|
/*
|
|
|
|
* at this point, we haven't cleared any vhost
|
|
|
|
* timers. We can fail out and retry cleanly
|
|
|
|
* next periodic check
|
|
|
|
*/
|
|
|
|
lws_context_unlock(context); /* ----------- context */
|
|
|
|
goto vh_timers_done;
|
|
|
|
}
|
|
|
|
wsi->context = context;
|
|
|
|
|
|
|
|
tmr = lws_zalloc(sizeof(*tmr) * n, "cbtmr");
|
|
|
|
if (!tmr) {
|
|
|
|
/* again OOM here can be handled cleanly */
|
|
|
|
lws_free(wsi);
|
|
|
|
lws_context_unlock(context); /* ----------- context */
|
|
|
|
goto vh_timers_done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* so we have the allocation for n pending timers... */
|
|
|
|
|
|
|
|
m = 0;
|
2018-04-11 13:39:42 +08:00
|
|
|
lws_start_foreach_ll(struct lws_vhost *, v, context->vhost_list) {
|
2018-07-30 15:24:16 -05:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
if (v->timed_vh_protocol_list) {
|
2018-07-30 15:24:16 -05:00
|
|
|
|
2018-11-15 16:33:54 +08:00
|
|
|
lws_vhost_lock(v); /* vhost ------------------------- */
|
|
|
|
|
2018-07-30 15:24:16 -05:00
|
|
|
lws_start_foreach_ll_safe(struct lws_timed_vh_protocol *,
|
|
|
|
q, v->timed_vh_protocol_list, next) {
|
|
|
|
|
|
|
|
/* only do n */
|
|
|
|
if (m == n)
|
|
|
|
break;
|
|
|
|
|
2018-11-15 16:33:54 +08:00
|
|
|
if (now >= q->time && q->tsi_req == tsi) {
|
2018-07-30 15:24:16 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* tmr is an allocated array.
|
|
|
|
* Ignore the linked-list.
|
|
|
|
*/
|
|
|
|
tmr[m].vhost = v;
|
|
|
|
tmr[m].protocol = q->protocol;
|
|
|
|
tmr[m++].reason = q->reason;
|
|
|
|
|
|
|
|
/* take the timer out now we took
|
|
|
|
* responsibility */
|
2018-11-15 16:33:54 +08:00
|
|
|
__lws_timed_callback_remove(v, q);
|
2016-07-15 13:41:38 +08:00
|
|
|
}
|
2018-07-30 15:24:16 -05:00
|
|
|
|
|
|
|
} lws_end_foreach_ll_safe(q);
|
2018-11-15 16:33:54 +08:00
|
|
|
|
|
|
|
lws_vhost_unlock(v); /* ----------------------- vhost */
|
2018-04-11 13:39:42 +08:00
|
|
|
}
|
2018-07-30 15:24:16 -05:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
} lws_end_foreach_ll(v, vhost_next);
|
2018-07-30 15:24:16 -05:00
|
|
|
lws_context_unlock(context); /* ---------------------------- context */
|
|
|
|
|
|
|
|
/* 3b: call the vh timer callbacks outside any lock */
|
|
|
|
|
|
|
|
for (m = 0; m < n; m++) {
|
|
|
|
|
|
|
|
wsi->vhost = tmr[m].vhost; /* not a real bound wsi */
|
|
|
|
wsi->protocol = tmr[m].protocol;
|
|
|
|
|
|
|
|
lwsl_debug("%s: timed cb: vh %s, protocol %s, reason %d\n",
|
|
|
|
__func__, tmr[m].vhost->name, tmr[m].protocol->name,
|
|
|
|
tmr[m].reason);
|
|
|
|
tmr[m].protocol->callback(wsi, tmr[m].reason, NULL, NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
lws_free(tmr);
|
|
|
|
lws_free(wsi);
|
|
|
|
|
|
|
|
vh_timers_done:
|
2018-03-02 15:31:35 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
/*
|
|
|
|
* Phase 4: check for unconfigured vhosts due to required
|
|
|
|
* interface missing before
|
|
|
|
*/
|
2018-03-02 15:31:35 +08:00
|
|
|
|
2018-06-27 07:15:39 +08:00
|
|
|
lws_context_lock(context, "periodic checks");
|
2018-04-11 13:39:42 +08:00
|
|
|
lws_start_foreach_llp(struct lws_vhost **, pv,
|
|
|
|
context->no_listener_vhost_list) {
|
|
|
|
struct lws_vhost *v = *pv;
|
|
|
|
lwsl_debug("deferred iface: checking if on vh %s\n", (*pv)->name);
|
2018-04-29 10:44:36 +08:00
|
|
|
if (_lws_vhost_init_server(NULL, *pv) == 0) {
|
2018-04-11 13:39:42 +08:00
|
|
|
/* became happy */
|
|
|
|
lwsl_notice("vh %s: became connected\n", v->name);
|
|
|
|
*pv = v->no_listener_vhost_list;
|
|
|
|
v->no_listener_vhost_list = NULL;
|
|
|
|
break;
|
2016-07-15 13:41:38 +08:00
|
|
|
}
|
2018-04-11 13:39:42 +08:00
|
|
|
} lws_end_foreach_llp(pv, no_listener_vhost_list);
|
|
|
|
lws_context_unlock(context);
|
2016-07-15 13:41:38 +08:00
|
|
|
|
2017-10-26 18:53:34 +08:00
|
|
|
/*
|
2018-04-11 13:39:42 +08:00
|
|
|
* Phase 5: role periodic checks
|
2017-10-26 18:53:34 +08:00
|
|
|
*/
|
2018-04-11 13:39:42 +08:00
|
|
|
#if defined(LWS_ROLE_WS)
|
|
|
|
role_ops_ws.periodic_checks(context, tsi, now);
|
|
|
|
#endif
|
|
|
|
#if defined(LWS_ROLE_CGI)
|
|
|
|
role_ops_cgi.periodic_checks(context, tsi, now);
|
|
|
|
#endif
|
|
|
|
|
2019-01-13 06:58:21 +08:00
|
|
|
#if defined(LWS_WITH_TLS)
|
2018-04-11 13:39:42 +08:00
|
|
|
/*
|
|
|
|
* Phase 6: check the remaining cert lifetime daily
|
|
|
|
*/
|
2018-05-02 18:35:58 +08:00
|
|
|
|
|
|
|
if (context->tls_ops &&
|
|
|
|
context->tls_ops->periodic_housekeeping)
|
|
|
|
context->tls_ops->periodic_housekeeping(context, now);
|
2019-01-13 06:58:21 +08:00
|
|
|
#endif
|
2017-09-14 13:14:11 +08:00
|
|
|
|
2018-07-31 13:21:56 +08:00
|
|
|
return 0;
|
2018-04-11 13:39:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
LWS_VISIBLE int
|
|
|
|
lws_service_fd_tsi(struct lws_context *context, struct lws_pollfd *pollfd,
|
|
|
|
int tsi)
|
|
|
|
{
|
|
|
|
struct lws_context_per_thread *pt = &context->pt[tsi];
|
|
|
|
struct lws *wsi;
|
2014-04-03 07:36:41 +08:00
|
|
|
|
2018-04-30 09:16:04 +08:00
|
|
|
if (!context || context->being_destroyed1)
|
|
|
|
return -1;
|
|
|
|
|
2018-11-14 20:04:14 +08:00
|
|
|
/* the case there's no pollfd to service, we just want to do periodic */
|
|
|
|
if (!pollfd) {
|
|
|
|
lws_service_periodic_checks(context, pollfd, tsi);
|
2018-07-31 13:21:56 +08:00
|
|
|
return -2;
|
2018-11-14 20:04:14 +08:00
|
|
|
}
|
2014-04-03 07:36:41 +08:00
|
|
|
|
2019-03-20 07:39:55 +08:00
|
|
|
assert(lws_socket_is_valid(pollfd->fd));
|
|
|
|
|
2014-04-03 07:36:41 +08:00
|
|
|
/* no, here to service a socket descriptor */
|
2015-11-02 20:34:12 +08:00
|
|
|
wsi = wsi_from_fd(context, pollfd->fd);
|
2015-12-06 05:52:09 +08:00
|
|
|
if (!wsi)
|
2014-04-03 07:36:41 +08:00
|
|
|
/* not lws connection ... leave revents alone and return */
|
|
|
|
return 0;
|
|
|
|
|
2019-02-23 05:41:30 +08:00
|
|
|
#if LWS_MAX_SMP > 1
|
|
|
|
if (wsi->undergoing_init_from_other_pt)
|
|
|
|
/*
|
|
|
|
* Temporary situation that other service thread is initializing
|
|
|
|
* this wsi right now for use on our service thread.
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
|
2014-04-03 07:36:41 +08:00
|
|
|
/*
|
|
|
|
* so that caller can tell we handled, past here we need to
|
|
|
|
* zero down pollfd->revents after handling
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* handle session socket closed */
|
|
|
|
|
2016-01-26 20:56:56 +08:00
|
|
|
if ((!(pollfd->revents & pollfd->events & LWS_POLLIN)) &&
|
2015-12-28 14:24:49 +08:00
|
|
|
(pollfd->revents & LWS_POLLHUP)) {
|
2016-01-27 08:50:31 +08:00
|
|
|
wsi->socket_is_permanently_unusable = 1;
|
2014-04-03 07:36:41 +08:00
|
|
|
lwsl_debug("Session Socket %p (fd=%d) dead\n",
|
2018-04-11 13:39:42 +08:00
|
|
|
(void *)wsi, pollfd->fd);
|
2014-04-03 07:36:41 +08:00
|
|
|
|
|
|
|
goto close_and_handled;
|
|
|
|
}
|
2015-12-17 15:35:41 +08:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
if (pollfd->revents & LWS_POLLOUT)
|
|
|
|
wsi->sock_send_blocking = FALSE;
|
2015-11-08 12:10:26 +08:00
|
|
|
#endif
|
2014-04-03 07:36:41 +08:00
|
|
|
|
2017-07-28 18:01:14 +02:00
|
|
|
if ((!(pollfd->revents & pollfd->events & LWS_POLLIN)) &&
|
2017-10-18 09:41:44 +08:00
|
|
|
(pollfd->revents & LWS_POLLHUP)) {
|
2017-05-07 08:19:55 +08:00
|
|
|
lwsl_debug("pollhup\n");
|
|
|
|
wsi->socket_is_permanently_unusable = 1;
|
2017-02-14 09:26:53 +08:00
|
|
|
goto close_and_handled;
|
2017-05-07 08:19:55 +08:00
|
|
|
}
|
2016-02-21 21:25:48 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
#if defined(LWS_WITH_TLS)
|
2018-05-02 18:35:58 +08:00
|
|
|
if (lwsi_state(wsi) == LRS_SHUTDOWN &&
|
|
|
|
lws_is_ssl(wsi) && wsi->tls.ssl) {
|
2018-03-11 11:26:06 +08:00
|
|
|
switch (__lws_tls_shutdown(wsi)) {
|
2017-10-18 09:41:44 +08:00
|
|
|
case LWS_SSL_CAPABLE_DONE:
|
|
|
|
case LWS_SSL_CAPABLE_ERROR:
|
2017-04-06 19:37:14 +02:00
|
|
|
goto close_and_handled;
|
2017-09-29 11:27:58 +08:00
|
|
|
|
2017-10-18 09:41:44 +08:00
|
|
|
case LWS_SSL_CAPABLE_MORE_SERVICE_READ:
|
|
|
|
case LWS_SSL_CAPABLE_MORE_SERVICE_WRITE:
|
|
|
|
case LWS_SSL_CAPABLE_MORE_SERVICE:
|
2017-04-06 19:37:14 +02:00
|
|
|
goto handled;
|
|
|
|
}
|
|
|
|
}
|
2017-03-10 07:46:05 +08:00
|
|
|
#endif
|
2018-01-25 09:00:08 +08:00
|
|
|
wsi->could_have_pending = 0; /* clear back-to-back write detection */
|
2017-03-10 07:46:05 +08:00
|
|
|
|
2014-04-03 07:36:41 +08:00
|
|
|
/* okay, what we came here to do... */
|
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
/* if we got here, we should have wire protocol ops set on the wsi */
|
|
|
|
assert(wsi->role_ops);
|
2018-04-02 11:55:17 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
// lwsl_notice("%s: %s: wsistate 0x%x\n", __func__, wsi->role_ops->name,
|
|
|
|
// wsi->wsistate);
|
2017-10-24 11:59:44 +08:00
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
switch ((wsi->role_ops->handle_POLLIN)(pt, wsi, pollfd)) {
|
2018-04-17 15:35:15 +08:00
|
|
|
case LWS_HPI_RET_WSI_ALREADY_DIED:
|
2018-04-11 13:39:42 +08:00
|
|
|
return 1;
|
|
|
|
case LWS_HPI_RET_HANDLED:
|
|
|
|
break;
|
2018-04-17 15:35:15 +08:00
|
|
|
case LWS_HPI_RET_PLEASE_CLOSE_ME:
|
2018-04-11 13:39:42 +08:00
|
|
|
close_and_handled:
|
|
|
|
lwsl_debug("%p: Close and handled\n", wsi);
|
|
|
|
lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS,
|
|
|
|
"close_and_handled");
|
2018-04-30 09:16:04 +08:00
|
|
|
#if defined(_DEBUG) && defined(LWS_WITH_LIBUV)
|
2018-04-19 10:08:48 +08:00
|
|
|
/*
|
|
|
|
* confirm close has no problem being called again while
|
|
|
|
* it waits for libuv service to complete the first async
|
|
|
|
* close
|
|
|
|
*/
|
2018-04-30 09:16:04 +08:00
|
|
|
if (context->event_loop_ops == &event_loop_ops_uv)
|
2018-04-19 10:08:48 +08:00
|
|
|
lws_close_free_wsi(wsi, LWS_CLOSE_STATUS_NOSTATUS,
|
|
|
|
"close_and_handled uv repeat test");
|
|
|
|
#endif
|
2017-10-24 11:59:44 +08:00
|
|
|
/*
|
2018-04-11 13:39:42 +08:00
|
|
|
* pollfd may point to something else after the close
|
|
|
|
* due to pollfd swapping scheme on delete on some platforms
|
|
|
|
* we can't clear revents now because it'd be the wrong guy's
|
|
|
|
* revents
|
2016-03-20 11:59:53 +08:00
|
|
|
*/
|
2018-04-02 11:55:17 +08:00
|
|
|
return 1;
|
2018-04-11 13:39:42 +08:00
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
#if defined(LWS_WITH_TLS)
|
2014-04-03 07:36:41 +08:00
|
|
|
handled:
|
2018-04-11 13:39:42 +08:00
|
|
|
#endif
|
2014-04-03 07:36:41 +08:00
|
|
|
pollfd->revents = 0;
|
2018-04-11 13:39:42 +08:00
|
|
|
|
2018-11-14 20:04:14 +08:00
|
|
|
/* check the timeout situation if we didn't in the last second */
|
|
|
|
lws_service_periodic_checks(context, pollfd, tsi);
|
|
|
|
|
2018-05-02 18:35:58 +08:00
|
|
|
lws_pt_lock(pt, __func__);
|
|
|
|
__lws_hrtimer_service(pt);
|
|
|
|
lws_pt_unlock(pt);
|
|
|
|
|
2018-04-11 13:39:42 +08:00
|
|
|
return 0;
|
2014-04-03 07:36:41 +08:00
|
|
|
}
|
|
|
|
|
2016-01-19 03:34:24 +08:00
|
|
|
LWS_VISIBLE int
|
|
|
|
lws_service_fd(struct lws_context *context, struct lws_pollfd *pollfd)
|
|
|
|
{
|
|
|
|
return lws_service_fd_tsi(context, pollfd, 0);
|
|
|
|
}
|
|
|
|
|
2014-04-03 07:36:41 +08:00
|
|
|
LWS_VISIBLE int
|
2015-12-04 11:08:32 +08:00
|
|
|
lws_service(struct lws_context *context, int timeout_ms)
|
2014-04-03 07:36:41 +08:00
|
|
|
{
|
2018-05-02 19:27:29 +08:00
|
|
|
struct lws_context_per_thread *pt = &context->pt[0];
|
|
|
|
int n;
|
|
|
|
|
|
|
|
if (!context)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
pt->inside_service = 1;
|
|
|
|
|
2018-04-29 10:44:36 +08:00
|
|
|
if (context->event_loop_ops->run_pt) {
|
|
|
|
/* we are configured for an event loop */
|
|
|
|
context->event_loop_ops->run_pt(context, 0);
|
|
|
|
|
2018-05-02 19:27:29 +08:00
|
|
|
pt->inside_service = 0;
|
|
|
|
|
2018-04-29 10:44:36 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2018-05-02 19:27:29 +08:00
|
|
|
n = lws_plat_service(context, timeout_ms);
|
|
|
|
|
|
|
|
pt->inside_service = 0;
|
|
|
|
|
|
|
|
return n;
|
2014-04-03 07:36:41 +08:00
|
|
|
}
|
|
|
|
|
2016-01-19 03:34:24 +08:00
|
|
|
LWS_VISIBLE int
|
|
|
|
lws_service_tsi(struct lws_context *context, int timeout_ms, int tsi)
|
|
|
|
{
|
2018-05-02 19:27:29 +08:00
|
|
|
struct lws_context_per_thread *pt = &context->pt[tsi];
|
|
|
|
int n;
|
|
|
|
|
|
|
|
pt->inside_service = 1;
|
2018-11-15 16:33:54 +08:00
|
|
|
#if LWS_MAX_SMP > 1
|
|
|
|
pt->self = pthread_self();
|
|
|
|
#endif
|
2018-05-02 19:27:29 +08:00
|
|
|
|
2018-04-29 10:44:36 +08:00
|
|
|
if (context->event_loop_ops->run_pt) {
|
|
|
|
/* we are configured for an event loop */
|
|
|
|
context->event_loop_ops->run_pt(context, tsi);
|
|
|
|
|
2018-05-02 19:27:29 +08:00
|
|
|
pt->inside_service = 0;
|
|
|
|
|
2018-04-29 10:44:36 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-05-02 19:27:29 +08:00
|
|
|
n = _lws_plat_service_tsi(context, timeout_ms, tsi);
|
|
|
|
|
|
|
|
pt->inside_service = 0;
|
|
|
|
|
|
|
|
return n;
|
2016-01-19 03:34:24 +08:00
|
|
|
}
|