mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
client: allow setting keep warm time
Until now if the generic transaction completes and the connection is idle, there's a fixed 5s grace period to keep the connection up in case something else wants it. This allows setting it in the client creation info struct .keep_warm_secs. If left at 0, then it maintains the backward-compatible 5s wait.
This commit is contained in:
parent
641831b3c5
commit
43b83c333b
4 changed files with 16 additions and 3 deletions
|
@ -163,6 +163,12 @@ struct lws_client_connect_info {
|
|||
void *mqtt_cp;
|
||||
#endif
|
||||
|
||||
uint16_t keep_warm_secs;
|
||||
/**< 0 means 5s. If the client connection to the endpoint becomes idle,
|
||||
* defer closing it for this many seconds in case another outgoing
|
||||
* connection to the same endpoint turns up.
|
||||
*/
|
||||
|
||||
/* Add new things just above here ---^
|
||||
* This is part of the ABI, don't needlessly break compatibility
|
||||
*
|
||||
|
|
|
@ -58,7 +58,10 @@ lws_client_connect_via_info(const struct lws_client_connect_info *i)
|
|||
if (wsi == NULL)
|
||||
goto bail;
|
||||
|
||||
|
||||
if (i->keep_warm_secs)
|
||||
wsi->keep_warm_secs = i->keep_warm_secs;
|
||||
else
|
||||
wsi->keep_warm_secs = 5;
|
||||
|
||||
wsi->context = i->context;
|
||||
wsi->desc.sockfd = LWS_SOCK_INVALID;
|
||||
|
|
|
@ -830,6 +830,9 @@ struct lws {
|
|||
|
||||
uint16_t ocport, c_port;
|
||||
uint16_t retry;
|
||||
#if defined(LWS_WITH_CLIENT)
|
||||
uint16_t keep_warm_secs;
|
||||
#endif
|
||||
|
||||
/* chars */
|
||||
|
||||
|
|
|
@ -798,7 +798,8 @@ _lws_generic_transaction_completed_active_conn(struct lws **_wsi, char take_vh_l
|
|||
lwsl_info("%s: nothing pipelined waiting\n", __func__);
|
||||
lwsi_set_state(wsi, LRS_IDLING);
|
||||
|
||||
lws_set_timeout(wsi, PENDING_TIMEOUT_CLIENT_CONN_IDLE, 5);
|
||||
lws_set_timeout(wsi, PENDING_TIMEOUT_CLIENT_CONN_IDLE,
|
||||
wsi->keep_warm_secs);
|
||||
|
||||
return 0; /* no new transaction right now */
|
||||
}
|
||||
|
@ -873,7 +874,7 @@ _lws_generic_transaction_completed_active_conn(struct lws **_wsi, char take_vh_l
|
|||
|
||||
wnew->cli_hostname_copy = wsi->cli_hostname_copy;
|
||||
wsi->cli_hostname_copy = NULL;
|
||||
|
||||
wnew->keep_warm_secs = wsi->keep_warm_secs;
|
||||
|
||||
/*
|
||||
* selected queued guy now replaces the original leader on the
|
||||
|
|
Loading…
Add table
Reference in a new issue