|
|
@ -59,7 +59,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._writeRequests = []; |
|
|
|
self._pendingWriteReqs = 0; |
|
|
|
|
|
|
|
self._flags = 0; |
|
|
|
self._connectQueueSize = 0; |
|
|
@ -237,7 +237,7 @@ Socket.prototype.destroySoon = function() { |
|
|
|
this.writable = false; |
|
|
|
this._flags |= FLAG_DESTROY_SOON; |
|
|
|
|
|
|
|
if (this._writeRequests.length == 0) { |
|
|
|
if (this._pendingWriteReqs == 0) { |
|
|
|
this.destroy(); |
|
|
|
} |
|
|
|
}; |
|
|
@ -395,7 +395,7 @@ Socket.prototype.write = function(data /* [encoding], [fd], [cb] */) { |
|
|
|
|
|
|
|
writeReq.oncomplete = afterWrite; |
|
|
|
writeReq.cb = cb; |
|
|
|
this._writeRequests.push(writeReq); |
|
|
|
this._pendingWriteReqs++; |
|
|
|
|
|
|
|
return this._handle.writeQueueSize == 0; |
|
|
|
}; |
|
|
@ -410,10 +410,9 @@ function afterWrite(status, handle, req, buffer) { |
|
|
|
} |
|
|
|
// TODO check status.
|
|
|
|
|
|
|
|
var req_ = self._writeRequests.shift(); |
|
|
|
assert.equal(req, req_); |
|
|
|
self._pendingWriteReqs--; |
|
|
|
|
|
|
|
if (self._writeRequests.length == 0) { |
|
|
|
if (self._pendingWriteReqs == 0) { |
|
|
|
// TODO remove all uses of ondrain - this is not a good hack.
|
|
|
|
if (self.ondrain) self.ondrain(); |
|
|
|
self.emit('drain'); |
|
|
@ -421,7 +420,7 @@ function afterWrite(status, handle, req, buffer) { |
|
|
|
|
|
|
|
if (req.cb) req.cb(); |
|
|
|
|
|
|
|
if (self._writeRequests.length == 0 && self._flags & FLAG_DESTROY_SOON) { |
|
|
|
if (self._pendingWriteReqs == 0 && self._flags & FLAG_DESTROY_SOON) { |
|
|
|
self.destroy(); |
|
|
|
} |
|
|
|
} |
|
|
|