Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Simplify writeReq handling in net_uv

  • Loading branch information...
ry committed Oct 6, 2011
1 parent a50c282 commit 065c6f401d1a76b541467b4e162d474fea2334af
Showing with 6 additions and 20 deletions.
  1. +6 −20 lib/net_uv.js
@@ -57,8 +57,7 @@ exports.connect = exports.createConnection = function(port /* [host], [cb] */) {

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

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

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

writeReq.oncomplete = afterWrite;
writeReq.cb = cb;
writeReq.next = null;

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

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

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

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

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

if (!self._writeRequestsHead && self._flags & FLAG_DESTROY_SOON) {
if (self._pendingWriteReqs == 0 && self._flags & FLAG_DESTROY_SOON) {
self.destroy();
}
}

0 comments on commit 065c6f4

Please sign in to comment.
You can’t perform that action at this time.