make sure server gets close

This commit is contained in:
Narciso Guillen
2014-06-23 19:55:02 -05:00
parent 328a9df8eb
commit fbdb94d146

View File

@@ -211,6 +211,9 @@ Server.prototype.attach = function(srv, opts){
res.end();
});
srv.listen(port);
// Export http server
this.httpServer = srv;
}
// set engine.io path to `/socket.io`
@@ -328,6 +331,24 @@ Server.prototype.of = function(name, fn){
return this.nsps[name];
};
/**
* Closes server connection
*
* @api public
*/
Server.prototype.close = function(){
this.nsps['/'].sockets.forEach(function(socket){
socket.onclose();
});
this.engine.close();
if(this.httpServer){
this.httpServer.close();
}
};
/**
* Expose main namespace (/).
*/