File tree 5 files changed +55
-5
lines changed 5 files changed +55
-5
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ function Connection(options) {
17
17
this . _protocol = new Protocol ( { config : this . config , connection : this } ) ;
18
18
this . _connectCalled = false ;
19
19
this . state = "disconnected" ;
20
+ this . threadId = null ;
20
21
}
21
22
22
23
function bindToCurrentDomain ( cb ) {
@@ -282,8 +283,9 @@ Connection.prototype._handleProtocolConnect = function() {
282
283
this . state = "connected" ;
283
284
} ;
284
285
285
- Connection . prototype . _handleProtocolHandshake = function ( ) {
286
- this . state = "authenticated" ;
286
+ Connection . prototype . _handleProtocolHandshake = function _handleProtocolHandshake ( packet ) {
287
+ this . state = "authenticated" ;
288
+ this . threadId = packet . threadId ;
287
289
} ;
288
290
289
291
Connection . prototype . _handleProtocolEnd = function ( err ) {
Original file line number Diff line number Diff line change @@ -229,7 +229,7 @@ Protocol.prototype._determinePacket = function(sequence) {
229
229
case 0x00 :
230
230
if ( ! this . _handshaked ) {
231
231
this . _handshaked = true ;
232
- this . emit ( 'handshake' ) ;
232
+ this . emit ( 'handshake' , this . _handshakeInitializationPacket ) ;
233
233
}
234
234
return Packets . OkPacket ;
235
235
case 0xfe : return Packets . EofPacket ;
Original file line number Diff line number Diff line change 1
1
// An experimental fake MySQL server for tricky integration tests. Expanded
2
2
// as needed.
3
3
4
+ var _ = require ( 'underscore' ) ;
4
5
var Net = require ( 'net' ) ;
5
6
var Packets = require ( '../lib/protocol/packets' ) ;
6
7
var PacketWriter = require ( '../lib/protocol/PacketWriter' ) ;
@@ -54,12 +55,14 @@ function FakeConnection(socket) {
54
55
FakeConnection . prototype . handshake = function ( options ) {
55
56
this . _handshakeOptions = options || { } ;
56
57
57
- this . _handshakeInitializationPacket = new Packets . HandshakeInitializationPacket ( {
58
+ var packetOpiotns = _ . extend ( {
58
59
scrambleBuff1 : new Buffer ( '1020304050607080' , 'hex' ) ,
59
60
scrambleBuff2 : new Buffer ( '0102030405060708090A0B0C' , 'hex' ) ,
60
61
serverCapabilities1 : 512 , // only 1 flag, PROTOCOL_41
61
62
protocol41 : true
62
- } ) ;
63
+ } , this . _handshakeOptions ) ;
64
+
65
+ this . _handshakeInitializationPacket = new Packets . HandshakeInitializationPacket ( packetOpiotns ) ;
63
66
64
67
this . _sendPacket ( this . _handshakeInitializationPacket ) ;
65
68
} ;
Original file line number Diff line number Diff line change
1
+ var assert = require ( 'assert' ) ;
2
+ var common = require ( '../../common' ) ;
3
+ var connection = common . createConnection ( ) ;
4
+
5
+ assert . strictEqual ( connection . threadId , null ) ;
6
+
7
+ connection . connect ( function ( err ) {
8
+ assert . ifError ( err ) ;
9
+ assert . notStrictEqual ( connection . threadId , null ) ;
10
+ assert . notStrictEqual ( connection . threadId , 0 ) ;
11
+
12
+ connection . end ( function ( err ) {
13
+ assert . ifError ( err ) ;
14
+ assert . notStrictEqual ( connection . threadId , null ) ;
15
+ assert . notStrictEqual ( connection . threadId , 0 ) ;
16
+ server . destroy ( ) ;
17
+ } ) ;
18
+ } ) ;
Original file line number Diff line number Diff line change
1
+ var assert = require ( 'assert' ) ;
2
+ var common = require ( '../../common' ) ;
3
+ var connection = common . createConnection ( { port : common . fakeServerPort } ) ;
4
+
5
+ var server = common . createFakeServer ( ) ;
6
+
7
+ server . listen ( common . fakeServerPort , function ( err ) {
8
+ assert . ifError ( err ) ;
9
+ assert . strictEqual ( connection . threadId , null ) ;
10
+
11
+ connection . connect ( function ( err ) {
12
+ assert . ifError ( err ) ;
13
+ assert . strictEqual ( connection . threadId , 42 ) ;
14
+
15
+ connection . end ( function ( err ) {
16
+ assert . ifError ( err ) ;
17
+ assert . strictEqual ( connection . threadId , 42 ) ;
18
+ server . destroy ( ) ;
19
+ } ) ;
20
+ } ) ;
21
+ } ) ;
22
+
23
+ server . on ( 'connection' , function ( incomingConnection ) {
24
+ incomingConnection . handshake ( {
25
+ threadId : 42
26
+ } ) ;
27
+ } ) ;
You can’t perform that action at this time.
0 commit comments