prevent buffered _writes from binding thousands of events.
This commit is contained in:
parent
a96f27682f
commit
cb2bcc21c6
@ -244,13 +244,24 @@ Peer.prototype.destroy = function destroy() {
|
|||||||
// Private APIs
|
// Private APIs
|
||||||
|
|
||||||
Peer.prototype._write = function write(chunk) {
|
Peer.prototype._write = function write(chunk) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
if (this.destroyed)
|
if (this.destroyed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!this.socket) {
|
if (!this.socket) {
|
||||||
return this.once('socket', function() {
|
if (!this._bchunks) {
|
||||||
this._write(chunk);
|
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)
|
if (NodeBuffer)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user