1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

tag UDP ports in use properly so they get closed correctly (#1508)

* tag ports in use properly so they get closed correctly

to close #1470

* redo test for udp port in use

* check port in use correctly on close
This commit is contained in:
Dave Conway-Jones 2018-01-11 22:03:59 +00:00 committed by Nick O'Leary
parent 915d73e6f2
commit a3640bd9bf

View File

@ -125,8 +125,8 @@ module.exports = function(RED) {
if (process.version.indexOf("v0.10") === 0) { opts = node.ipv; }
var sock;
if (udpInputPortsInUse[this.outport]) {
sock = udpInputPortsInUse[this.outport];
if (udpInputPortsInUse[this.outport || this.port]) {
sock = udpInputPortsInUse[this.outport || this.port];
}
else {
sock = dgram.createSocket(opts); // default to udp4
@ -136,7 +136,7 @@ module.exports = function(RED) {
// prevent it going to the global error handler and shutting node-red
// down.
});
udpInputPortsInUse[this.outport] = sock;
udpInputPortsInUse[this.outport || this.port] = sock;
}
if (node.multicast != "false") {
@ -161,7 +161,7 @@ module.exports = function(RED) {
node.log(RED._("udp.status.bc-ready",{outport:node.outport,host:node.addr,port:node.port}));
}
});
} else if ((node.outport !== "") && (!udpInputPortsInUse[this.outport])) {
} else if ((node.outport !== "") && (!udpInputPortsInUse[node.outport])) {
sock.bind(node.outport);
node.log(RED._("udp.status.ready",{outport:node.outport,host:node.addr,port:node.port}));
} else {
@ -198,8 +198,8 @@ module.exports = function(RED) {
});
node.on("close", function() {
if (udpInputPortsInUse.hasOwnProperty(node.outport)) {
delete udpInputPortsInUse[node.outport];
if (udpInputPortsInUse.hasOwnProperty(node.outport || node.port)) {
delete udpInputPortsInUse[node.outport || node.port];
}
try {
sock.close();