|
|
@ -56,7 +56,7 @@ var ioWatchers = new FreeList("iowatcher", 100, function () { |
|
|
|
|
|
|
|
|
|
|
|
IOWatcher.prototype.ondrain = function () { |
|
|
|
assert(this.socket); |
|
|
|
if (this.socket) { |
|
|
|
var socket = this.socket; |
|
|
|
|
|
|
|
if (socket.writable || socket.readable) { |
|
|
@ -67,6 +67,7 @@ IOWatcher.prototype.ondrain = function () { |
|
|
|
if (socket.ondrain) socket.ondrain(); |
|
|
|
|
|
|
|
if (socket._eof) socket._shutdown(); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -252,12 +253,13 @@ Object.defineProperty(Stream.prototype, 'readyState', { |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
Stream.prototype._appendBucket = function (data, encoding, fd) { |
|
|
|
Stream.prototype._appendBucket = function (data, encoding, fd, callback) { |
|
|
|
if (data.length != 0) { |
|
|
|
// TODO reject empty data.
|
|
|
|
var newBucket = { data: data }; |
|
|
|
if (encoding) newBucket.encoding = encoding; |
|
|
|
if (fd) newBucket.fd = fd; |
|
|
|
if (callback) newBucket.callback = callback; |
|
|
|
|
|
|
|
// TODO properly calculate queueSize
|
|
|
|
|
|
|
@ -280,7 +282,7 @@ Stream.prototype._appendBucket = function (data, encoding, fd) { |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
Stream.prototype.write = function (data, encoding, fd) { |
|
|
|
Stream.prototype.write = function (data /* encoding, fd, callback */) { |
|
|
|
if (this._eof) { |
|
|
|
throw new Error('Stream.end() called already; cannot write.'); |
|
|
|
} |
|
|
@ -289,7 +291,29 @@ Stream.prototype.write = function (data, encoding, fd) { |
|
|
|
throw new Error('Stream is not writable'); |
|
|
|
} |
|
|
|
|
|
|
|
var queueSize = this._appendBucket(data, encoding, fd); |
|
|
|
// parse the arguments. ugly.
|
|
|
|
|
|
|
|
var encoding, fd, callback; |
|
|
|
|
|
|
|
if (arguments[1] === undefined || typeof arguments[1] == 'string') { |
|
|
|
encoding = arguments[1]; |
|
|
|
if (typeof arguments[2] == 'number') { |
|
|
|
fd = arguments[2]; |
|
|
|
callback = arguments[3]; |
|
|
|
} else { |
|
|
|
callback = arguments[2]; |
|
|
|
} |
|
|
|
} else if (typeof arguments[1] == 'number') { |
|
|
|
fd = arguments[1]; |
|
|
|
callback = arguments[2]; |
|
|
|
} else if (typeof arguments[1] == 'function') { |
|
|
|
callback = arguments[1]; |
|
|
|
} else { |
|
|
|
throw new Error("Bad type for second argument"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var queueSize = this._appendBucket(data, encoding, fd, callback); |
|
|
|
|
|
|
|
if (this._connecting) return false; |
|
|
|
|
|
|
|