Skip to content

Commit

Permalink
Allow to use unix sockets in tcp servers.
Browse files Browse the repository at this point in the history
* Add socket config option to specify path where socket will be stored.
* Add socket_mod config option to set correct permission on socket file.
* Remove socket on process exit.
  • Loading branch information
nihn committed Feb 2, 2016
1 parent 243a1f2 commit 74f875e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions servers/tcp.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var net = require('net');
var fs = require('fs');

function rinfo(tcpstream, data) {
this.address = tcpstream.remoteAddress;
Expand All @@ -23,8 +24,15 @@ exports.start = function(config, callback) {
});
});

server.listen(config.port || 8125, config.address || undefined);
this.server = server;
server.on('listening', (e) => {
config.socket && config.socket_mod && fs.chmod(config.socket, config.socket_mod);
});

process.on('exit', (e) => {
config.socket && fs.unlinkSync(config.socket);
})

server.listen(config.socket || config.port || 8125, config.address || undefined);
this.server = server;
return true;
};

0 comments on commit 74f875e

Please sign in to comment.