Skip to content

Commit

Permalink
[feature] add support for Server#close(callback) (socketio#2748)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhmeadows63 authored and darrachequesne committed Nov 15, 2016
1 parent 5a123be commit e14a10b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
9 changes: 7 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
9 changes: 6 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
}
};

Expand Down

0 comments on commit e14a10b

Please sign in to comment.