Tcpgetfix: Another small check (#1070)

* TCPget: Add another check for clients[connection_id]
This commit is contained in:
Nathanaël Lécaudé 2016-11-26 16:16:19 -05:00 committed by Dave Conway-Jones
parent b530c1a43d
commit 2084ad318f
1 changed files with 21 additions and 19 deletions

View File

@ -467,26 +467,28 @@ module.exports = function(RED) {
else { else {
for (var j = 0; j < data.length; j++ ) { for (var j = 0; j < data.length; j++ ) {
if (node.out === "time") { if (node.out === "time") {
// do the timer thing if (clients[connection_id]) {
if (clients[connection_id] && clients[connection_id].timeout) { // do the timer thing
i += 1; if (clients[connection_id].timeout) {
buf[i] = data[j]; i += 1;
} buf[i] = data[j];
else { }
clients[connection_id].timeout = setTimeout(function () { else {
if (clients[connection_id]) { clients[connection_id].timeout = setTimeout(function () {
clients[connection_id].timeout = null; if (clients[connection_id]) {
clients[connection_id].msg.payload = new Buffer(i+1); clients[connection_id].timeout = null;
buf.copy(clients[connection_id].msg.payload,0,0,i+1); clients[connection_id].msg.payload = new Buffer(i+1);
node.send(clients[connection_id].msg); buf.copy(clients[connection_id].msg.payload,0,0,i+1);
if (clients[connection_id].client) { node.send(clients[connection_id].msg);
node.status({}); clients[connection_id].client.destroy(); if (clients[connection_id].client) {
delete clients[connection_id]; node.status({}); clients[connection_id].client.destroy();
delete clients[connection_id];
}
} }
} }, node.splitc);
}, node.splitc); i = 0;
i = 0; buf[0] = data[j];
buf[0] = data[j]; }
} }
} }
// count bytes into a buffer... // count bytes into a buffer...