mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-25 09:55:15 +00:00
25 lines
518 B
JavaScript
25 lines
518 B
JavaScript
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;
|
|
};
|