self.destroyed = false;
self.errorEmitted = false;
self.bytesRead = 0;
- self.bytesWritten = 0;
+ self._bytesDispatched = 0;
// Handle creation may be deferred to bind() or connect() time.
if (self._handle) {
throw new TypeError('First argument must be a buffer or a string.');
}
- this.bytesWritten += data.length;
-
// If we are still connecting, then buffer this for later.
if (this._connecting) {
this._connectQueueSize += data.length;
writeReq.oncomplete = afterWrite;
writeReq.cb = cb;
+
this._pendingWriteReqs++;
+ this._bytesDispatched += writeReq.bytes;
return this._handle.writeQueueSize == 0;
};
+Socket.prototype.__defineGetter__('bytesWritten', function() {
+ var bytes = this._bytesDispatched,
+ connectQueue = this._connectQueue;
+
+ if (connectQueue) {
+ connectQueue.forEach(function(el) {
+ var data = el[0];
+ if (Buffer.isBuffer(data)) {
+ bytes += data.length;
+ } else {
+ bytes += Buffer.byteLength(data, el[1]);
+ }
+ }, this);
+ }
+
+ return bytes;
+});
+
+
function afterWrite(status, handle, req) {
var self = handle.socket;