net: Add hook for when writeQueue changes
authorRyan Dahl <ry@tinyclouds.org>
Mon, 31 Jan 2011 19:01:57 +0000 (11:01 -0800)
committerRyan Dahl <ry@tinyclouds.org>
Mon, 31 Jan 2011 19:01:59 +0000 (11:01 -0800)
lib/net.js

index 38ef6d6..8c387df 100644 (file)
@@ -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;