diff --git a/Readme.md b/Readme.md index 651e614f81..296ca69766 100644 --- a/Readme.md +++ b/Readme.md @@ -198,9 +198,14 @@ server.listen(3000); For other available methods, see `Namespace` below. -### Server#close +### Server#close([fn:Function]) - Closes socket.io server + Closes socket.io server. + + The optional `fn` is passed to the `server.close([callback])` method of the + core `net` module and is called on error or when all connections are closed. + The callback is expected to implement the common single argument `err` + signature (if any). ```js var Server = require('socket.io'); diff --git a/lib/index.js b/lib/index.js index 030c0bceca..24627a68cc 100644 --- a/lib/index.js +++ b/lib/index.js @@ -352,10 +352,11 @@ Server.prototype.of = function(name, fn){ /** * Closes server connection * + * @param {Function} [fn] optional, called as `fn([err])` on error OR all conns closed * @api public */ -Server.prototype.close = function(){ +Server.prototype.close = function(fn){ for (var id in this.nsps['/'].sockets) { if (this.nsps['/'].sockets.hasOwnProperty(id)) { this.nsps['/'].sockets[id].onclose(); @@ -364,8 +365,10 @@ Server.prototype.close = function(){ this.engine.close(); - if(this.httpServer){ - this.httpServer.close(); + if (this.httpServer) { + this.httpServer.close(fn); + } else { + fn && fn(); } };