From 9f3a20c76d45e98c4f39463435837adebdf5d0dc Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Mon, 31 Jan 2011 11:01:57 -0800 Subject: [PATCH] net: Add hook for when writeQueue changes --- lib/net.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/net.js b/lib/net.js index 38ef6d616a8..8c387df0e49 100644 --- a/lib/net.js +++ b/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;