@@ -319,7 +319,7 @@ public void connect() throws IOException {
319319 if (connected ) {
320320 throw new IllegalStateException ("BinaryLogClient is already connected" );
321321 }
322- Long connectionId ;
322+ GreetingPacket greetingPacket ;
323323 try {
324324 try {
325325 Socket socket = socketFactory != null ? socketFactory .createSocket () : new Socket ();
@@ -332,15 +332,7 @@ public void connect() throws IOException {
332332 throw new IOException ("Failed to connect to MySQL on " + hostname + ":" + port +
333333 ". Please make sure it's running." , e );
334334 }
335- byte [] initialHandshakePacket = channel .read ();
336- if (initialHandshakePacket [0 ] == (byte ) 0xFF /* error */ ) {
337- byte [] bytes = Arrays .copyOfRange (initialHandshakePacket , 1 , initialHandshakePacket .length );
338- ErrorPacket errorPacket = new ErrorPacket (bytes );
339- throw new ServerException (errorPacket .getErrorMessage (), errorPacket .getErrorCode (),
340- errorPacket .getSqlState ());
341- }
342- GreetingPacket greetingPacket = new GreetingPacket (initialHandshakePacket );
343- connectionId = greetingPacket .getThreadId ();
335+ greetingPacket = receiveGreeting ();
344336 authenticate (greetingPacket .getScramble (), greetingPacket .getServerCollation ());
345337 if (binlogFilename == null ) {
346338 fetchBinlogFilenameAndPosition ();
@@ -365,7 +357,7 @@ public void connect() throws IOException {
365357 connected = true ;
366358 if (logger .isLoggable (Level .INFO )) {
367359 logger .info ("Connected to " + hostname + ":" + port + " at " + binlogFilename + "/" + binlogPosition +
368- " (sid:" + serverId + ", cid:" + connectionId + ")" );
360+ " (sid:" + serverId + ", cid:" + greetingPacket . getThreadId () + ")" );
369361 }
370362 synchronized (lifecycleListeners ) {
371363 for (LifecycleListener lifecycleListener : lifecycleListeners ) {
@@ -384,6 +376,17 @@ public void connect() throws IOException {
384376 listenForEventPackets ();
385377 }
386378
379+ private GreetingPacket receiveGreeting () throws IOException {
380+ byte [] initialHandshakePacket = channel .read ();
381+ if (initialHandshakePacket [0 ] == (byte ) 0xFF /* error */ ) {
382+ byte [] bytes = Arrays .copyOfRange (initialHandshakePacket , 1 , initialHandshakePacket .length );
383+ ErrorPacket errorPacket = new ErrorPacket (bytes );
384+ throw new ServerException (errorPacket .getErrorMessage (), errorPacket .getErrorCode (),
385+ errorPacket .getSqlState ());
386+ }
387+ return new GreetingPacket (initialHandshakePacket );
388+ }
389+
387390 private void requestBinaryLogStream () throws IOException {
388391 Command dumpBinaryLogCommand ;
389392 synchronized (gtidSetAccessLock ) {
0 commit comments