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

4 years ago
  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. };