self._destroy(err);
};
- this.cleartext.on('end', function(err) {
- debug('clearIn end');
- if (!self._done) {
- self._ssl.shutdown();
- self._cycle();
- }
- self._destroy(err);
- });
-
- this.cleartext.on('close', function() {
- debug('source close');
- self.emit('close');
- self._destroy();
- });
-
- this.cleartext.on('drain', function() {
- debug('source drain');
- self._cycle();
- self.encrypted.resume();
- });
-
- this.encrypted.on('drain', function() {
- debug('target drain');
- self._cycle();
- self.cleartext.resume();
- });
-
process.nextTick(function() {
self._ssl.start();
self._cycle();
// pair.encrypted.write(d)
// });
//
+ var encPending = this._encInPending.length > 0;
while (this._encInPending.length > 0) {
tmp = this._encInPending.shift();
assert(rv === tmp.length);
}
+ // If we've cleared all of incoming encrypted data, emit drain.
+ if (encPending && this._encInPending.length === 0) {
+ debug('encrypted drain');
+ this.encrypted.emit('drain');
+ }
+
+
// Pull in any clear data coming from the application.
// This arrives via some code like this:
//
// pair.cleartext.write("hello world");
//
+ var clearPending = this._clearInPending.length > 0;
while (this._clearInPending.length > 0) {
tmp = this._clearInPending.shift();
try {
assert(rv === tmp.length);
}
+ // If we've cleared all of incoming cleartext data, emit drain.
+ if (clearPending && this._clearInPending.length === 0) {
+ debug('cleartext drain');
+ this.cleartext.emit('drain');
+ }
+
+
// Move decrypted, clear data out into the application.
// From the user's perspective this occurs as a 'data' event
// on the pair.cleartext.
this._ssl = null;
this.encrypted.emit('close');
this.cleartext.emit('close');
- this.emit('end', err);
}
this._cycle();
};