diff options
author | isaacs <i@izs.me> | 2013-02-28 15:32:32 -0800 |
---|---|---|
committer | isaacs <i@izs.me> | 2013-02-28 17:38:17 -0800 |
commit | 88644eaa2db3e9b603efca00e640ff08d9320c1b (patch) | |
tree | 09027029e40cddc963d2be6be455c1e0e48dcbb0 /lib/tls.js | |
parent | 4b67f0be6d682845661662f43602b4c0245b02a0 (diff) | |
download | nodejs-88644eaa2db3e9b603efca00e640ff08d9320c1b.tar.gz nodejs-88644eaa2db3e9b603efca00e640ff08d9320c1b.tar.bz2 nodejs-88644eaa2db3e9b603efca00e640ff08d9320c1b.zip |
stream: There is no _read cb, there is only push
This makes it so that `stream.push(chunk)` is the only way to signal the
end of reading, removing the confusing disparity between the
callback-style _read method, and the fact that most real-world streams
do not have a 1:1 corollation between the "please give me data" event,
and the actual arrival of a chunk of data.
It is still possible, of course, to implement a `CallbackReadable` on
top of this. Simply provide a method like this as the callback:
function readCallback(er, chunk) {
if (er)
stream.emit('error', er);
else
stream.push(chunk);
}
However, *only* fs streams actually would behave in this way, so it
makes not a lot of sense to make TCP, TLS, HTTP, and all the rest have
to bend into this uncomfortable paradigm.
Diffstat (limited to 'lib/tls.js')
-rw-r--r-- | lib/tls.js | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/tls.js b/lib/tls.js index 2a780373a..bb0a03af2 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -381,12 +381,13 @@ CryptoStream.prototype._writePending = function writePending() { }; -CryptoStream.prototype._read = function read(size, cb) { +CryptoStream.prototype._read = function read(size) { // XXX: EOF?! - if (!this.pair.ssl) return cb(null, null); + if (!this.pair.ssl) return this.push(null); // Wait for session to be resumed - if (this._resumingSession || !this._reading) return cb(null, ''); + // Mark that we're done reading, but don't provide data or EOF + if (this._resumingSession || !this._reading) return this.push(''); var out; if (this === this.pair.cleartext) { @@ -441,11 +442,12 @@ CryptoStream.prototype._read = function read(size, cb) { if (this === this.pair.cleartext) this._opposite._done(); - return cb(null, null); + // EOF + return this.push(null); } // Bail out - return cb(null, ''); + return this.push(''); } // Give them requested data @@ -459,7 +461,7 @@ CryptoStream.prototype._read = function read(size, cb) { self.read(bytesRead); }); } - return cb(null, pool.slice(start, start + bytesRead)); + return this.push(pool.slice(start, start + bytesRead)); }; |