Browse Source

net: Add hook for when writeQueue changes

v0.7.4-release
Ryan Dahl 14 years ago
parent
commit
9f3a20c76d
  1. 11
      lib/net.js

11
lib/net.js

@ -345,6 +345,8 @@ Socket.prototype.write = function(data /* [encoding], [fd], [cb] */) {
this._writeQueueFD.push(fd);
}
this._onBufferChange();
return false;
} else {
// Fast.
@ -417,6 +419,7 @@ Socket.prototype._writeOut = function(data, encoding, fd, cb) {
this._writeQueueEncoding.unshift(encoding);
this._writeQueueCallbacks.unshift(cb);
this._writeWatcher.start();
this._onBufferChange();
queuedData = true;
}
}
@ -465,6 +468,7 @@ Socket.prototype._writeOut = function(data, encoding, fd, cb) {
this._writeQueue.unshift(leftOver);
this._writeQueueEncoding.unshift(null);
this._writeQueueCallbacks.unshift(cb);
this._onBufferChange();
// If didn't successfully write any bytes, enqueue our fd and try again
if (!bytesWritten) {
@ -475,6 +479,12 @@ Socket.prototype._writeOut = function(data, encoding, fd, cb) {
};
Socket.prototype._onBufferChange = function() {
// Put DTrace hooks here.
;
};
// Flushes the write buffer out.
// Returns true if the entire buffer was flushed.
Socket.prototype.flush = function() {
@ -491,6 +501,7 @@ Socket.prototype.flush = function() {
// Only decrement if it's not the END_OF_FILE object...
this.bufferSize -= data.length;
this._onBufferChange();
var flushed = this._writeOut(data, encoding, fd, cb);
if (!flushed) return false;

Loading…
Cancel
Save