Aggiungi override probe TCP keepalive
This commit is contained in:
1 parent
6b19a8a606
commit
cc4a3ed9c1
9 files changed
+154
-3
No files matched your search
+12
-2
@@ -19,6 +19,7 @@ module.exports = function(RED) {
|
||||
var reconnectTime = RED.settings.socketReconnectTime||10000;
|
||||
const msgQueueSize = RED.settings.tcpMsgQueueSize || 1000;
|
||||
const Denque = require('denque');
|
||||
const tcpKeepAlive = require('./tcp-keepalive');
|
||||
var net = require('net');
|
||||
|
||||
var connectionPool = {};
|
||||
@@ -45,6 +46,14 @@ module.exports = function(RED) {
|
||||
*/
|
||||
const dequeue = queue => queue.shift();
|
||||
|
||||
function setKeepAlive(socket, delay, probes, node) {
|
||||
socket.setKeepAlive(true, delay);
|
||||
if (probes > 0 && !tcpKeepAlive.setKeepAliveProbes(socket, probes) && !node.keepaliveProbesWarned) {
|
||||
node.keepaliveProbesWarned = true;
|
||||
node.warn("TCP keepalive probe count override is not available on this platform/runtime");
|
||||
}
|
||||
}
|
||||
|
||||
function TcpIn(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
this.host = n.host;
|
||||
@@ -55,6 +64,7 @@ module.exports = function(RED) {
|
||||
this.newline = (n.newline||"").replace("\\n","\n").replace("\\r","\r");
|
||||
this.base64 = n.base64;
|
||||
this.keepalive = parseInt(n.keepalive) || 120000;
|
||||
this.keepaliveProbes = tcpKeepAlive.parseKeepAliveProbes(n.keepaliveProbes);
|
||||
this.server = (typeof n.server == 'boolean')?n.server:(n.server == "server");
|
||||
this.closing = false;
|
||||
this.connected = false;
|
||||
@@ -76,7 +86,7 @@ module.exports = function(RED) {
|
||||
node.log(RED._("tcpin.status.connected",{host:node.host,port:node.port}));
|
||||
node.status({fill:"green",shape:"dot",text:"common.status.connected"});
|
||||
});
|
||||
client.setKeepAlive(true, node.keepalive);
|
||||
setKeepAlive(client, node.keepalive, node.keepaliveProbes, node);
|
||||
connectionPool[id] = client;
|
||||
|
||||
client.on('data', function (data) {
|
||||
@@ -151,7 +161,7 @@ module.exports = function(RED) {
|
||||
}
|
||||
else {
|
||||
var server = net.createServer(function (socket) {
|
||||
socket.setKeepAlive(true, node.keepalive);
|
||||
setKeepAlive(socket, node.keepalive, node.keepaliveProbes, node);
|
||||
var id = (1+Math.random()*4294967295).toString(16);
|
||||
var fromi;
|
||||
var fromp;
|
||||
|
||||
Reference in new issue
Block a user