@@ -23,7 +23,7 @@ namespace MySqlConnector.Core;
23
23
24
24
#pragma warning disable CA1001 // Types that own disposable fields should be disposable
25
25
26
- internal sealed partial class ServerSession
26
+ internal sealed partial class ServerSession : IServerCapabilities
27
27
{
28
28
public ServerSession ( ILogger logger )
29
29
: this ( logger , null , 0 , Interlocked . Increment ( ref s_lastId ) )
@@ -44,7 +44,6 @@ public ServerSession(ILogger logger, ConnectionPool? pool, int poolGeneration, i
44
44
m_activityTags = [ ] ;
45
45
DataReader = new ( ) ;
46
46
Log . CreatedNewSession ( m_logger , Id ) ;
47
- Context = new Context ( default ) ;
48
47
}
49
48
50
49
public string Id { get ; }
@@ -60,13 +59,14 @@ public ServerSession(ILogger logger, ConnectionPool? pool, int poolGeneration, i
60
59
public long LastLeasedTimestamp { get ; set ; }
61
60
public long LastReturnedTimestamp { get ; private set ; }
62
61
public string ? DatabaseOverride { get ; set ; }
63
-
64
62
public string HostName { get ; private set ; }
65
63
public IPEndPoint ? IPEndPoint => m_tcpClient ? . Client . RemoteEndPoint as IPEndPoint ;
66
64
public string ? UserID { get ; private set ; }
67
65
public WeakReference < MySqlConnection > ? OwningConnection { get ; set ; }
68
- public Context Context { get ; private set ; }
69
-
66
+ public bool SupportsDeprecateEof { get ; private set ; }
67
+ public bool SupportsCachedPreparedMetadata { get ; private set ; }
68
+ public bool SupportsQueryAttributes { get ; private set ; }
69
+ public bool SupportsSessionTrack { get ; private set ; }
70
70
public bool ProcAccessDenied { get ; set ; }
71
71
public ICollection < KeyValuePair < string , object ? > > ActivityTags => m_activityTags ;
72
72
public MySqlDataReader DataReader { get ; set ; }
@@ -241,7 +241,7 @@ public async Task PrepareAsync(IMySqlCommand command, IOBehavior ioBehavior, Can
241
241
ColumnDefinitionPayload . Initialize ( ref parameters [ i ] , new ( columnsAndParameters , columnsAndParametersSize , payloadLength ) ) ;
242
242
columnsAndParametersSize += payloadLength ;
243
243
}
244
- if ( ! Context . SupportsDeprecateEof )
244
+ if ( ! SupportsDeprecateEof )
245
245
{
246
246
payload = await ReceiveReplyAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
247
247
EofPayload . Create ( payload . Span ) ;
@@ -261,7 +261,7 @@ public async Task PrepareAsync(IMySqlCommand command, IOBehavior ioBehavior, Can
261
261
ColumnDefinitionPayload . Initialize ( ref columns [ i ] , new ( columnsAndParameters , columnsAndParametersSize , payloadLength ) ) ;
262
262
columnsAndParametersSize += payloadLength ;
263
263
}
264
- if ( ! Context . SupportsDeprecateEof )
264
+ if ( ! SupportsDeprecateEof )
265
265
{
266
266
payload = await ReceiveReplyAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
267
267
EofPayload . Create ( payload . Span ) ;
@@ -315,12 +315,12 @@ public void FinishQuerying()
315
315
// In order to handle this case, we issue a dummy query that will consume the pending cancellation.
316
316
// See https://bugs.mysql.com/bug.php?id=45679
317
317
Log . SendingSleepToClearPendingCancellation ( m_logger , Id ) ;
318
- var payload = Context . SupportsQueryAttributes ? s_sleepWithAttributesPayload : s_sleepNoAttributesPayload ;
318
+ var payload = SupportsQueryAttributes ? s_sleepWithAttributesPayload : s_sleepNoAttributesPayload ;
319
319
#pragma warning disable CA2012 // Safe because method completes synchronously
320
320
SendAsync ( payload , IOBehavior . Synchronous , CancellationToken . None ) . GetAwaiter ( ) . GetResult ( ) ;
321
321
payload = ReceiveReplyAsync ( IOBehavior . Synchronous , CancellationToken . None ) . GetAwaiter ( ) . GetResult ( ) ;
322
322
#pragma warning restore CA2012
323
- OkPayload . Verify ( payload . Span , Context ) ;
323
+ OkPayload . Verify ( payload . Span , this ) ;
324
324
}
325
325
326
326
lock ( m_lock )
@@ -455,7 +455,6 @@ public async Task DisposeAsync(IOBehavior ioBehavior, CancellationToken cancella
455
455
456
456
ServerVersion = new ( initialHandshake . ServerVersion ) ;
457
457
ConnectionId = initialHandshake . ConnectionId ;
458
- Context = new Context ( initialHandshake . ProtocolCapabilities ) ;
459
458
AuthPluginData = initialHandshake . AuthPluginData ;
460
459
m_useCompression = cs . UseCompression && ( initialHandshake . ProtocolCapabilities & ProtocolCapabilities . Compress ) != 0 ;
461
460
CancellationTimeout = cs . CancellationTimeout ;
@@ -470,11 +469,15 @@ public async Task DisposeAsync(IOBehavior ioBehavior, CancellationToken cancella
470
469
}
471
470
472
471
m_supportsConnectionAttributes = ( initialHandshake . ProtocolCapabilities & ProtocolCapabilities . ConnectionAttributes ) != 0 ;
472
+ SupportsDeprecateEof = ( initialHandshake . ProtocolCapabilities & ProtocolCapabilities . DeprecateEof ) != 0 ;
473
+ SupportsCachedPreparedMetadata = ( initialHandshake . ProtocolCapabilities & ProtocolCapabilities . MariaDbCacheMetadata ) != 0 ;
474
+ SupportsQueryAttributes = ( initialHandshake . ProtocolCapabilities & ProtocolCapabilities . QueryAttributes ) != 0 ;
475
+ SupportsSessionTrack = ( initialHandshake . ProtocolCapabilities & ProtocolCapabilities . SessionTrack ) != 0 ;
473
476
var serverSupportsSsl = ( initialHandshake . ProtocolCapabilities & ProtocolCapabilities . Ssl ) != 0 ;
474
477
m_characterSet = ServerVersion . Version >= ServerVersions . SupportsUtf8Mb4 ? CharacterSet . Utf8Mb4GeneralCaseInsensitive : CharacterSet . Utf8Mb3GeneralCaseInsensitive ;
475
478
m_setNamesPayload = ServerVersion . Version >= ServerVersions . SupportsUtf8Mb4 ?
476
- ( Context . SupportsQueryAttributes ? s_setNamesUtf8mb4WithAttributesPayload : s_setNamesUtf8mb4NoAttributesPayload ) :
477
- ( Context . SupportsQueryAttributes ? s_setNamesUtf8WithAttributesPayload : s_setNamesUtf8NoAttributesPayload ) ;
479
+ ( SupportsQueryAttributes ? s_setNamesUtf8mb4WithAttributesPayload : s_setNamesUtf8mb4NoAttributesPayload ) :
480
+ ( SupportsQueryAttributes ? s_setNamesUtf8WithAttributesPayload : s_setNamesUtf8NoAttributesPayload ) ;
478
481
479
482
// disable pipelining for RDS MySQL 5.7 (assuming Aurora); otherwise take it from the connection string or default to true
480
483
if ( ! cs . Pipelining . HasValue && ServerVersion . Version . Major == 5 && ServerVersion . Version . Minor == 7 && HostName . EndsWith ( ".rds.amazonaws.com" , StringComparison . OrdinalIgnoreCase ) )
@@ -502,7 +505,7 @@ public async Task DisposeAsync(IOBehavior ioBehavior, CancellationToken cancella
502
505
}
503
506
}
504
507
505
- Log . SessionMadeConnection ( m_logger , Id , ServerVersion . OriginalString , ConnectionId , m_useCompression , m_supportsConnectionAttributes , Context . SupportsDeprecateEof , Context . SupportsCachedPreparedMetadata , serverSupportsSsl , Context . SupportsSessionTrack , m_supportsPipelining , Context . SupportsQueryAttributes ) ;
508
+ Log . SessionMadeConnection ( m_logger , Id , ServerVersion . OriginalString , ConnectionId , m_useCompression , m_supportsConnectionAttributes , SupportsDeprecateEof , SupportsCachedPreparedMetadata , serverSupportsSsl , SupportsSessionTrack , m_supportsPipelining , SupportsQueryAttributes ) ;
506
509
507
510
if ( cs . SslMode != MySqlSslMode . None && ( cs . SslMode != MySqlSslMode . Preferred || serverSupportsSsl ) )
508
511
{
@@ -529,7 +532,7 @@ public async Task DisposeAsync(IOBehavior ioBehavior, CancellationToken cancella
529
532
payload = await SwitchAuthenticationAsync ( cs , password , payload , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
530
533
}
531
534
532
- var ok = OkPayload . Create ( payload . Span , Context ) ;
535
+ var ok = OkPayload . Create ( payload . Span , this ) ;
533
536
var statusInfo = ok . StatusInfo ;
534
537
535
538
if ( m_useCompression )
@@ -540,7 +543,7 @@ public async Task DisposeAsync(IOBehavior ioBehavior, CancellationToken cancella
540
543
// set 'collation_connection' to the server default
541
544
await SendAsync ( m_setNamesPayload , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
542
545
payload = await ReceiveReplyAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
543
- OkPayload . Verify ( payload . Span , Context ) ;
546
+ OkPayload . Verify ( payload . Span , this ) ;
544
547
}
545
548
546
549
if ( ShouldGetRealServerDetails ( cs ) )
@@ -591,18 +594,18 @@ public async Task<bool> TryResetConnectionAsync(ConnectionSettings cs, MySqlConn
591
594
592
595
// read two OK replies
593
596
payload = await ReceiveReplyAsync ( 1 , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
594
- OkPayload . Verify ( payload . Span , Context ) ;
597
+ OkPayload . Verify ( payload . Span , this ) ;
595
598
596
599
payload = await ReceiveReplyAsync ( 1 , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
597
- OkPayload . Verify ( payload . Span , Context ) ;
600
+ OkPayload . Verify ( payload . Span , this ) ;
598
601
599
602
return true ;
600
603
}
601
604
602
605
Log . SendingResetConnectionRequest ( m_logger , Id , ServerVersion . OriginalString ) ;
603
606
await SendAsync ( ResetConnectionPayload . Instance , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
604
607
payload = await ReceiveReplyAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
605
- OkPayload . Verify ( payload . Span , Context ) ;
608
+ OkPayload . Verify ( payload . Span , this ) ;
606
609
}
607
610
else
608
611
{
@@ -626,13 +629,13 @@ public async Task<bool> TryResetConnectionAsync(ConnectionSettings cs, MySqlConn
626
629
Log . OptimisticReauthenticationFailed ( m_logger , Id ) ;
627
630
payload = await SwitchAuthenticationAsync ( cs , password , payload , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
628
631
}
629
- OkPayload . Verify ( payload . Span , Context ) ;
632
+ OkPayload . Verify ( payload . Span , this ) ;
630
633
}
631
634
632
635
// set 'collation_connection' to the server default
633
636
await SendAsync ( m_setNamesPayload , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
634
637
payload = await ReceiveReplyAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
635
- OkPayload . Verify ( payload . Span , Context ) ;
638
+ OkPayload . Verify ( payload . Span , this ) ;
636
639
637
640
return true ;
638
641
}
@@ -691,7 +694,7 @@ private async Task<PayloadData> SwitchAuthenticationAsync(ConnectionSettings cs,
691
694
payload = await ReceiveReplyAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
692
695
693
696
// OK payload can be sent immediately (e.g., if password is empty) bypassing even the fast authentication path
694
- if ( OkPayload . IsOk ( payload . Span , Context ) )
697
+ if ( OkPayload . IsOk ( payload . Span , this ) )
695
698
return payload ;
696
699
697
700
var cachingSha2ServerResponsePayload = CachingSha2ServerResponsePayload . Create ( payload . Span ) ;
@@ -831,7 +834,7 @@ public async ValueTask<bool> TryPingAsync(bool logInfo, IOBehavior ioBehavior, C
831
834
Log . PingingServer ( m_logger , Id ) ;
832
835
await SendAsync ( PingPayload . Instance , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
833
836
var payload = await ReceiveReplyAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
834
- OkPayload . Verify ( payload . Span , Context ) ;
837
+ OkPayload . Verify ( payload . Span , this ) ;
835
838
Log . SuccessfullyPingedServer ( m_logger , logInfo ? LogLevel . Information : LogLevel . Trace , Id ) ;
836
839
return true ;
837
840
}
@@ -1639,7 +1642,7 @@ private async Task GetRealServerDetailsAsync(IOBehavior ioBehavior, Cancellation
1639
1642
Log . DetectedProxy ( m_logger , Id ) ;
1640
1643
try
1641
1644
{
1642
- var payload = Context . SupportsQueryAttributes ? s_selectConnectionIdVersionWithAttributesPayload : s_selectConnectionIdVersionNoAttributesPayload ;
1645
+ var payload = SupportsQueryAttributes ? s_selectConnectionIdVersionWithAttributesPayload : s_selectConnectionIdVersionNoAttributesPayload ;
1643
1646
await SendAsync ( payload , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
1644
1647
1645
1648
// column count: 2
@@ -1649,7 +1652,7 @@ private async Task GetRealServerDetailsAsync(IOBehavior ioBehavior, Cancellation
1649
1652
_ = await ReceiveReplyAsync ( ioBehavior , CancellationToken . None ) . ConfigureAwait ( false ) ;
1650
1653
_ = await ReceiveReplyAsync ( ioBehavior , CancellationToken . None ) . ConfigureAwait ( false ) ;
1651
1654
1652
- if ( ! Context . SupportsDeprecateEof )
1655
+ if ( ! SupportsDeprecateEof )
1653
1656
{
1654
1657
payload = await ReceiveReplyAsync ( ioBehavior , CancellationToken . None ) . ConfigureAwait ( false ) ;
1655
1658
_ = EofPayload . Create ( payload . Span ) ;
@@ -1669,8 +1672,8 @@ static void ReadRow(ReadOnlySpan<byte> span, out int? connectionId, out ServerVe
1669
1672
1670
1673
// OK/EOF payload
1671
1674
payload = await ReceiveReplyAsync ( ioBehavior , CancellationToken . None ) . ConfigureAwait ( false ) ;
1672
- if ( OkPayload . IsOk ( payload . Span , Context ) )
1673
- OkPayload . Verify ( payload . Span , Context ) ;
1675
+ if ( OkPayload . IsOk ( payload . Span , this ) )
1676
+ OkPayload . Verify ( payload . Span , this ) ;
1674
1677
else
1675
1678
EofPayload . Create ( payload . Span ) ;
1676
1679
0 commit comments