timeout settable from info
This adds an info member that allows the user code to set the library's network action timeout in seconds. If left at the default 0, the build-time default AWAITING_TIMEOUT continues to be used. As suggested https://github.com/warmcat/libwebsockets/issues/427 Signed-off-by: Andy Green <andy.green@linaro.org>
This commit is contained in:
parent
eb91ad0964
commit
200a6a296e
10 changed files with 25 additions and 12 deletions
|
@ -48,7 +48,7 @@ to user code.
|
|||
User api additions
|
||||
------------------
|
||||
|
||||
1) The info struct gained two new members
|
||||
1) The info struct gained three new members
|
||||
|
||||
- max_http_header_data: 0 for default (1024) or set the maximum amount of known
|
||||
http header payload that lws can deal with. Payload in unknown http
|
||||
|
@ -64,6 +64,9 @@ User api additions
|
|||
additional connects will fail until some of the pending connections timeout
|
||||
or complete.
|
||||
|
||||
- timeout_secs: 0 for default (currently 20s), or set the library's
|
||||
network activity timeout to the given number of seconds
|
||||
|
||||
HTTP header processing in lws only exists until just after the first main
|
||||
callback after the HTTP handshake... for ws connections that is ESTABLISHED and
|
||||
for HTTP connections the HTTP callback.
|
||||
|
|
|
@ -353,7 +353,7 @@ some_wait:
|
|||
|
||||
wsi->mode = LWSCM_WSCL_ISSUE_HANDSHAKE2;
|
||||
lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_CLIENT_HS_SEND,
|
||||
AWAITING_TIMEOUT);
|
||||
context->timeout_secs);
|
||||
|
||||
/* fallthru */
|
||||
|
||||
|
@ -386,7 +386,7 @@ some_wait:
|
|||
wsi->u.hdr.lextable_pos = 0;
|
||||
wsi->mode = LWSCM_WSCL_WAITING_SERVER_REPLY;
|
||||
lws_set_timeout(wsi, PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE,
|
||||
AWAITING_TIMEOUT);
|
||||
context->timeout_secs);
|
||||
break;
|
||||
|
||||
case LWSCM_WSCL_WAITING_SERVER_REPLY:
|
||||
|
|
|
@ -97,7 +97,6 @@ lws_create_context(struct lws_context_creation_info *info)
|
|||
lwsl_info(" LWS_MAX_PROTOCOLS : %u\n", LWS_MAX_PROTOCOLS);
|
||||
lwsl_info(" LWS_MAX_SMP : %u\n", LWS_MAX_SMP);
|
||||
lwsl_info(" SPEC_LATEST_SUPPORTED : %u\n", SPEC_LATEST_SUPPORTED);
|
||||
lwsl_info(" AWAITING_TIMEOUT : %u\n", AWAITING_TIMEOUT);
|
||||
lwsl_info(" sizeof (*info) : %u\n", sizeof(*info));
|
||||
#if LWS_POSIX
|
||||
lwsl_info(" SYSTEM_RANDOM_FILEPATH: '%s'\n", SYSTEM_RANDOM_FILEPATH);
|
||||
|
@ -136,6 +135,12 @@ lws_create_context(struct lws_context_creation_info *info)
|
|||
context->ka_time = info->ka_time;
|
||||
context->ka_interval = info->ka_interval;
|
||||
context->ka_probes = info->ka_probes;
|
||||
if (info->timeout_secs)
|
||||
context->timeout_secs = info->timeout_secs;
|
||||
else
|
||||
context->timeout_secs = AWAITING_TIMEOUT;
|
||||
|
||||
lwsl_info(" default timeout (secs): %u\n", context->timeout_secs);
|
||||
|
||||
if (info->max_http_header_data)
|
||||
context->max_http_header_data = info->max_http_header_data;
|
||||
|
|
|
@ -167,7 +167,7 @@ http_postbody:
|
|||
|
||||
if (wsi->u.http.content_remain) {
|
||||
lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_CONTENT,
|
||||
AWAITING_TIMEOUT);
|
||||
wsi->context->timeout_secs);
|
||||
break;
|
||||
}
|
||||
/* he sent all the content in time */
|
||||
|
|
|
@ -302,7 +302,7 @@ just_kill_connection:
|
|||
wsi->state = LWSS_SHUTDOWN;
|
||||
lws_change_pollfd(wsi, LWS_POLLOUT, LWS_POLLIN);
|
||||
lws_set_timeout(wsi, PENDING_TIMEOUT_SHUTDOWN_FLUSH,
|
||||
AWAITING_TIMEOUT);
|
||||
context->timeout_secs);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1315,7 +1315,10 @@ extern int lws_extension_callback_pm_deflate(
|
|||
* @fd_limit_per_thread: nonzero means restrict each service thread to this
|
||||
* many fds, 0 means the default which is divide the process fd
|
||||
* limit by the number of threads.
|
||||
*
|
||||
* @timeout_secs: various processes involving network roundtrips in the
|
||||
* library are protected from hanging forever by timeouts. If
|
||||
* nonzero, this member lets you set the timeout used in seconds.
|
||||
* Otherwise a default timeout is used.
|
||||
*/
|
||||
|
||||
struct lws_context_creation_info {
|
||||
|
@ -1349,6 +1352,7 @@ struct lws_context_creation_info {
|
|||
|
||||
unsigned int count_threads;
|
||||
unsigned int fd_limit_per_thread;
|
||||
unsigned int timeout_secs;
|
||||
|
||||
/* Add new things just above here ---^
|
||||
* This is part of the ABI, don't needlessly break compatibility
|
||||
|
|
|
@ -575,7 +575,7 @@ LWS_VISIBLE int lws_serve_http_file_fragment(struct lws *wsi)
|
|||
n = (int)amount;
|
||||
if (n) {
|
||||
lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_CONTENT,
|
||||
AWAITING_TIMEOUT);
|
||||
context->timeout_secs);
|
||||
wsi->u.http.filepos += n;
|
||||
m = lws_write(wsi, pt->serv_buf, n,
|
||||
wsi->u.http.filepos == wsi->u.http.filelen ?
|
||||
|
|
|
@ -632,6 +632,7 @@ struct lws_context {
|
|||
unsigned int http_proxy_port;
|
||||
unsigned int options;
|
||||
unsigned int fd_limit_per_thread;
|
||||
unsigned int timeout_secs;
|
||||
|
||||
/*
|
||||
* set to the Thread ID that's doing the service loop just before entry
|
||||
|
|
|
@ -302,7 +302,7 @@ lws_http_action(struct lws *wsi)
|
|||
* put a timeout on it having arrived
|
||||
*/
|
||||
lws_set_timeout(wsi, PENDING_TIMEOUT_HTTP_CONTENT,
|
||||
AWAITING_TIMEOUT);
|
||||
wsi->context->timeout_secs);
|
||||
|
||||
n = wsi->protocol->callback(wsi, LWS_CALLBACK_HTTP,
|
||||
wsi->user_space, uri_ptr, uri_len);
|
||||
|
@ -780,7 +780,7 @@ lws_adopt_socket(struct lws_context *context, lws_sockfd_type accept_fd)
|
|||
|
||||
/* the transport is accepted... give him time to negotiate */
|
||||
lws_set_timeout(new_wsi, PENDING_TIMEOUT_ESTABLISH_WITH_SERVER,
|
||||
AWAITING_TIMEOUT);
|
||||
context->timeout_secs);
|
||||
|
||||
#if LWS_POSIX == 0
|
||||
mbed3_tcp_stream_accept(accept_fd, new_wsi);
|
||||
|
|
|
@ -653,7 +653,7 @@ lws_server_socket_service_ssl(struct lws *wsi, lws_sockfd_type accept_fd)
|
|||
goto fail;
|
||||
|
||||
lws_set_timeout(wsi, PENDING_TIMEOUT_SSL_ACCEPT,
|
||||
AWAITING_TIMEOUT);
|
||||
context->timeout_secs);
|
||||
|
||||
lwsl_info("inserted SSL accept into fds, trying SSL_accept\n");
|
||||
|
||||
|
@ -746,7 +746,7 @@ go_again:
|
|||
accepted:
|
||||
/* OK, we are accepted... give him some time to negotiate */
|
||||
lws_set_timeout(wsi, PENDING_TIMEOUT_ESTABLISH_WITH_SERVER,
|
||||
AWAITING_TIMEOUT);
|
||||
context->timeout_secs);
|
||||
|
||||
wsi->mode = LWSCM_HTTP_SERVING;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue