Skip to content

Commit bd86dfe

Browse files
committed
Remove special case for handshake in determine packet code
1 parent 430dab0 commit bd86dfe

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

Changes.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ you spot any mistakes.
77
## HEAD
88

99
* Fix `connection.threadId` missing on handshake failure
10+
* Remove special case for handshake in determine packet code
1011
* Small performance improvement starting command sequence
1112

1213
## v2.16.0 (2018-07-17)

lib/protocol/Protocol.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,6 @@ Protocol.prototype._enqueue = function(sequence) {
156156
sequence._timer.active();
157157
self._emitPacket(packet);
158158
})
159-
.on('end', function() {
160-
self._dequeue(sequence);
161-
})
162159
.on('timeout', function() {
163160
var err = new Error(sequence.constructor.name + ' inactivity timeout');
164161

@@ -185,8 +182,20 @@ Protocol.prototype._enqueue = function(sequence) {
185182
sequence._tlsUpgradeCompleteHandler();
186183
});
187184
});
185+
186+
sequence.on('end', function () {
187+
self._handshaked = true;
188+
189+
if (!self._fatalError) {
190+
self.emit('handshake', self._handshakeInitializationPacket);
191+
}
192+
});
188193
}
189194

195+
sequence.on('end', function () {
196+
self._dequeue(sequence);
197+
});
198+
190199
if (this._queue.length === 1) {
191200
this._parser.resetPacketNumber();
192201
this._startSequence(sequence);
@@ -311,12 +320,7 @@ Protocol.prototype._determinePacket = function(sequence) {
311320
}
312321

313322
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;
320324
case 0xfe: return Packets.EofPacket;
321325
case 0xff: return Packets.ErrorPacket;
322326
}

0 commit comments

Comments
 (0)