mirror of
https://github.com/tsl0922/ttyd.git
synced 2025-12-25 21:14:21 +01:00
add websocket ping interval option (#519)
This commit is contained in:
35
src/server.c
35
src/server.c
@@ -42,6 +42,18 @@ static const struct lws_extension extensions[] = {
|
||||
{NULL, NULL, NULL}};
|
||||
#endif
|
||||
|
||||
#if LWS_LIBRARY_VERSION_NUMBER >= 4000000
|
||||
static const uint32_t backoff_ms[] = { 1000, 2000, 3000, 4000, 5000 };
|
||||
static lws_retry_bo_t retry = {
|
||||
.retry_ms_table = backoff_ms,
|
||||
.retry_ms_table_count = LWS_ARRAY_SIZE(backoff_ms),
|
||||
.conceal_count = LWS_ARRAY_SIZE(backoff_ms),
|
||||
.secs_since_valid_ping = 300,
|
||||
.secs_since_valid_hangup = 300 + 7,
|
||||
.jitter_percent = 0,
|
||||
};
|
||||
#endif
|
||||
|
||||
// command line options
|
||||
static const struct option options[] = {
|
||||
{"port", required_argument, NULL, 'p'},
|
||||
@@ -52,6 +64,9 @@ static const struct option options[] = {
|
||||
{"signal", required_argument, NULL, 's'},
|
||||
{"index", required_argument, NULL, 'I'},
|
||||
{"base-path", required_argument, NULL, 'b'},
|
||||
#if LWS_LIBRARY_VERSION_NUMBER >= 4000000
|
||||
{"ping-interval", required_argument, NULL, 'P'},
|
||||
#endif
|
||||
{"ipv6", no_argument, NULL, '6'},
|
||||
{"ssl", no_argument, NULL, 'S'},
|
||||
{"ssl-cert", required_argument, NULL, 'C'},
|
||||
@@ -69,7 +84,13 @@ static const struct option options[] = {
|
||||
{"version", no_argument, NULL, 'v'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{NULL, 0, 0, 0}};
|
||||
|
||||
#if LWS_LIBRARY_VERSION_NUMBER < 4000000
|
||||
static const char *opt_string = "p:i:c:u:g:s:I:b:6aSC:K:A:Rt:T:Om:oBd:vh";
|
||||
#endif
|
||||
#if LWS_LIBRARY_VERSION_NUMBER >= 4000000
|
||||
static const char *opt_string = "p:i:c:u:g:s:I:b:P:6aSC:K:A:Rt:T:Om:oBd:vh";
|
||||
#endif
|
||||
|
||||
static void print_help() {
|
||||
// clang-format off
|
||||
@@ -95,6 +116,9 @@ static void print_help() {
|
||||
" -B, --browser Open terminal with the default system browser\n"
|
||||
" -I, --index Custom index.html path\n"
|
||||
" -b, --base-path Expected base path for requests coming from a reverse proxy (eg: /mounted/here)\n"
|
||||
#if LWS_LIBRARY_VERSION_NUMBER >= 4000000
|
||||
" -P, --ping-interval Websocket ping interval(sec) (default: 300)\n"
|
||||
#endif
|
||||
#ifdef LWS_WITH_IPV6
|
||||
" -6, --ipv6 Enable IPv6 support\n"
|
||||
#endif
|
||||
@@ -380,6 +404,17 @@ int main(int argc, char **argv) {
|
||||
sc(ws) sc(index) sc(token) sc(parent)
|
||||
#undef sc
|
||||
} break;
|
||||
#if LWS_LIBRARY_VERSION_NUMBER >= 4000000
|
||||
case 'P':
|
||||
if (atoi(optarg) <= 0) {
|
||||
fprintf(stderr, "ttyd: invalid ping interval: %s\n", optarg);
|
||||
return -1;
|
||||
}
|
||||
retry.secs_since_valid_ping = atoi(optarg);
|
||||
retry.secs_since_valid_hangup = atoi(optarg) + 7;
|
||||
info.retry_and_idle_policy = &retry;
|
||||
break;
|
||||
#endif
|
||||
case '6':
|
||||
info.options &= ~(LWS_SERVER_OPTION_DISABLE_IPV6);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user