You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
518 B
24 lines
518 B
module.exports = function makeKillable(server) {
|
|
var sockets = [];
|
|
|
|
server.on('connection', function (socket) {
|
|
//add socket to list
|
|
sockets.push(socket);
|
|
|
|
socket.once('close', function () {
|
|
//remove socket from list
|
|
sockets.splice(sockets.indexOf(socket), 1);
|
|
});
|
|
});
|
|
|
|
server.kill = function (cb) {
|
|
server.close(cb);
|
|
sockets.forEach(function (socket) {
|
|
socket.destroy();
|
|
});
|
|
// reset so the server can be restarted
|
|
sockets = [];
|
|
};
|
|
|
|
return server;
|
|
};
|
|
|