index.js 518 B

12345678910111213141516171819202122232425
  1. module.exports = function makeKillable(server) {
  2. var sockets = [];
  3. server.on('connection', function (socket) {
  4. //add socket to list
  5. sockets.push(socket);
  6. socket.once('close', function () {
  7. //remove socket from list
  8. sockets.splice(sockets.indexOf(socket), 1);
  9. });
  10. });
  11. server.kill = function (cb) {
  12. server.close(cb);
  13. sockets.forEach(function (socket) {
  14. socket.destroy();
  15. });
  16. // reset so the server can be restarted
  17. sockets = [];
  18. };
  19. return server;
  20. };