mirror of
https://github.com/tsl0922/ttyd.git
synced 2025-12-25 21:14:21 +01:00
server: add --exit-no-conn option (#1029)
Co-authored-by: Shuanglei Tao <tsl0922@gmail.com>
This commit is contained in:
@@ -379,8 +379,8 @@ int callback_tty(struct lws *wsi, enum lws_callback_reasons reason, void *user,
|
||||
}
|
||||
}
|
||||
|
||||
if (server->once && server->client_count == 0) {
|
||||
lwsl_notice("exiting due to the --once option.\n");
|
||||
if ((server->once || server->exit_no_conn) && server->client_count == 0) {
|
||||
lwsl_notice("exiting due to the --once/--exit-no-conn option.\n");
|
||||
force_exit = true;
|
||||
lws_cancel_service(context);
|
||||
exit(0);
|
||||
|
||||
@@ -77,12 +77,13 @@ static const struct option options[] = {{"port", required_argument, NULL, 'p'},
|
||||
{"check-origin", no_argument, NULL, 'O'},
|
||||
{"max-clients", required_argument, NULL, 'm'},
|
||||
{"once", no_argument, NULL, 'o'},
|
||||
{"exit-no-conn", no_argument, NULL, 'q'},
|
||||
{"browser", no_argument, NULL, 'B'},
|
||||
{"debug", required_argument, NULL, 'd'},
|
||||
{"version", no_argument, NULL, 'v'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{NULL, 0, 0, 0}};
|
||||
static const char *opt_string = "p:i:U:c:H:u:g:s:w:I:b:P:6aSC:K:A:Wt:T:Om:oBd:vh";
|
||||
static const char *opt_string = "p:i:U:c:H:u:g:s:w:I:b:P:6aSC:K:A:Wt:T:Om:oqBd:vh";
|
||||
|
||||
static void print_help() {
|
||||
// clang-format off
|
||||
@@ -108,6 +109,7 @@ static void print_help() {
|
||||
" -O, --check-origin Do not allow websocket connection from different origin\n"
|
||||
" -m, --max-clients Maximum clients to support (default: 0, no limit)\n"
|
||||
" -o, --once Accept only one client and exit on disconnection\n"
|
||||
" -q, --exit-no-conn Exit on all clients disconnection\n"
|
||||
" -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, max length: 128)\n"
|
||||
@@ -150,6 +152,7 @@ static void print_config() {
|
||||
if (server->url_arg) lwsl_notice(" allow url arg: true\n");
|
||||
if (server->max_clients > 0) lwsl_notice(" max clients: %d\n", server->max_clients);
|
||||
if (server->once) lwsl_notice(" once: true\n");
|
||||
if (server->exit_no_conn) lwsl_notice(" exit_no_conn: true\n");
|
||||
if (server->index != NULL) lwsl_notice(" custom index.html: %s\n", server->index);
|
||||
if (server->cwd != NULL) lwsl_notice(" working directory: %s\n", server->cwd);
|
||||
if (!server->writable) lwsl_notice("The --writable option is not set, will start in readonly mode");
|
||||
@@ -367,6 +370,9 @@ int main(int argc, char **argv) {
|
||||
case 'o':
|
||||
server->once = true;
|
||||
break;
|
||||
case 'q':
|
||||
server->exit_no_conn = true;
|
||||
break;
|
||||
case 'B':
|
||||
browser = true;
|
||||
break;
|
||||
|
||||
@@ -59,7 +59,7 @@ struct pss_tty {
|
||||
typedef struct {
|
||||
struct pss_tty *pss;
|
||||
bool ws_closed;
|
||||
} pty_ctx_t ;
|
||||
} pty_ctx_t;
|
||||
|
||||
struct server {
|
||||
int client_count; // client count
|
||||
@@ -78,6 +78,7 @@ struct server {
|
||||
bool check_origin; // whether allow websocket connection from different origin
|
||||
int max_clients; // maximum clients to support
|
||||
bool once; // whether accept only one client and exit on disconnection
|
||||
bool exit_no_conn; // whether exit on all clients disconnection
|
||||
char socket_path[255]; // UNIX domain socket path
|
||||
char terminal_type[30]; // terminal type to report
|
||||
|
||||
|
||||
Reference in New Issue
Block a user