@@ -156,9 +156,6 @@ Protocol.prototype._enqueue = function(sequence) {
156
156
sequence . _timer . active ( ) ;
157
157
self . _emitPacket ( packet ) ;
158
158
} )
159
- . on ( 'end' , function ( ) {
160
- self . _dequeue ( sequence ) ;
161
- } )
162
159
. on ( 'timeout' , function ( ) {
163
160
var err = new Error ( sequence . constructor . name + ' inactivity timeout' ) ;
164
161
@@ -185,8 +182,20 @@ Protocol.prototype._enqueue = function(sequence) {
185
182
sequence . _tlsUpgradeCompleteHandler ( ) ;
186
183
} ) ;
187
184
} ) ;
185
+
186
+ sequence . on ( 'end' , function ( ) {
187
+ self . _handshaked = true ;
188
+
189
+ if ( ! self . _fatalError ) {
190
+ self . emit ( 'handshake' , self . _handshakeInitializationPacket ) ;
191
+ }
192
+ } ) ;
188
193
}
189
194
195
+ sequence . on ( 'end' , function ( ) {
196
+ self . _dequeue ( sequence ) ;
197
+ } ) ;
198
+
190
199
if ( this . _queue . length === 1 ) {
191
200
this . _parser . resetPacketNumber ( ) ;
192
201
this . _startSequence ( sequence ) ;
@@ -311,12 +320,7 @@ Protocol.prototype._determinePacket = function(sequence) {
311
320
}
312
321
313
322
switch ( firstByte ) {
314
- case 0x00 :
315
- if ( ! this . _handshaked ) {
316
- this . _handshaked = true ;
317
- this . emit ( 'handshake' , this . _handshakeInitializationPacket ) ;
318
- }
319
- return Packets . OkPacket ;
323
+ case 0x00 : return Packets . OkPacket ;
320
324
case 0xfe : return Packets . EofPacket ;
321
325
case 0xff : return Packets . ErrorPacket ;
322
326
}
0 commit comments