prevent buffered _writes from binding thousands of events.

This commit is contained in:
Christopher Jeffrey 2015-12-19 02:52:51 -08:00
parent a96f27682f
commit cb2bcc21c6

View File

@ -244,13 +244,24 @@ Peer.prototype.destroy = function destroy() {
// Private APIs
Peer.prototype._write = function write(chunk) {
var self = this;
if (this.destroyed)
return;
if (!this.socket) {
return this.once('socket', function() {
this._write(chunk);
});
if (!this._bchunks) {
this._bchunks = [];
this.once('socket', function() {
var chunks = self._bchunks;
delete self._bchunks;
chunks.forEach(function(chunk) {
self._write(chunk);
});
});
}
this._bchunks.push(chunk);
return;
}
if (NodeBuffer)