net: Add hook for when writeQueue changes

This commit is contained in:
Ryan Dahl 2011-01-31 11:01:57 -08:00
parent ef123600ce
commit 9f3a20c76d

View File

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