Skip to content

Commit

Permalink
discard transport on server close
Browse files Browse the repository at this point in the history
  • Loading branch information
nkzawa committed Jan 21, 2016
1 parent 7a64e67 commit 941a6eb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/server.js
Expand Up @@ -179,7 +179,7 @@ Server.prototype.close = function(){
debug('closing all open clients');
for (var i in this.clients) {
if (this.clients.hasOwnProperty(i)) {
this.clients[i].close();
this.clients[i].close(true);
}
}
return this;
Expand Down
11 changes: 7 additions & 4 deletions lib/socket.js
Expand Up @@ -440,29 +440,32 @@ Socket.prototype.getAvailableUpgrades = function () {
/**
* Closes the socket and underlying transport.
*
* @param {Boolean} optional, discard
* @return {Socket} for chaining
* @api public
*/

Socket.prototype.close = function () {
Socket.prototype.close = function (discard) {
if ('open' != this.readyState) return;

this.readyState = 'closing';

if (this.writeBuffer.length) {
this.once('drain', this.closeTransport.bind(this));
this.once('drain', this.closeTransport.bind(this, discard));
return;
}

this.closeTransport();
this.closeTransport(discard);
};

/**
* Closes the underlying transport.
*
* @param {Boolean} discard
* @api private
*/

Socket.prototype.closeTransport = function () {
Socket.prototype.closeTransport = function (discard) {
if (discard) this.transport.discard();
this.transport.close(this.onClose.bind(this, 'forced close'));
};

0 comments on commit 941a6eb

Please sign in to comment.