Reattach 'readable' event listener when changing streams

Parser was not unregistering the 'readable' event listener from the old
socket, nor registering it to the new socket when setSocket() was
called.  This caused event handling to stop during the STARTTLS handoff.

Signed-off-by: Kevin Locke <klocke@quantpost.com>
fork
Kevin Locke 11 years ago
parent 2981485551
commit b73f325327

@ -40,8 +40,6 @@ function Parser(stream, debug) {
this._ignoreReadable = false;
this.debug = debug;
this.setStream(stream);
var self = this;
this._cbReadable = function() {
if (self._ignoreReadable)
@ -51,12 +49,18 @@ function Parser(stream, debug) {
else
self._tryread();
};
this._stream.on('readable', this._cbReadable);
this.setStream(stream);
process.nextTick(this._cbReadable);
}
inherits(Parser, EventEmitter);
Parser.prototype.setStream = function(stream) {
if (this._stream) {
this._stream.removeListener('readable', this._cbReadable);
}
if (/^v0\.8\./.test(process.version)) {
this._stream = (new ReadableStream()).wrap(stream);
@ -66,6 +70,8 @@ Parser.prototype.setStream = function(stream) {
stream._events.error.pop();
} else
this._stream = stream;
this._stream.on('readable', this._cbReadable);
};
Parser.prototype._tryread = function(n) {

Loading…
Cancel
Save