55using System . Text ;
66using System . Threading ;
77using System . Threading . Tasks ;
8+ using Microsoft . Extensions . Logging ;
89using SuperSocket . Client ;
910using SuperSocket . MySQL . Packets ;
1011using SuperSocket . ProtoBase ;
@@ -23,8 +24,8 @@ public class MySQLConnection : EasyClient<MySQLPacket>
2324
2425 public bool IsAuthenticated { get ; private set ; }
2526
26- public MySQLConnection ( string host , int port , string userName , string password )
27- : base ( new MySQLPacketFilter ( MySQLPacketDecoder . ClientInstance ) )
27+ public MySQLConnection ( string host , int port , string userName , string password , ILogger logger = null )
28+ : base ( new MySQLPacketFilter ( MySQLPacketDecoder . ClientInstance ) , logger )
2829 {
2930 _host = host ?? throw new ArgumentNullException ( nameof ( host ) ) ;
3031 _port = port > 0 ? port : DefaultPort ;
@@ -87,6 +88,8 @@ public async Task ConnectAsync(CancellationToken cancellationToken = default)
8788 ? errorPacket . ErrorMessage
8889 : "Authentication failed" ;
8990 throw new InvalidOperationException ( $ "MySQL authentication failed: { errorMsg } (Error { errorPacket . ErrorCode } )") ;
91+ case EOFPacket eofPacket :
92+ throw new InvalidOperationException ( $ "MySQL authentication failed.") ;
9093 default :
9194 throw new InvalidOperationException ( $ "Unexpected packet received during authentication: { authResult ? . GetType ( ) . Name ?? "null" } ") ;
9295 }
@@ -160,7 +163,8 @@ public async Task DisconnectAsync()
160163 {
161164 try
162165 {
163- await CloseAsync ( ) ;
166+ if ( Connection != null )
167+ await CloseAsync ( ) ;
164168 }
165169 finally
166170 {
0 commit comments