From a44220560ba543a3425782347629897cef1466eb Mon Sep 17 00:00:00 2001 From: deuce <> Date: Thu, 15 Mar 2018 22:39:04 +0000 Subject: [PATCH] Add a new send_chunks() method which will deal with short send() calls. We can't rely on our send buffers being infinite anymore. --- exec/load/binkp.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/exec/load/binkp.js b/exec/load/binkp.js index 06a2757ee8..b8f320f7a0 100644 --- a/exec/load/binkp.js +++ b/exec/load/binkp.js @@ -230,6 +230,19 @@ BinkP.prototype.crypt = { return ret; }, }; +BinkP.prototype.send_chunks = function(str) { + var ret; + var sent = 0; + + while (sent < str.length) { + ret = this.sock.send(str.substr(sent)); + if (ret >= 0) + sent += ret; + else + return false; + } + return true; +}; BinkP.prototype.send_buf = function(str) { if (this.out_keys === undefined) return str; @@ -880,7 +893,7 @@ BinkP.prototype.sendCmd = function(cmd, data) len |= 0x8000; // We'll send it all in one go to avoid sending small packets... var sstr = this.send_buf(ascii((len & 0xff00)>>8) + ascii(len & 0xff) + ascii(cmd) + data); - if (this.sock.send(sstr) !== sstr.length) + if (!this.send_chunks(sstr)) return false; switch(cmd) { case this.command.M_EOB: @@ -913,7 +926,7 @@ BinkP.prototype.sendData = function(data) log(LOG_DEBUG, "Sending "+data.length+" bytes of data"); // We'll send it all in one go to avoid sending small packets... var sstr = this.send_buf(ascii((len & 0xff00)>>8) + ascii(len & 0xff) + data); - if (!this.sock.send(sstr) != sstr.length) + if (!this.send_chunks(sstr)) return false; return true; }; -- GitLab