Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Socket write speed
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Oct 6, 2011
1 parent 4c1d441 commit a50c282
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions lib/net_uv.js
Expand Up @@ -57,7 +57,8 @@ exports.connect = exports.createConnection = function(port /* [host], [cb] */) {


/* called when creating new Socket, or when re-using a closed Socket */ /* called when creating new Socket, or when re-using a closed Socket */
function initSocketHandle(self) { function initSocketHandle(self) {
self._writeRequests = []; self._writeRequestsHead = null;
self._writeRequestsTail = null;


self._flags = 0; self._flags = 0;
self._connectQueueSize = 0; self._connectQueueSize = 0;
Expand Down Expand Up @@ -235,7 +236,7 @@ Socket.prototype.destroySoon = function() {
this.writable = false; this.writable = false;
this._flags |= FLAG_DESTROY_SOON; this._flags |= FLAG_DESTROY_SOON;


if (this._writeRequests.length == 0) { if (!this._writeRequestsHead) {
this.destroy(); this.destroy();
} }
}; };
Expand Down Expand Up @@ -392,7 +393,14 @@ Socket.prototype.write = function(data /* [encoding], [fd], [cb] */) {


writeReq.oncomplete = afterWrite; writeReq.oncomplete = afterWrite;
writeReq.cb = cb; writeReq.cb = cb;
this._writeRequests.push(writeReq); writeReq.next = null;

if (this._writeRequestsTail) {
this._writeRequestsTail.next = writeReq;
this._writeRequestsTail = writeReq;
} else {
this._writeRequestsHead = this._writeRequestsTail = writeReq;
}


return this._handle.writeQueueSize == 0; return this._handle.writeQueueSize == 0;
}; };
Expand All @@ -407,18 +415,23 @@ function afterWrite(status, handle, req, buffer) {
} }
// TODO check status. // TODO check status.


var req_ = self._writeRequests.shift(); var req_ = self._writeRequestsHead;
if (req_.next) {
self._writeRequestsHead = req_.next;
} else {
self._writeRequestsHead = self._writeRequestsTail = null;
}
assert.equal(req, req_); assert.equal(req, req_);


if (self._writeRequests.length == 0) { if (!self._writeRequestsHead) {
// TODO remove all uses of ondrain - this is not a good hack. // TODO remove all uses of ondrain - this is not a good hack.
if (self.ondrain) self.ondrain(); if (self.ondrain) self.ondrain();
self.emit('drain'); self.emit('drain');
} }


if (req.cb) req.cb(); if (req.cb) req.cb();


if (self._writeRequests.length == 0 && self._flags & FLAG_DESTROY_SOON) { if (!self._writeRequestsHead && self._flags & FLAG_DESTROY_SOON) {
self.destroy(); self.destroy();
} }
} }
Expand Down

0 comments on commit a50c282

Please sign in to comment.