index.js 430 B

12345678910111213141516171819
  1. module.exports = enableDestroy;
  2. function enableDestroy(server) {
  3. var connections = {}
  4. server.on('connection', function(conn) {
  5. var key = conn.remoteAddress + ':' + conn.remotePort;
  6. connections[key] = conn;
  7. conn.on('close', function() {
  8. delete connections[key];
  9. });
  10. });
  11. server.destroy = function(cb) {
  12. server.close(cb);
  13. for (var key in connections)
  14. connections[key].destroy();
  15. };
  16. }