From f70f2b66b94568fba6ed1cec9589c166e7dfb8a9 Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Thu, 10 Sep 2015 08:00:12 +0000 Subject: [PATCH] Return a "stopcase" (string) as part of the result object. --- exec/load/termcapture_lib.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/exec/load/termcapture_lib.js b/exec/load/termcapture_lib.js index ac1e201336..ac8acd8ee0 100644 --- a/exec/load/termcapture_lib.js +++ b/exec/load/termcapture_lib.js @@ -52,15 +52,26 @@ function capture() var lines=[]; var curline=""; var hello=[]; + var stopcause="Disconnected"; var start=time(); - while(socket.is_connected && lines.length < this.max_lines && hello.length < this.max_lines && time()-start < timeout) { + while(socket.is_connected) { if(js.terminated) { error = "Terminated locally"; return false; } - if(!socket.poll(timeout)) + if(lines.length >= this.max_lines) { + stopcause = "Max lines reached:" + this.max_lines; break; + } + if(time()-start >= timeout) { + stopcause = "Capture timeout reached: " + timeout + " seconds"; + break; + } + if(!socket.poll(timeout)) { + stopcause = "Poll timeout reached: " + timeout + " seconds"; + break; + } var byte = socket.recvBin(1); var char = ascii(byte); if(protocol=="telnet" && byte == telnet.IAC) { @@ -114,6 +125,7 @@ function capture() } if(curline.length >= this.max_line_length) { log(LOG_DEBUG,"Stopping capture on line length of " + curline.length); + stopcause = "Max line length reached:" + this.max_line_length + " bytes"; break; } lastbyte=byte; @@ -130,7 +142,7 @@ function capture() i++; } - return { preview: lines, hello: hello, ip_address: socket.remote_ip_address }; + return { preview: lines, hello: hello, ip_address: socket.remote_ip_address, stopcause: stopcause }; } /* Leave as last line for convenient load() usage: */ -- GitLab