123456789101112131415161718192021222324 |
- 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;
- };
|