{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'},
{"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'},
{"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
" -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
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;