@@ -340,7 +340,7 @@ public async Task ConnectAsync(ConnectionSettings cs, int startTickCount, ILoadB
340
340
else if ( cs . ConnectionProtocol == MySqlConnectionProtocol . UnixSocket )
341
341
connected = await OpenUnixSocketAsync ( cs , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
342
342
else if ( cs . ConnectionProtocol == MySqlConnectionProtocol . NamedPipe )
343
- connected = await OpenNamedPipeAsync ( cs , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
343
+ connected = await OpenNamedPipeAsync ( cs , startTickCount , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
344
344
if ( ! connected )
345
345
{
346
346
lock ( m_lock )
@@ -981,23 +981,35 @@ private async Task<bool> OpenUnixSocketAsync(ConnectionSettings cs, IOBehavior i
981
981
return false ;
982
982
}
983
983
984
- private Task < bool > OpenNamedPipeAsync ( ConnectionSettings cs , IOBehavior ioBehavior , CancellationToken cancellationToken )
984
+ #if NET45 || NETSTANDARD1_3
985
+ #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
986
+ #endif
987
+ private async Task < bool > OpenNamedPipeAsync ( ConnectionSettings cs , int startTickCount , IOBehavior ioBehavior , CancellationToken cancellationToken )
988
+ #if NET45 || NETSTANDARD1_3Co
989
+ #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
990
+ #endif
985
991
{
986
992
#if NETSTANDARD1_3
987
993
throw new NotSupportedException( "Named pipe connections are not supported in netstandard1.3" ) ;
988
994
#else
989
995
if ( Log . IsInfoEnabled ( ) )
990
996
Log . Info ( "Session{0} connecting to NamedPipe '{1}' on Server '{2}'" , m_logArguments [ 0 ] , cs . PipeName , cs . HostNames ! [ 0 ] ) ;
991
997
var namedPipeStream = new NamedPipeClientStream ( cs . HostNames ! [ 0 ] , cs . PipeName , PipeDirection . InOut , PipeOptions . Asynchronous ) ;
998
+ var timeout = Math . Max ( 1 , cs . ConnectionTimeoutMilliseconds - unchecked ( Environment . TickCount - startTickCount ) ) ;
992
999
try
993
1000
{
994
1001
using ( cancellationToken . Register ( ( ) => namedPipeStream . Dispose ( ) ) )
995
1002
{
996
1003
try
997
1004
{
998
- namedPipeStream . Connect ( ) ;
1005
+ #if ! NET45
1006
+ if ( ioBehavior == IOBehavior . Asynchronous )
1007
+ await namedPipeStream . ConnectAsync ( timeout , cancellationToken ) . ConfigureAwait ( false ) ;
1008
+ else
1009
+ #endif
1010
+ namedPipeStream . Connect ( timeout ) ;
999
1011
}
1000
- catch ( ObjectDisposedException ex ) when ( cancellationToken . IsCancellationRequested )
1012
+ catch ( Exception ex ) when ( ( ex is ObjectDisposedException && cancellationToken . IsCancellationRequested ) || ex is TimeoutException )
1001
1013
{
1002
1014
m_logArguments [ 1 ] = cs . PipeName ;
1003
1015
Log . Info ( "Session{0} connect timeout expired connecting to named pipe '{1}'" , m_logArguments ) ;
@@ -1016,10 +1028,10 @@ private Task<bool> OpenNamedPipeAsync(ConnectionSettings cs, IOBehavior ioBehavi
1016
1028
1017
1029
lock ( m_lock )
1018
1030
m_state = State . Connected ;
1019
- return Task . FromResult ( true ) ;
1031
+ return true ;
1020
1032
}
1021
1033
1022
- return Task . FromResult ( false ) ;
1034
+ return false ;
1023
1035
#endif
1024
1036
}
1025
1037
0 commit comments