From 0fc275f3a3251f1839a2e59d04011f6a4e41541c Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Fri, 5 Jul 2019 23:05:09 +0800 Subject: [PATCH] server: remove the reconnect option (enabled by default) --- README.md | 1 - html/src/components/terminal/index.tsx | 19 ++++--------------- man/ttyd.1 | 4 ---- man/ttyd.man.md | 3 --- src/index.html | 2 +- src/protocol.c | 4 ---- src/server.c | 15 +-------------- src/server.h | 2 -- 8 files changed, 6 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index f995462..e60b37b 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,6 @@ OPTIONS: -u, --uid User id to run with -g, --gid Group id to run with -s, --signal Signal to send to the command when exit it (default: 1, SIGHUP) - -r, --reconnect Time to reconnect for the client in seconds (default: 10) -a, --url-arg Allow client to send command line arguments in URL (eg: http://localhost:7681?arg=foo&arg=bar) -R, --readonly Do not allow clients to write to the TTY -t, --client-option Send option to client (format: key=value), repeat to add more options diff --git a/html/src/components/terminal/index.tsx b/html/src/components/terminal/index.tsx index 909f740..b1e662e 100644 --- a/html/src/components/terminal/index.tsx +++ b/html/src/components/terminal/index.tsx @@ -21,7 +21,6 @@ const enum Command { OUTPUT = '0', SET_WINDOW_TITLE = '1', SET_PREFERENCES = '2', - SET_RECONNECT = '3', // client side INPUT = '0', @@ -44,7 +43,6 @@ export class Xterm extends Component { private zmodemAddon: ZmodemAddon; private socket: WebSocket; private title: string; - private reconnect: number; private resizeTimeout: number; private backoff: backoff.Backoff; @@ -124,7 +122,6 @@ export class Xterm extends Component { socket.onopen = this.onSocketOpen; socket.onmessage = this.onSocketData; socket.onclose = this.onSocketClose; - socket.onerror = this.onSocketError; terminal.loadAddon(fitAddon); terminal.loadAddon(overlayAddon); @@ -166,7 +163,7 @@ export class Xterm extends Component { private onSocketClose(event: CloseEvent) { console.log(`[ttyd] websocket connection closed with code: ${event.code}`); - const { overlayAddon, openTerminal, reconnect } = this; + const { overlayAddon } = this; overlayAddon.showOverlay('Connection Closed', null); window.removeEventListener('beforeunload', this.onWindowUnload); @@ -174,17 +171,13 @@ export class Xterm extends Component { if (event.code === 1008) { window.location.reload(); } + // 1000: CLOSE_NORMAL - if (event.code !== 1000 && reconnect > 0) { - setTimeout(openTerminal, reconnect * 1000); + if (event.code !== 1000) { + this.backoff.backoff(); } } - @bind - private onSocketError() { - this.backoff.backoff(); - } - @bind private onSocketData(event: MessageEvent) { const { terminal, textDecoder, zmodemAddon } = this; @@ -207,10 +200,6 @@ export class Xterm extends Component { terminal.setOption(key, preferences[key]); }); break; - case Command.SET_RECONNECT: - this.reconnect = Number(textDecoder.decode(data)); - console.log(`[ttyd] enabling reconnect: ${this.reconnect} seconds`); - break; default: console.warn(`[ttyd] unknown command: ${cmd}`); break; diff --git a/man/ttyd.1 b/man/ttyd.1 index be484ff..9157166 100644 --- a/man/ttyd.1 +++ b/man/ttyd.1 @@ -54,10 +54,6 @@ Cross platform: macOS, Linux, FreeBSD/OpenBSD, OpenWrt/LEDE, Windows \-s, \-\-signal Signal to send to the command when exit it (default: 1, SIGHUP) -.PP -\-r, \-\-reconnect - Time to reconnect for the client in seconds (default: 10) - .PP \-a, \-\-url\-arg Allow client to send command line arguments in URL (eg: diff --git a/man/ttyd.man.md b/man/ttyd.man.md index 4169239..2ea3311 100644 --- a/man/ttyd.man.md +++ b/man/ttyd.man.md @@ -37,9 +37,6 @@ ttyd 1 "September 2016" ttyd "User Manual" -s, --signal Signal to send to the command when exit it (default: 1, SIGHUP) - -r, --reconnect - Time to reconnect for the client in seconds (default: 10) - -a, --url-arg Allow client to send command line arguments in URL (eg: http://localhost:7681?arg=foo&arg=bar) diff --git a/src/index.html b/src/index.html index 6e414ba..d84f125 100644 --- a/src/index.html +++ b/src/index.html @@ -1 +1 @@ -ttyd - Terminal \ No newline at end of file +ttyd - Terminal \ No newline at end of file diff --git a/src/protocol.c b/src/protocol.c index ac6bb04..ebdb3e4 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -28,7 +28,6 @@ // initial message list char initial_cmds[] = { SET_WINDOW_TITLE, - SET_RECONNECT, SET_PREFERENCES }; @@ -45,9 +44,6 @@ send_initial_message(struct lws *wsi, int index) { gethostname(buffer, sizeof(buffer) - 1); n = sprintf((char *) p, "%c%s (%s)", cmd, server->command, buffer); break; - case SET_RECONNECT: - n = sprintf((char *) p, "%c%d", cmd, server->reconnect); - break; case SET_PREFERENCES: n = sprintf((char *) p, "%c%s", cmd, server->prefs_json); break; diff --git a/src/server.c b/src/server.c index c125c0c..260fb2a 100644 --- a/src/server.c +++ b/src/server.c @@ -44,7 +44,6 @@ static const struct option options[] = { {"uid", required_argument, NULL, 'u'}, {"gid", required_argument, NULL, 'g'}, {"signal", required_argument, NULL, 's'}, - {"reconnect", required_argument, NULL, 'r'}, {"index", required_argument, NULL, 'I'}, {"ipv6", no_argument, NULL, '6'}, {"ssl", no_argument, NULL, 'S'}, @@ -62,7 +61,7 @@ static const struct option options[] = { {"help", no_argument, NULL, 'h'}, {NULL, 0, 0, 0} }; -static const char *opt_string = "p:i:c:u:g:s:r:I:6aSC:K:A:Rt:T:Om:oBd:vh"; +static const char *opt_string = "p:i:c:u:g:s:I:6aSC:K:A:Rt:T:Om:oBd:vh"; void print_help() { fprintf(stderr, "ttyd is a tool for sharing terminal over the web\n\n" @@ -77,7 +76,6 @@ void print_help() { " -u, --uid User id to run with\n" " -g, --gid Group id to run with\n" " -s, --signal Signal to send to the command when exit it (default: 1, SIGHUP)\n" - " -r, --reconnect Time to reconnect for the client in seconds (default: 10)\n" " -a, --url-arg Allow client to send command line arguments in URL (eg: http://localhost:7681?arg=foo&arg=bar)\n" " -R, --readonly Do not allow clients to write to the TTY\n" " -t, --client-option Send option to client (format: key=value), repeat to add more options\n" @@ -110,7 +108,6 @@ tty_server_new(int argc, char **argv, int start) { memset(ts, 0, sizeof(struct tty_server)); LIST_INIT(&ts->clients); ts->client_count = 0; - ts->reconnect = 10; ts->sig_code = SIGHUP; sprintf(ts->terminal_type, "%s", "xterm-256color"); get_sig_name(ts->sig_code, ts->sig_name, sizeof(ts->sig_name)); @@ -329,13 +326,6 @@ main(int argc, char **argv) { } } break; - case 'r': - server->reconnect = atoi(optarg); - if (server->reconnect < 0) { - fprintf(stderr, "ttyd: invalid reconnect: %s\n", optarg); - return -1; - } - break; case 'I': if (!strncmp(optarg, "~/", 2)) { const char* home = getenv("HOME"); @@ -448,9 +438,6 @@ main(int argc, char **argv) { lwsl_notice(" start command: %s\n", server->command); lwsl_notice(" close signal: %s (%d)\n", server->sig_name, server->sig_code); lwsl_notice(" terminal type: %s\n", server->terminal_type); - if (server->reconnect > 0) { - lwsl_notice(" reconnect timeout: %ds\n", server->reconnect); - } if (server->check_origin) lwsl_notice(" check origin: true\n"); if (server->url_arg) diff --git a/src/server.h b/src/server.h index b605875..3a0ad9a 100644 --- a/src/server.h +++ b/src/server.h @@ -11,7 +11,6 @@ #define OUTPUT '0' #define SET_WINDOW_TITLE '1' #define SET_PREFERENCES '2' -#define SET_RECONNECT '3' // websocket url path #define WS_PATH "/ws" @@ -65,7 +64,6 @@ struct tty_server { int client_count; // client count char *prefs_json; // client preferences char *credential; // encoded basic auth credential - int reconnect; // reconnect timeout char *index; // custom index.html char *command; // full command line char **argv; // command with arguments -- 2.43.4