don't throw on error

This commit is contained in:
AJ ONeal 2017-12-15 04:20:16 +00:00
parent d8ead3181d
commit e2393d965a
2 changed files with 58 additions and 49 deletions

View File

@ -53,10 +53,11 @@ module.exports.create = function (cli, dnsd) {
process.exit(0); process.exit(0);
} }
console.error("TCP Server Error:"); console.error("TCP Server Error:");
console.error(err); console.error(err.stack);
tcpServer.close(function () { tcpServer.close(function () {
setTimeout(runTcp, 1000); setTimeout(runTcp, 1000);
}); });
//throw new Error(err);
}); });
tcpServer.listen(cli.port, function () { tcpServer.listen(cli.port, function () {

View File

@ -1,6 +1,7 @@
'use strict'; 'use strict';
module.exports.create = function (cli, dnsd) { module.exports.create = function (cli, dnsd) {
function runUdp() {
var server = require('dgram').createSocket({ var server = require('dgram').createSocket({
type: cli.udp6 ? 'udp6' : 'udp4' type: cli.udp6 ? 'udp6' : 'udp4'
, reuseAddr: true , reuseAddr: true
@ -19,8 +20,12 @@ module.exports.create = function (cli, dnsd) {
process.exit(123); process.exit(123);
return; return;
} }
console.error("error:", err.stack); console.error("UDP Server Error:");
server.close(); console.error(err.stack);
server.close(function () {
setTimeout(runUdp, 1000);
});
//throw new Error(err);
}; };
handlers.onMessage = function (nb, rinfo) { handlers.onMessage = function (nb, rinfo) {
@ -29,9 +34,9 @@ module.exports.create = function (cli, dnsd) {
dnsd.onMessage(nb, function (err, newAb, dbgmsg) { dnsd.onMessage(nb, function (err, newAb, dbgmsg) {
// TODO send legit error message // TODO send legit error message
if (err) { server.send(Buffer.from([0x00])); return; } if (err) { server.send(Buffer.from([0x00]), rinfo.port, rinfo.address); return; }
server.send(newAb, rinfo.port, rinfo.address, function () { server.send(newAb, rinfo.port, rinfo.address, function () {
console.log(dbgmsg, rinfo.port, rinfo.address); console.log('[dnsd.onMessage] ' + dbgmsg, rinfo.port, rinfo.address);
}); });
}); });
}; };
@ -55,4 +60,7 @@ module.exports.create = function (cli, dnsd) {
server.on('listening', handlers.onListening); server.on('listening', handlers.onListening);
return server; return server;
}
return runUdp();
}; };