From: Shuanglei Tao Date: Sat, 20 May 2017 10:55:48 +0000 (+0800) Subject: Do not reconnect if process exited, fixes #50 X-Git-Url: http://git.prime8.dev/?a=commitdiff_plain;h=4e0801db8ef43d7e949df45f7343e71771dfb3f5;p=ttyd.git Do not reconnect if process exited, fixes #50 --- diff --git a/html/js/app.js b/html/js/app.js index f284d12..2b5a0fb 100644 --- a/html/js/app.js +++ b/html/js/app.js @@ -93,7 +93,8 @@ } window.removeEventListener('beforeunload', unloadCallback); clearInterval(pingTimer); - if (autoReconnect > 0) { + // 1000: CLOSE_NORMAL + if (event.code !== 1000 && autoReconnect > 0) { setTimeout(openWs, autoReconnect * 1000); } }; diff --git a/src/index.html b/src/index.html index e2ec8b2..26930a7 100644 --- a/src/index.html +++ b/src/index.html @@ -17,6 +17,6 @@ e||this.emit("scroll",this.ydisp),this.refresh(0,this.rows-1)},s.prototype.scrol
- + diff --git a/src/protocol.c b/src/protocol.c index 35128e7..237d1d2 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -227,6 +227,7 @@ callback_tty(struct lws *wsi, enum lws_callback_reasons reason, if (!client->initialized) { if (send_initial_message(wsi) < 0) { tty_client_remove(client); + lws_close_reason(wsi, LWS_CLOSE_STATUS_UNEXPECTED_CONDITION, NULL, 0); return -1; } client->initialized = true; @@ -241,6 +242,9 @@ callback_tty(struct lws *wsi, enum lws_callback_reasons reason, STAILQ_REMOVE_HEAD(&client->queue, list); free(frame); tty_client_remove(client); + lws_close_reason(wsi, + frame->len == 0 ? LWS_CLOSE_STATUS_NORMAL : LWS_CLOSE_STATUS_UNEXPECTED_CONDITION, + NULL, 0); return -1; } @@ -303,6 +307,7 @@ callback_tty(struct lws *wsi, enum lws_callback_reasons reason, if (write(client->pty, client->buffer + 1, client->len - 1) < client->len - 1) { lwsl_err("write INPUT to pty\n"); tty_client_remove(client); + lws_close_reason(wsi, LWS_CLOSE_STATUS_UNEXPECTED_CONDITION, NULL, 0); return -1; } break; @@ -312,6 +317,7 @@ callback_tty(struct lws *wsi, enum lws_callback_reasons reason, if (lws_write(wsi, &c, 1, LWS_WRITE_TEXT) != 1) { lwsl_err("send PONG\n"); tty_client_remove(client); + lws_close_reason(wsi, LWS_CLOSE_STATUS_UNEXPECTED_CONDITION, NULL, 0); return -1; } } @@ -338,6 +344,7 @@ callback_tty(struct lws *wsi, enum lws_callback_reasons reason, } if (!client->authenticated) { tty_client_remove(client); + lws_close_reason(wsi, LWS_CLOSE_STATUS_POLICY_VIOLATION, NULL, 0); return -1; } } @@ -349,7 +356,8 @@ callback_tty(struct lws *wsi, enum lws_callback_reasons reason, break; default: lwsl_warn("unknown message type: %c\n", command); - break; + lws_close_reason(wsi, LWS_CLOSE_STATUS_INVALID_PAYLOAD, NULL, 0); + return -1; } if (client->buffer != NULL) {