From 9166de8a9c7e2b38d6f35e1cf1b2b56436741c69 Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Mon, 12 May 2025 17:56:40 -0500 Subject: [PATCH 01/26] Move all SNI files to common project --- .../src/Microsoft.Data.SqlClient.csproj | 77 ++++++++++++++----- .../ConcurrentQueueSemaphore.netcore.cs} | 0 .../ManagedSni/LocalDB.netcore.Unix.cs} | 0 .../ManagedSni/LocalDB.netcore.Windows.cs} | 0 .../ManagedSni/SNICommon.netcore.cs} | 0 .../SqlClient/ManagedSni/SNIError.netcore.cs} | 0 .../ManagedSni/SNIHandle.netcore.cs} | 0 .../ManagedSni/SNILoadHandle.netcore.cs} | 0 .../ManagedSni/SNIMarsConnection.netcore.cs} | 0 .../ManagedSni/SNIMarsHandle.netcore.cs} | 0 .../ManagedSni/SNINpHandle.netcore.cs} | 0 .../ManagedSni/SNIPacket.netcore.cs} | 0 .../ManagedSni/SNIPhysicalHandle.netcore.cs} | 0 .../SqlClient/ManagedSni/SNIProxy.netcore.cs} | 0 .../SNIStreams.ValueTask.netcore.cs} | 0 .../ManagedSni/SNIStreams.netcore.cs} | 0 .../ManagedSni/SNITcpHandle.netcore.cs} | 0 .../SqlClient/ManagedSni/SSRP.netcore.cs} | 0 .../SslOverTdsStream.NetCoreApp.cs | 0 .../ManagedSni/SslOverTdsStream.netcore.cs} | 0 20 files changed, 58 insertions(+), 19 deletions(-) rename src/Microsoft.Data.SqlClient/{netcore/src/Microsoft/Data/SqlClient/SNI/ConcurrentQueueSemaphore.cs => src/Microsoft/Data/SqlClient/ManagedSni/ConcurrentQueueSemaphore.netcore.cs} (100%) rename src/Microsoft.Data.SqlClient/{netcore/src/Microsoft/Data/SqlClient/SNI/LocalDB.Unix.cs => src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Unix.cs} (100%) rename src/Microsoft.Data.SqlClient/{netcore/src/Microsoft/Data/SqlClient/SNI/LocalDB.Windows.cs => src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Windows.cs} (100%) rename src/Microsoft.Data.SqlClient/{netcore/src/Microsoft/Data/SqlClient/SNI/SNICommon.cs => src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs} (100%) rename src/Microsoft.Data.SqlClient/{netcore/src/Microsoft/Data/SqlClient/SNI/SNIError.cs => src/Microsoft/Data/SqlClient/ManagedSni/SNIError.netcore.cs} (100%) rename src/Microsoft.Data.SqlClient/{netcore/src/Microsoft/Data/SqlClient/SNI/SNIHandle.cs => src/Microsoft/Data/SqlClient/ManagedSni/SNIHandle.netcore.cs} (100%) rename src/Microsoft.Data.SqlClient/{netcore/src/Microsoft/Data/SqlClient/SNI/SNILoadHandle.cs => src/Microsoft/Data/SqlClient/ManagedSni/SNILoadHandle.netcore.cs} (100%) rename src/Microsoft.Data.SqlClient/{netcore/src/Microsoft/Data/SqlClient/SNI/SNIMarsConnection.cs => src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsConnection.netcore.cs} (100%) rename src/Microsoft.Data.SqlClient/{netcore/src/Microsoft/Data/SqlClient/SNI/SNIMarsHandle.cs => src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsHandle.netcore.cs} (100%) rename src/Microsoft.Data.SqlClient/{netcore/src/Microsoft/Data/SqlClient/SNI/SNINpHandle.cs => src/Microsoft/Data/SqlClient/ManagedSni/SNINpHandle.netcore.cs} (100%) rename src/Microsoft.Data.SqlClient/{netcore/src/Microsoft/Data/SqlClient/SNI/SNIPacket.cs => src/Microsoft/Data/SqlClient/ManagedSni/SNIPacket.netcore.cs} (100%) rename src/Microsoft.Data.SqlClient/{netcore/src/Microsoft/Data/SqlClient/SNI/SNIPhysicalHandle.cs => src/Microsoft/Data/SqlClient/ManagedSni/SNIPhysicalHandle.netcore.cs} (100%) rename src/Microsoft.Data.SqlClient/{netcore/src/Microsoft/Data/SqlClient/SNI/SNIProxy.cs => src/Microsoft/Data/SqlClient/ManagedSni/SNIProxy.netcore.cs} (100%) rename src/Microsoft.Data.SqlClient/{netcore/src/Microsoft/Data/SqlClient/SNI/SNIStreams.ValueTask.cs => src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.ValueTask.netcore.cs} (100%) rename src/Microsoft.Data.SqlClient/{netcore/src/Microsoft/Data/SqlClient/SNI/SNIStreams.cs => src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.netcore.cs} (100%) rename src/Microsoft.Data.SqlClient/{netcore/src/Microsoft/Data/SqlClient/SNI/SNITcpHandle.cs => src/Microsoft/Data/SqlClient/ManagedSni/SNITcpHandle.netcore.cs} (100%) rename src/Microsoft.Data.SqlClient/{netcore/src/Microsoft/Data/SqlClient/SNI/SSRP.cs => src/Microsoft/Data/SqlClient/ManagedSni/SSRP.netcore.cs} (100%) rename src/Microsoft.Data.SqlClient/{netcore/src/Microsoft/Data/SqlClient/SNI => src/Microsoft/Data/SqlClient/ManagedSni}/SslOverTdsStream.NetCoreApp.cs (100%) rename src/Microsoft.Data.SqlClient/{netcore/src/Microsoft/Data/SqlClient/SNI/SslOverTdsStream.cs => src/Microsoft/Data/SqlClient/ManagedSni/SslOverTdsStream.netcore.cs} (100%) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index 1f81fe403f..86fb4d5be1 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -272,6 +272,57 @@ Microsoft\Data\SqlClient\LocalAppContextSwitches.cs + + Microsoft\Data\SqlClient\ManagedSni\ConcurrentQueueSemaphore.netcore.cs + + + Microsoft\Data\SqlClient\ManagedSni\SNIError.netcore.cs + + + Microsoft\Data\SqlClient\ManagedSni\SNICommon.netcore.cs + + + Microsoft\Data\SqlClient\ManagedSni\SNIHandle.netcore.cs + + + Microsoft\Data\SqlClient\ManagedSni\SNILoadHandle.netcore.cs + + + Microsoft\Data\SqlClient\ManagedSni\SNIMarsConnection.netcore.cs + + + Microsoft\Data\SqlClient\ManagedSni\SNIMarsHandle.netcore.cs + + + Microsoft\Data\SqlClient\ManagedSni\SNINpHandle.netcore.cs + + + Microsoft\Data\SqlClient\ManagedSni\SNIPacket.netcore.cs + + + Microsoft\Data\SqlClient\ManagedSni\SNIPhysicalHandle.netcore.cs + + + Microsoft\Data\SqlClient\ManagedSni\SNIProxy.netcore.cs + + + Microsoft\Data\SqlClient\ManagedSni\SNIStream.netcore.cs + + + Microsoft\Data\SqlClient\ManagedSni\SNIStreams.ValueTask.netcore.cs + + + Microsoft\Data\SqlClient\ManagedSni\SNITcpHandle.netcore.cs + + + Microsoft\Data\SqlClient\ManagedSni\SslOverTdsStream.netcore.cs + + + Microsoft\Data\SqlClient\ManagedSni\SslOverTdsStream.NetCoreApp.cs + + + Microsoft\Data\SqlClient\ManagedSni\SSRP.netcore.cs + Microsoft\Data\SqlClient\NoneAttestationEnclaveProvider.cs @@ -728,24 +779,8 @@ System\Diagnostics\CodeAnalysis.cs + - - - - - - - - - - - - - - - - - @@ -878,6 +913,9 @@ Microsoft\Data\SqlClient\LocalDb\LocalDbApi.Windows.cs + + Microsoft\Data\SqlClient\ManagedSni\LocalDB.netcore.Windows.cs + Microsoft\Data\SqlClient\PacketHandle.netcore.Windows.cs @@ -906,7 +944,6 @@ Microsoft\Data\SqlTypes\SqlFileStream.Windows.cs - @@ -925,6 +962,9 @@ Microsoft\Data\SqlClient\LocalDb\LocalDbApi.Unix.cs + + Microsoft\Data\SqlClient\ManagedSni\LocalDB.netcore.Unix.cs + Microsoft\Data\SqlClient\PacketHandle.netcore.Unix.cs @@ -947,7 +987,6 @@ Microsoft\Data\SqlTypes\SqlFileStream.netcore.Unix.cs - diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/ConcurrentQueueSemaphore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/ConcurrentQueueSemaphore.netcore.cs similarity index 100% rename from src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/ConcurrentQueueSemaphore.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/ConcurrentQueueSemaphore.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/LocalDB.Unix.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Unix.cs similarity index 100% rename from src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/LocalDB.Unix.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Unix.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/LocalDB.Windows.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Windows.cs similarity index 100% rename from src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/LocalDB.Windows.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Windows.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNICommon.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs similarity index 100% rename from src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNICommon.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIError.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIError.netcore.cs similarity index 100% rename from src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIError.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIError.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIHandle.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIHandle.netcore.cs similarity index 100% rename from src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIHandle.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIHandle.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNILoadHandle.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNILoadHandle.netcore.cs similarity index 100% rename from src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNILoadHandle.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNILoadHandle.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIMarsConnection.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsConnection.netcore.cs similarity index 100% rename from src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIMarsConnection.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsConnection.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIMarsHandle.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsHandle.netcore.cs similarity index 100% rename from src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIMarsHandle.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsHandle.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNINpHandle.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNINpHandle.netcore.cs similarity index 100% rename from src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNINpHandle.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNINpHandle.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIPacket.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPacket.netcore.cs similarity index 100% rename from src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIPacket.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPacket.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIPhysicalHandle.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPhysicalHandle.netcore.cs similarity index 100% rename from src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIPhysicalHandle.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPhysicalHandle.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIProxy.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIProxy.netcore.cs similarity index 100% rename from src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIProxy.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIProxy.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIStreams.ValueTask.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.ValueTask.netcore.cs similarity index 100% rename from src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIStreams.ValueTask.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.ValueTask.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIStreams.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.netcore.cs similarity index 100% rename from src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIStreams.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNITcpHandle.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNITcpHandle.netcore.cs similarity index 100% rename from src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNITcpHandle.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNITcpHandle.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SSRP.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SSRP.netcore.cs similarity index 100% rename from src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SSRP.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SSRP.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SslOverTdsStream.NetCoreApp.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SslOverTdsStream.NetCoreApp.cs similarity index 100% rename from src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SslOverTdsStream.NetCoreApp.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SslOverTdsStream.NetCoreApp.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SslOverTdsStream.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SslOverTdsStream.netcore.cs similarity index 100% rename from src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SslOverTdsStream.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SslOverTdsStream.netcore.cs From a24243e3c70e95da78bb3c03f7861733ffa884dd Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Mon, 12 May 2025 18:31:21 -0500 Subject: [PATCH 02/26] Move all managed SNI classes to ManagedSni namespace --- .../src/Microsoft/Data/SqlClient/TdsParser.Unix.cs | 2 +- .../src/Microsoft/Data/SqlClient/TdsParser.Windows.cs | 2 +- .../Data/SqlClient/TdsParserStateObjectManaged.cs | 5 ++--- .../ManagedSni/ConcurrentQueueSemaphore.netcore.cs | 3 +-- .../Data/SqlClient/ManagedSni/LocalDB.netcore.Unix.cs | 2 +- .../SqlClient/ManagedSni/LocalDB.netcore.Windows.cs | 3 +-- .../Data/SqlClient/ManagedSni/SNICommon.netcore.cs | 4 +--- .../Data/SqlClient/ManagedSni/SNIError.netcore.cs | 2 +- .../Data/SqlClient/ManagedSni/SNIHandle.netcore.cs | 2 +- .../Data/SqlClient/ManagedSni/SNILoadHandle.netcore.cs | 2 +- .../SqlClient/ManagedSni/SNIMarsConnection.netcore.cs | 2 +- .../Data/SqlClient/ManagedSni/SNIMarsHandle.netcore.cs | 2 +- .../Data/SqlClient/ManagedSni/SNINpHandle.netcore.cs | 2 +- .../Data/SqlClient/ManagedSni/SNIPacket.netcore.cs | 2 +- .../SqlClient/ManagedSni/SNIPhysicalHandle.netcore.cs | 2 +- .../Data/SqlClient/ManagedSni/SNIProxy.netcore.cs | 5 +---- .../ManagedSni/SNIStreams.ValueTask.netcore.cs | 2 +- .../Data/SqlClient/ManagedSni/SNIStreams.netcore.cs | 2 +- .../Data/SqlClient/ManagedSni/SNITcpHandle.netcore.cs | 2 +- .../Data/SqlClient/ManagedSni/SSRP.netcore.cs | 2 +- .../ManagedSni/SslOverTdsStream.NetCoreApp.cs | 2 +- .../SqlClient/ManagedSni/SslOverTdsStream.netcore.cs | 2 +- .../Data/SqlClient/PacketHandle.netcore.Unix.cs | 6 +++--- .../Data/SqlClient/PacketHandle.netcore.Windows.cs | 6 +++--- .../Data/SqlClient/SessionHandle.netcore.Unix.cs | 7 ++++--- .../Data/SqlClient/SessionHandle.netcore.Windows.cs | 10 ++++++---- .../Data/SqlClient/TdsParserStateObjectFactory.Unix.cs | 8 ++++---- .../SqlClient/TdsParserStateObjectFactory.Windows.cs | 10 +++++----- 28 files changed, 48 insertions(+), 53 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Unix.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Unix.cs index 2f242a083f..7ec1025c3e 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Unix.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Unix.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Data.SqlClient.SNI; +using Microsoft.Data.SqlClient.ManagedSni; namespace Microsoft.Data.SqlClient { diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Windows.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Windows.cs index de4bcb1338..b6a12020b8 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Windows.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Windows.cs @@ -5,7 +5,7 @@ using System; using System.Diagnostics; using Interop.Windows.Sni; -using Microsoft.Data.SqlClient.SNI; +using Microsoft.Data.SqlClient.ManagedSni; namespace Microsoft.Data.SqlClient { diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs index e6dddc79f9..6b6a0ba3a9 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs @@ -7,15 +7,14 @@ using System; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; -using System.Net.Security; using System.Runtime.CompilerServices; -using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.Data.Common; using Microsoft.Data.ProviderBase; -namespace Microsoft.Data.SqlClient.SNI +// @TODO: If this is in the manages SNI namespace, it should be in the managed SNI folder +namespace Microsoft.Data.SqlClient.ManagedSni { internal sealed class TdsParserStateObjectManaged : TdsParserStateObject { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/ConcurrentQueueSemaphore.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/ConcurrentQueueSemaphore.netcore.cs index 46d3b70a25..83f4dbeaa3 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/ConcurrentQueueSemaphore.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/ConcurrentQueueSemaphore.netcore.cs @@ -2,12 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; using System.Collections.Concurrent; using System.Threading; using System.Threading.Tasks; -namespace Microsoft.Data.SqlClient.SNI +namespace Microsoft.Data.SqlClient.ManagedSni { /// /// This class implements a FIFO Queue with SemaphoreSlim for ordered execution of parallel tasks. diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Unix.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Unix.cs index a9b235d47c..e151e0b57f 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Unix.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Unix.cs @@ -4,7 +4,7 @@ using System; -namespace Microsoft.Data.SqlClient.SNI +namespace Microsoft.Data.SqlClient.ManagedSni { internal class LocalDB { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Windows.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Windows.cs index 6f8e855542..b945becb6e 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Windows.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Windows.cs @@ -9,8 +9,7 @@ using Interop.Windows.Kernel32; using Microsoft.Win32; - -namespace Microsoft.Data.SqlClient.SNI +namespace Microsoft.Data.SqlClient.ManagedSni { internal sealed class LocalDB { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs index 0f98b34673..11e66bc647 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs @@ -10,11 +10,9 @@ using System.Security.Cryptography.X509Certificates; using System.Text; using Microsoft.Data.Common; -using System.Threading; -using System.Threading.Tasks; using Microsoft.Data.ProviderBase; -namespace Microsoft.Data.SqlClient.SNI +namespace Microsoft.Data.SqlClient.ManagedSni { /// /// SNI Asynchronous callback diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIError.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIError.netcore.cs index 080e274f94..fd62a51bc4 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIError.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIError.netcore.cs @@ -4,7 +4,7 @@ using System; -namespace Microsoft.Data.SqlClient.SNI +namespace Microsoft.Data.SqlClient.ManagedSni { /// /// SNI error diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIHandle.netcore.cs index 515686f6a3..61de004ce8 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIHandle.netcore.cs @@ -10,7 +10,7 @@ using System.Threading; using System.Threading.Tasks; -namespace Microsoft.Data.SqlClient.SNI +namespace Microsoft.Data.SqlClient.ManagedSni { /// /// SNI connection handle diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNILoadHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNILoadHandle.netcore.cs index c1a5e1a573..2e169fa09f 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNILoadHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNILoadHandle.netcore.cs @@ -4,7 +4,7 @@ using System.Threading; -namespace Microsoft.Data.SqlClient.SNI +namespace Microsoft.Data.SqlClient.ManagedSni { /// /// Global SNI settings and status diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsConnection.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsConnection.netcore.cs index f929a1ba32..ed46fb0c42 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsConnection.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsConnection.netcore.cs @@ -7,7 +7,7 @@ using System.Diagnostics; using System.Threading; -namespace Microsoft.Data.SqlClient.SNI +namespace Microsoft.Data.SqlClient.ManagedSni { /// /// SNI MARS connection. Multiple MARS streams will be overlaid on this connection. diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsHandle.netcore.cs index b7f682f6d5..27da79c762 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsHandle.netcore.cs @@ -7,7 +7,7 @@ using System.Diagnostics; using System.Threading; -namespace Microsoft.Data.SqlClient.SNI +namespace Microsoft.Data.SqlClient.ManagedSni { /// /// MARS handle diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNINpHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNINpHandle.netcore.cs index 8f8af57f58..69aedd00e1 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNINpHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNINpHandle.netcore.cs @@ -12,7 +12,7 @@ using System.Threading; using Microsoft.Data.ProviderBase; -namespace Microsoft.Data.SqlClient.SNI +namespace Microsoft.Data.SqlClient.ManagedSni { /// /// Named Pipe connection handle diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPacket.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPacket.netcore.cs index fd542e542f..7e98ba4260 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPacket.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPacket.netcore.cs @@ -11,7 +11,7 @@ using System.Threading; using System.Threading.Tasks; -namespace Microsoft.Data.SqlClient.SNI +namespace Microsoft.Data.SqlClient.ManagedSni { /// /// SNI Packet diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPhysicalHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPhysicalHandle.netcore.cs index 1acc6a14c8..7b4fe4a868 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPhysicalHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPhysicalHandle.netcore.cs @@ -8,7 +8,7 @@ using System.Threading; using Microsoft.Data.SqlClient.Utilities; -namespace Microsoft.Data.SqlClient.SNI +namespace Microsoft.Data.SqlClient.ManagedSni { internal abstract class SNIPhysicalHandle : SNIHandle { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIProxy.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIProxy.netcore.cs index 265f80246c..24b973c50d 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIProxy.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIProxy.netcore.cs @@ -3,17 +3,14 @@ // See the LICENSE file in the project root for more information. using System; -using System.Buffers; -using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Net; -using System.Net.Security; using System.Net.Sockets; using System.Text; using Microsoft.Data.ProviderBase; -namespace Microsoft.Data.SqlClient.SNI +namespace Microsoft.Data.SqlClient.ManagedSni { /// /// Managed SNI proxy implementation. Contains many SNI entry points used by SqlClient. diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.ValueTask.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.ValueTask.netcore.cs index f5f38f0efe..34d6c034cf 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.ValueTask.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.ValueTask.netcore.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; using System; -namespace Microsoft.Data.SqlClient.SNI +namespace Microsoft.Data.SqlClient.ManagedSni { internal sealed partial class SNISslStream { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.netcore.cs index 389f25eeae..1e7509682d 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.netcore.cs @@ -6,7 +6,7 @@ using System.IO; using System.Net.Sockets; -namespace Microsoft.Data.SqlClient.SNI +namespace Microsoft.Data.SqlClient.ManagedSni { /// /// This class extends SslStream to customize stream behavior for Managed SNI implementation. diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNITcpHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNITcpHandle.netcore.cs index b3ecfb156a..15330be02d 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNITcpHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNITcpHandle.netcore.cs @@ -15,7 +15,7 @@ using Microsoft.Data.Common; using Microsoft.Data.ProviderBase; -namespace Microsoft.Data.SqlClient.SNI +namespace Microsoft.Data.SqlClient.ManagedSni { /// /// TCP connection handle diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SSRP.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SSRP.netcore.cs index 085551c16e..b16df0d3cf 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SSRP.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SSRP.netcore.cs @@ -12,7 +12,7 @@ using System.Threading.Tasks; using Microsoft.Data.ProviderBase; -namespace Microsoft.Data.SqlClient.SNI +namespace Microsoft.Data.SqlClient.ManagedSni { internal sealed class SSRP { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SslOverTdsStream.NetCoreApp.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SslOverTdsStream.NetCoreApp.cs index be8d1a0160..078dc47f0a 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SslOverTdsStream.NetCoreApp.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SslOverTdsStream.NetCoreApp.cs @@ -7,7 +7,7 @@ using System.Threading; using System.Threading.Tasks; -namespace Microsoft.Data.SqlClient.SNI +namespace Microsoft.Data.SqlClient.ManagedSni { internal sealed partial class SslOverTdsStream { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SslOverTdsStream.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SslOverTdsStream.netcore.cs index e0f48a28d3..52393fa8ab 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SslOverTdsStream.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SslOverTdsStream.netcore.cs @@ -6,7 +6,7 @@ using System.IO; using System.IO.Pipes; -namespace Microsoft.Data.SqlClient.SNI +namespace Microsoft.Data.SqlClient.ManagedSni { /// /// SSL encapsulated over TDS transport. During SSL handshake, SSL packets are diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PacketHandle.netcore.Unix.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PacketHandle.netcore.Unix.cs index 3ec188d79d..8e3089a919 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PacketHandle.netcore.Unix.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PacketHandle.netcore.Unix.cs @@ -22,16 +22,16 @@ internal readonly ref struct PacketHandle public const int NativePacketType = 2; public const int ManagedPacketType = 3; - public readonly SNI.SNIPacket ManagedPacket; + public readonly ManagedSni.SNIPacket ManagedPacket; public readonly int Type; - private PacketHandle(SNI.SNIPacket managedPacket, int type) + private PacketHandle(ManagedSni.SNIPacket managedPacket, int type) { Type = type; ManagedPacket = managedPacket; } - public static PacketHandle FromManagedPacket(SNI.SNIPacket managedPacket) => + public static PacketHandle FromManagedPacket(ManagedSni.SNIPacket managedPacket) => new PacketHandle(managedPacket, ManagedPacketType); } } diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PacketHandle.netcore.Windows.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PacketHandle.netcore.Windows.cs index aca8292100..9575db5d63 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PacketHandle.netcore.Windows.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PacketHandle.netcore.Windows.cs @@ -24,12 +24,12 @@ internal readonly ref struct PacketHandle public const int NativePacketType = 2; public const int ManagedPacketType = 3; - public readonly SNI.SNIPacket ManagedPacket; + public readonly ManagedSni.SNIPacket ManagedPacket; public readonly SNIPacket NativePacket; public readonly IntPtr NativePointer; public readonly int Type; - private PacketHandle(IntPtr nativePointer, SNIPacket nativePacket, SNI.SNIPacket managedPacket, int type) + private PacketHandle(IntPtr nativePointer, SNIPacket nativePacket, ManagedSni.SNIPacket managedPacket, int type) { Type = type; ManagedPacket = managedPacket; @@ -37,7 +37,7 @@ private PacketHandle(IntPtr nativePointer, SNIPacket nativePacket, SNI.SNIPacket NativePacket = nativePacket; } - public static PacketHandle FromManagedPacket(SNI.SNIPacket managedPacket) => + public static PacketHandle FromManagedPacket(ManagedSni.SNIPacket managedPacket) => new PacketHandle(default, default, managedPacket, ManagedPacketType); public static PacketHandle FromNativePointer(IntPtr nativePointer) => diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SessionHandle.netcore.Unix.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SessionHandle.netcore.Unix.cs index 72dc26f8f9..42092ddae5 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SessionHandle.netcore.Unix.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SessionHandle.netcore.Unix.cs @@ -19,10 +19,10 @@ internal readonly ref struct SessionHandle public const int NativeHandleType = 1; public const int ManagedHandleType = 2; - public readonly SNI.SNIHandle ManagedHandle; + public readonly ManagedSni.SNIHandle ManagedHandle; public readonly int Type; - public SessionHandle(SNI.SNIHandle managedHandle, int type) + public SessionHandle(ManagedSni.SNIHandle managedHandle, int type) { Type = type; ManagedHandle = managedHandle; @@ -30,7 +30,8 @@ public SessionHandle(SNI.SNIHandle managedHandle, int type) public bool IsNull => ManagedHandle is null; - public static SessionHandle FromManagedSession(SNI.SNIHandle managedSessionHandle) => new SessionHandle(managedSessionHandle, ManagedHandleType); + public static SessionHandle FromManagedSession(ManagedSni.SNIHandle managedSessionHandle) => + new SessionHandle(managedSessionHandle, ManagedHandleType); } } diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SessionHandle.netcore.Windows.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SessionHandle.netcore.Windows.cs index 015395bd6f..2f392f104e 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SessionHandle.netcore.Windows.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SessionHandle.netcore.Windows.cs @@ -19,12 +19,12 @@ internal readonly ref struct SessionHandle public const int NativeHandleType = 1; public const int ManagedHandleType = 2; - public readonly SNI.SNIHandle ManagedHandle; + public readonly ManagedSni.SNIHandle ManagedHandle; public readonly SNIHandle NativeHandle; public readonly int Type; - public SessionHandle(SNI.SNIHandle managedHandle, SNIHandle nativeHandle, int type) + public SessionHandle(ManagedSni.SNIHandle managedHandle, SNIHandle nativeHandle, int type) { Type = type; ManagedHandle = managedHandle; @@ -33,9 +33,11 @@ public SessionHandle(SNI.SNIHandle managedHandle, SNIHandle nativeHandle, int ty public bool IsNull => (Type == NativeHandleType) ? NativeHandle is null : ManagedHandle is null; - public static SessionHandle FromManagedSession(SNI.SNIHandle managedSessionHandle) => new SessionHandle(managedSessionHandle, default, ManagedHandleType); + public static SessionHandle FromManagedSession(ManagedSni.SNIHandle managedSessionHandle) => + new SessionHandle(managedSessionHandle, default, ManagedHandleType); - public static SessionHandle FromNativeHandle(SNIHandle nativeSessionHandle) => new SessionHandle(default, nativeSessionHandle, NativeHandleType); + public static SessionHandle FromNativeHandle(SNIHandle nativeSessionHandle) => + new SessionHandle(default, nativeSessionHandle, NativeHandleType); } } diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectFactory.Unix.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectFactory.Unix.cs index 86bc3013a9..c5fed558f7 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectFactory.Unix.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectFactory.Unix.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Data.SqlClient.SNI; +using Microsoft.Data.SqlClient.ManagedSni; namespace Microsoft.Data.SqlClient { @@ -13,14 +13,14 @@ internal sealed class TdsParserStateObjectFactory public static readonly TdsParserStateObjectFactory Singleton = new TdsParserStateObjectFactory(); - public EncryptionOptions EncryptionOptions => SNI.SNILoadHandle.SingletonInstance.Options; + public EncryptionOptions EncryptionOptions => ManagedSni.SNILoadHandle.SingletonInstance.Options; - public uint SNIStatus => SNI.SNILoadHandle.SingletonInstance.Status; + public uint SNIStatus => ManagedSni.SNILoadHandle.SingletonInstance.Status; /// /// Verify client encryption possibility. /// - public bool ClientOSEncryptionSupport => SNI.SNILoadHandle.SingletonInstance.ClientOSEncryptionSupport; + public bool ClientOSEncryptionSupport => ManagedSni.SNILoadHandle.SingletonInstance.ClientOSEncryptionSupport; public TdsParserStateObject CreateTdsParserStateObject(TdsParser parser) { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectFactory.Windows.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectFactory.Windows.cs index 3e849231ab..b6ad96ffd1 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectFactory.Windows.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectFactory.Windows.cs @@ -2,9 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System; #if NET -using Microsoft.Data.SqlClient.SNI; +using System; +using Microsoft.Data.SqlClient.ManagedSni; #endif namespace Microsoft.Data.SqlClient @@ -27,14 +27,14 @@ internal sealed class TdsParserStateObjectFactory public EncryptionOptions EncryptionOptions => #if NET - UseManagedSNI ? SNI.SNILoadHandle.SingletonInstance.Options : SNILoadHandle.SingletonInstance.Options; + UseManagedSNI ? ManagedSni.SNILoadHandle.SingletonInstance.Options : SNILoadHandle.SingletonInstance.Options; #else SNILoadHandle.SingletonInstance.Options; #endif public uint SNIStatus => #if NET - UseManagedSNI ? SNI.SNILoadHandle.SingletonInstance.Status : SNILoadHandle.SingletonInstance.Status; + UseManagedSNI ? ManagedSni.SNILoadHandle.SingletonInstance.Status : SNILoadHandle.SingletonInstance.Status; #else SNILoadHandle.SingletonInstance.Status; #endif @@ -44,7 +44,7 @@ internal sealed class TdsParserStateObjectFactory /// public bool ClientOSEncryptionSupport => #if NET - UseManagedSNI ? SNI.SNILoadHandle.SingletonInstance.ClientOSEncryptionSupport : SNILoadHandle.SingletonInstance.ClientOSEncryptionSupport; + UseManagedSNI ? ManagedSni.SNILoadHandle.SingletonInstance.ClientOSEncryptionSupport : SNILoadHandle.SingletonInstance.ClientOSEncryptionSupport; #else SNILoadHandle.SingletonInstance.ClientOSEncryptionSupport; #endif From 1b5f94bc86626819b050473ac9f236a555f184d6 Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Tue, 13 May 2025 11:49:37 -0500 Subject: [PATCH 03/26] SNIError => SniError --- .../netcore/src/Microsoft.Data.SqlClient.csproj | 4 ++-- .../src/Microsoft/Data/SqlClient/TdsParser.Unix.cs | 2 +- .../Microsoft/Data/SqlClient/TdsParser.Windows.cs | 5 +++-- .../ManagedSni/LocalDB.netcore.Windows.cs | 12 ++++++------ .../Data/SqlClient/ManagedSni/SNICommon.netcore.cs | 6 +++--- .../SqlClient/ManagedSni/SNILoadHandle.netcore.cs | 4 ++-- .../ManagedSni/SNIMarsConnection.netcore.cs | 2 +- .../SqlClient/ManagedSni/SNIMarsHandle.netcore.cs | 4 ++-- .../Data/SqlClient/ManagedSni/SNIPacket.netcore.cs | 6 +++--- .../Data/SqlClient/ManagedSni/SNIProxy.netcore.cs | 14 +++++++------- .../SqlClient/ManagedSni/SNITcpHandle.netcore.cs | 2 +- .../{SNIError.netcore.cs => SniError.netcore.cs} | 6 +++--- 12 files changed, 34 insertions(+), 33 deletions(-) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/{SNIError.netcore.cs => SniError.netcore.cs} (90%) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index 86fb4d5be1..e5c63a7d1c 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -275,8 +275,8 @@ Microsoft\Data\SqlClient\ManagedSni\ConcurrentQueueSemaphore.netcore.cs - - Microsoft\Data\SqlClient\ManagedSni\SNIError.netcore.cs + + Microsoft\Data\SqlClient\ManagedSni\SniError.netcore.cs Microsoft\Data\SqlClient\ManagedSni\SNICommon.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Unix.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Unix.cs index 7ec1025c3e..fbb341cef2 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Unix.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Unix.cs @@ -26,7 +26,7 @@ private void WaitForSSLHandShakeToComplete(ref uint error, ref int protocolVersi private SNIErrorDetails GetSniErrorDetails() { SNIErrorDetails details; - SNIError sniError = SNIProxy.Instance.GetLastError(); + SniError sniError = SNIProxy.Instance.GetLastError(); details.sniErrorNumber = sniError.sniError; details.errorMessage = sniError.errorMessage; details.nativeError = sniError.nativeError; diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Windows.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Windows.cs index b6a12020b8..12f793cff1 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Windows.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Windows.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using Interop.Windows.Sni; using Microsoft.Data.SqlClient.ManagedSni; +using SniError = Microsoft.Data.SqlClient.ManagedSni.SniError; namespace Microsoft.Data.SqlClient { @@ -68,7 +69,7 @@ private SNIErrorDetails GetSniErrorDetails() if (TdsParserStateObjectFactory.UseManagedSNI) { - SNIError sniError = SNIProxy.Instance.GetLastError(); + SniError sniError = SNIProxy.Instance.GetLastError(); details.sniErrorNumber = sniError.sniError; details.errorMessage = sniError.errorMessage; details.nativeError = sniError.nativeError; @@ -79,7 +80,7 @@ private SNIErrorDetails GetSniErrorDetails() } else { - SniNativeWrapper.SniGetLastError(out SniError sniError); + SniNativeWrapper.SniGetLastError(out Interop.Windows.Sni.SniError sniError); details.sniErrorNumber = sniError.sniError; details.errorMessage = sniError.errorMessage; details.nativeError = sniError.nativeError; diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Windows.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Windows.cs index b945becb6e..c88034e348 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Windows.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Windows.cs @@ -54,7 +54,7 @@ private string GetConnectionString(string localDbInstance) int result = localDBStartInstanceFunc(localDbInstance, 0, localDBConnectionString, ref sizeOfbuffer); if (result != TdsEnums.SNI_SUCCESS) { - SNILoadHandle.SingletonInstance.LastError = new SNIError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBErrorCode, Strings.SNI_ERROR_50); + SNILoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBErrorCode, Strings.SNI_ERROR_50); SqlClientEventSource.Log.TrySNITraceEvent(nameof(LocalDB), EventType.ERR, "Unsuccessful 'LocalDBStartInstance' method call with {0} result to start '{1}' localDb instance", args0: result, args1: localDbInstance); localDBConnectionString = null; } @@ -132,7 +132,7 @@ private bool LoadUserInstanceDll() // If there was no DLL path found, then there is an error. if (dllPath == null) { - SNILoadHandle.SingletonInstance.LastError = new SNIError(SNIProviders.INVALID_PROV, 0, MapLocalDBErrorStateToCode(registryQueryErrorState), MapLocalDBErrorStateToErrorMessage(registryQueryErrorState)); + SNILoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, MapLocalDBErrorStateToCode(registryQueryErrorState), MapLocalDBErrorStateToErrorMessage(registryQueryErrorState)); SqlClientEventSource.Log.TrySNITraceEvent(nameof(LocalDB), EventType.ERR, "User instance DLL path is null."); return false; } @@ -140,7 +140,7 @@ private bool LoadUserInstanceDll() // In case the registry had an empty path for dll if (string.IsNullOrWhiteSpace(dllPath)) { - SNILoadHandle.SingletonInstance.LastError = new SNIError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBInvalidSqlUserInstanceDllPath, Strings.SNI_ERROR_55); + SNILoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBInvalidSqlUserInstanceDllPath, Strings.SNI_ERROR_55); SqlClientEventSource.Log.TrySNITraceEvent(nameof(LocalDB), EventType.ERR, "User instance DLL path is invalid. DLL path = {0}", dllPath); return false; } @@ -150,7 +150,7 @@ private bool LoadUserInstanceDll() if (libraryHandle.IsInvalid) { - SNILoadHandle.SingletonInstance.LastError = new SNIError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBFailedToLoadDll, Strings.SNI_ERROR_56); + SNILoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBFailedToLoadDll, Strings.SNI_ERROR_56); SqlClientEventSource.Log.TrySNITraceEvent(nameof(LocalDB), EventType.ERR, "Library Handle is invalid. Could not load the dll."); libraryHandle.Dispose(); return false; @@ -161,7 +161,7 @@ private bool LoadUserInstanceDll() if (_startInstanceHandle == IntPtr.Zero) { - SNILoadHandle.SingletonInstance.LastError = new SNIError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBBadRuntime, Strings.SNI_ERROR_57); + SNILoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBBadRuntime, Strings.SNI_ERROR_57); SqlClientEventSource.Log.TrySNITraceEvent(nameof(LocalDB), EventType.ERR, "Was not able to load the PROC from DLL. Bad Runtime."); libraryHandle.Dispose(); return false; @@ -172,7 +172,7 @@ private bool LoadUserInstanceDll() if (localDBStartInstanceFunc == null) { - SNILoadHandle.SingletonInstance.LastError = new SNIError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBBadRuntime, Strings.SNI_ERROR_57); + SNILoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBBadRuntime, Strings.SNI_ERROR_57); libraryHandle.Dispose(); _startInstanceHandle = IntPtr.Zero; return false; diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs index 11e66bc647..46de1892c4 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs @@ -285,7 +285,7 @@ internal static IPAddress[] GetDnsIpAddresses(string serverName) internal static uint ReportSNIError(SNIProviders provider, uint nativeError, uint sniError, string errorMessage) { SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNICommon), EventType.ERR, "Provider = {0}, native Error = {1}, SNI Error = {2}, Error Message = {3}", args0: provider, args1: nativeError, args2: sniError, args3: errorMessage); - return ReportSNIError(new SNIError(provider, nativeError, sniError, errorMessage)); + return ReportSNIError(new SniError(provider, nativeError, sniError, errorMessage)); } /// @@ -299,7 +299,7 @@ internal static uint ReportSNIError(SNIProviders provider, uint nativeError, uin internal static uint ReportSNIError(SNIProviders provider, uint sniError, Exception sniException, uint nativeErrorCode = 0) { SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNICommon), EventType.ERR, "Provider = {0}, SNI Error = {1}, Exception = {2}", args0: provider, args1: sniError, args2: sniException?.Message); - return ReportSNIError(new SNIError(provider, sniError, sniException, nativeErrorCode)); + return ReportSNIError(new SniError(provider, sniError, sniException, nativeErrorCode)); } /// @@ -307,7 +307,7 @@ internal static uint ReportSNIError(SNIProviders provider, uint sniError, Except /// /// SNI error /// - internal static uint ReportSNIError(SNIError error) + internal static uint ReportSNIError(SniError error) { SNILoadHandle.SingletonInstance.LastError = error; return TdsEnums.SNI_ERROR; diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNILoadHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNILoadHandle.netcore.cs index 2e169fa09f..d1fefd6d12 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNILoadHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNILoadHandle.netcore.cs @@ -14,14 +14,14 @@ internal class SNILoadHandle public static readonly SNILoadHandle SingletonInstance = new SNILoadHandle(); public readonly EncryptionOptions _encryptionOption = EncryptionOptions.OFF; - public ThreadLocal _lastError = new ThreadLocal(static () => new SNIError(SNIProviders.INVALID_PROV, 0, TdsEnums.SNI_SUCCESS, string.Empty)); + public ThreadLocal _lastError = new ThreadLocal(static () => new SniError(SNIProviders.INVALID_PROV, 0, TdsEnums.SNI_SUCCESS, string.Empty)); private readonly uint _status = TdsEnums.SNI_SUCCESS; /// /// Last SNI error /// - public SNIError LastError + public SniError LastError { get { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsConnection.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsConnection.netcore.cs index ed46fb0c42..dee845cdfe 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsConnection.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsConnection.netcore.cs @@ -288,7 +288,7 @@ public void HandleReceiveComplete(SNIPacket packet, uint sniErrorCode) if (!_sessions.ContainsKey(_currentHeader.sessionId)) { - SNILoadHandle.SingletonInstance.LastError = new SNIError(SNIProviders.SMUX_PROV, 0, SNICommon.InvalidParameterError, Strings.SNI_ERROR_5); + SNILoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.SMUX_PROV, 0, SNICommon.InvalidParameterError, Strings.SNI_ERROR_5); HandleReceiveError(packet); SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsConnection), EventType.ERR, "Current Header Session Id {0} not found, MARS Session Id {1} will be destroyed, New SNI error created: {2}", args0: _currentHeader?.sessionId, args1: _lowerHandle?.ConnectionId, args2: sniErrorCode); _lowerHandle.Dispose(); diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsHandle.netcore.cs index 27da79c762..8159566639 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsHandle.netcore.cs @@ -33,7 +33,7 @@ internal sealed class SNIMarsHandle : SNIHandle private uint _receiveHighwater = 4; private uint _receiveHighwaterLastAck = 4; private uint _sequenceNumber; - private SNIError _connectionError; + private SniError _connectionError; /// /// Connection ID @@ -517,7 +517,7 @@ public override uint Receive(out SNIPacket packet, int timeoutInMilliseconds) SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, Waiting for packet event.", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater); if (!_packetEvent.Wait(timeoutInMilliseconds)) { - SNILoadHandle.SingletonInstance.LastError = new SNIError(SNIProviders.SMUX_PROV, 0, SNICommon.ConnTimeoutError, Strings.SNI_ERROR_11); + SNILoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.SMUX_PROV, 0, SNICommon.ConnTimeoutError, Strings.SNI_ERROR_11); SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, _packetEvent wait timed out.", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater); return TdsEnums.SNI_WAIT_TIMEOUT; } diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPacket.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPacket.netcore.cs index 7e98ba4260..7a32e1ce52 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPacket.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPacket.netcore.cs @@ -284,7 +284,7 @@ private static void ReadFromStreamAsyncContinuation(Task task, object state Exception e = task.Exception?.InnerException; if (e != null) { - SNILoadHandle.SingletonInstance.LastError = new SNIError(SNIProviders.TCP_PROV, SNICommon.InternalExceptionError, e); + SNILoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.TCP_PROV, SNICommon.InternalExceptionError, e); #if DEBUG SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIPacket), EventType.ERR, "Connection Id {0}, Internal Exception occurred while reading data: {1}", args0: packet._owner?.ConnectionId, args1: e?.Message); #endif @@ -298,7 +298,7 @@ private static void ReadFromStreamAsyncContinuation(Task task, object state #endif if (packet._dataLength == 0) { - SNILoadHandle.SingletonInstance.LastError = new SNIError(SNIProviders.TCP_PROV, 0, SNICommon.ConnTerminatedError, Strings.SNI_ERROR_2); + SNILoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.TCP_PROV, 0, SNICommon.ConnTerminatedError, Strings.SNI_ERROR_2); #if DEBUG SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIPacket), EventType.ERR, "Connection Id {0}, No data read from stream, connection was terminated.", args0: packet._owner?.ConnectionId); #endif @@ -339,7 +339,7 @@ public async void WriteToStreamAsync(Stream stream, SNIAsyncCallback callback, S } catch (Exception e) { - SNILoadHandle.SingletonInstance.LastError = new SNIError(provider, SNICommon.InternalExceptionError, e); + SNILoadHandle.SingletonInstance.LastError = new SniError(provider, SNICommon.InternalExceptionError, e); #if DEBUG SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIPacket), EventType.ERR, "Connection Id {0}, Internal Exception occurred while writing data: {1}", args0: _owner?.ConnectionId, args1: e?.Message); #endif diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIProxy.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIProxy.netcore.cs index 24b973c50d..557daeefa9 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIProxy.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIProxy.netcore.cs @@ -104,7 +104,7 @@ internal static SNIHandle CreateConnectionHandle( } catch (Exception e) { - SNILoadHandle.SingletonInstance.LastError = new SNIError(SNIProviders.INVALID_PROV, SNICommon.ErrorSpnLookup, e); + SNILoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, SNICommon.ErrorSpnLookup, e); } } @@ -205,7 +205,7 @@ private static SNITCPHandle CreateTcpHandle( string hostName = details.ServerName; if (string.IsNullOrWhiteSpace(hostName)) { - SNILoadHandle.SingletonInstance.LastError = new SNIError(SNIProviders.TCP_PROV, 0, SNICommon.InvalidConnStringError, Strings.SNI_ERROR_25); + SNILoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.TCP_PROV, 0, SNICommon.InvalidConnStringError, Strings.SNI_ERROR_25); return null; } @@ -221,7 +221,7 @@ private static SNITCPHandle CreateTcpHandle( } catch (SocketException se) { - SNILoadHandle.SingletonInstance.LastError = new SNIError(SNIProviders.TCP_PROV, SNICommon.ErrorLocatingServerInstance, se); + SNILoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.TCP_PROV, SNICommon.ErrorLocatingServerInstance, se); return null; } } @@ -263,7 +263,7 @@ private static SNINpHandle CreateNpHandle(DataSource details, TimeoutTimer timeo /// Get last SNI error on this thread /// /// - internal SNIError GetLastError() + internal SniError GetLastError() { return SNILoadHandle.SingletonInstance.LastError; } @@ -439,7 +439,7 @@ internal static string GetLocalDBInstance(string dataSource, out bool error) } else if (index > 0) { - SNILoadHandle.SingletonInstance.LastError = new SNIError(SNIProviders.INVALID_PROV, 0, SNICommon.ErrorLocatingServerInstance, Strings.SNI_ERROR_26); + SNILoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, SNICommon.ErrorLocatingServerInstance, Strings.SNI_ERROR_26); SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIProxy), EventType.ERR, "Incompatible use of prefix with LocalDb: '{0}'", dataSource); error = true; } @@ -458,7 +458,7 @@ internal static string GetLocalDBInstance(string dataSource, out bool error) } else { - SNILoadHandle.SingletonInstance.LastError = new SNIError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBNoInstanceName, Strings.SNI_ERROR_51); + SNILoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBNoInstanceName, Strings.SNI_ERROR_51); error = true; } } @@ -585,7 +585,7 @@ private bool InferConnectionDetails() private void ReportSNIError(SNIProviders provider) { - SNILoadHandle.SingletonInstance.LastError = new SNIError(provider, 0, SNICommon.InvalidConnStringError, Strings.SNI_ERROR_25); + SNILoadHandle.SingletonInstance.LastError = new SniError(provider, 0, SNICommon.InvalidConnStringError, Strings.SNI_ERROR_25); IsBadDataSource = true; } diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNITcpHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNITcpHandle.netcore.cs index 15330be02d..5075637b2b 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNITcpHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNITcpHandle.netcore.cs @@ -688,7 +688,7 @@ public override uint EnableSsl(uint options) catch (AuthenticationException aue) { SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.ERR, "Connection Id {0}, Authentication exception occurred: {1}", args0: _connectionId, args1: aue?.Message); - return ReportTcpSNIError(aue, SNIError.CertificateValidationErrorCode); + return ReportTcpSNIError(aue, SniError.CertificateValidationErrorCode); } catch (InvalidOperationException ioe) { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIError.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniError.netcore.cs similarity index 90% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIError.netcore.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniError.netcore.cs index fd62a51bc4..1aea18a925 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIError.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniError.netcore.cs @@ -9,7 +9,7 @@ namespace Microsoft.Data.SqlClient.ManagedSni /// /// SNI error /// - internal class SNIError + internal class SniError { // Error numbers from native SNI implementation internal const uint CertificateValidationErrorCode = 2148074277; @@ -22,7 +22,7 @@ internal class SNIError public readonly uint lineNumber; public readonly Exception exception; - public SNIError(SNIProviders provider, uint nativeError, uint sniErrorCode, string errorMessage) + public SniError(SNIProviders provider, uint nativeError, uint sniErrorCode, string errorMessage) { lineNumber = 0; function = string.Empty; @@ -33,7 +33,7 @@ public SNIError(SNIProviders provider, uint nativeError, uint sniErrorCode, stri exception = null; } - public SNIError(SNIProviders provider, uint sniErrorCode, Exception sniException, uint nativeErrorCode = 0) + public SniError(SNIProviders provider, uint sniErrorCode, Exception sniException, uint nativeErrorCode = 0) { lineNumber = 0; function = string.Empty; From 94c0b32d5c3f5e94e017319dbbaf47acdab210ea Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Tue, 13 May 2025 11:59:24 -0500 Subject: [PATCH 04/26] SNIHandle => SniHandle --- .../src/Microsoft.Data.SqlClient.csproj | 4 +-- .../SqlClient/TdsParserStateObjectManaged.cs | 32 +++++++++---------- .../ManagedSni/SNIMarsConnection.netcore.cs | 4 +-- .../ManagedSni/SNIMarsHandle.netcore.cs | 2 +- .../SqlClient/ManagedSni/SNIPacket.netcore.cs | 4 +-- .../ManagedSni/SNIPhysicalHandle.netcore.cs | 2 +- .../SqlClient/ManagedSni/SNIProxy.netcore.cs | 4 +-- .../ManagedSni/SNITcpHandle.netcore.cs | 2 +- ...Handle.netcore.cs => SniHandle.netcore.cs} | 2 +- .../SqlClient/SessionHandle.netcore.Unix.cs | 6 ++-- .../SessionHandle.netcore.Windows.cs | 6 ++-- 11 files changed, 34 insertions(+), 34 deletions(-) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/{SNIHandle.netcore.cs => SniHandle.netcore.cs} (99%) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index e5c63a7d1c..da7359f509 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -281,8 +281,8 @@ Microsoft\Data\SqlClient\ManagedSni\SNICommon.netcore.cs - - Microsoft\Data\SqlClient\ManagedSni\SNIHandle.netcore.cs + + Microsoft\Data\SqlClient\ManagedSni\SniHandle.netcore.cs Microsoft\Data\SqlClient\ManagedSni\SNILoadHandle.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs index 6b6a0ba3a9..7538c2aaa0 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs @@ -19,7 +19,7 @@ namespace Microsoft.Data.SqlClient.ManagedSni internal sealed class TdsParserStateObjectManaged : TdsParserStateObject { private SNIMarsConnection? _marsConnection; - private SNIHandle? _sessionHandle; + private SniHandle? _sessionHandle; public TdsParserStateObjectManaged(TdsParser parser) : base(parser) { } @@ -93,7 +93,7 @@ internal override void CreatePhysicalSNIHandle( string hostNameInCertificate, string serverCertificateFilename) { - SNIHandle? sessionHandle = SNIProxy.CreateConnectionHandle(serverName, timeout, out instanceName, ref spns, serverSPN, + SniHandle? sessionHandle = SNIProxy.CreateConnectionHandle(serverName, timeout, out instanceName, ref spns, serverSPN, flushCache, async, parallel, isIntegratedSecurity, iPAddressPreference, cachedFQDN, ref pendingDNSInfo, tlsFirst, hostNameInCertificate, serverCertificateFilename); @@ -121,7 +121,7 @@ internal override void AssignPendingDNSInfo(string userProtocol, string DNSCache internal void ReadAsyncCallback(SNIPacket packet, uint error) { - SNIHandle? sessionHandle = _sessionHandle; + SniHandle? sessionHandle = _sessionHandle; if (sessionHandle is not null) { ReadAsyncCallback(IntPtr.Zero, PacketHandle.FromManagedPacket(packet), error); @@ -141,7 +141,7 @@ internal void ReadAsyncCallback(SNIPacket packet, uint error) internal void WriteAsyncCallback(SNIPacket packet, uint sniError) { - SNIHandle? sessionHandle = _sessionHandle; + SniHandle? sessionHandle = _sessionHandle; if (sessionHandle is not null) { WriteAsyncCallback(IntPtr.Zero, PacketHandle.FromManagedPacket(packet), sniError); @@ -166,7 +166,7 @@ protected override void RemovePacketFromPendingList(PacketHandle packet) internal override void Dispose() { - SNIHandle? sessionHandle = Interlocked.Exchange(ref _sessionHandle, null); + SniHandle? sessionHandle = Interlocked.Exchange(ref _sessionHandle, null); if (sessionHandle is not null) { SqlClientEventSource.Log.TryTraceEvent("TdsParserStateObjectManaged.Dispose | Info | State Object Id {0}, Session Id {1}, Disposing session Handle and counters.", _objectID, sessionHandle.ConnectionId); @@ -203,7 +203,7 @@ protected override void FreeGcHandle(int remaining, bool release) internal override bool IsFailedHandle() { - SNIHandle? sessionHandle = _sessionHandle; + SniHandle? sessionHandle = _sessionHandle; if (sessionHandle is not null) { return sessionHandle.Status != TdsEnums.SNI_SUCCESS; @@ -214,7 +214,7 @@ internal override bool IsFailedHandle() internal override PacketHandle ReadSyncOverAsync(int timeoutRemaining, out uint error) { - SNIHandle sessionHandle = GetSessionSNIHandleHandleOrThrow(); + SniHandle sessionHandle = GetSessionSNIHandleHandleOrThrow(); error = sessionHandle.Receive(out SNIPacket packet, timeoutRemaining); @@ -240,7 +240,7 @@ internal override void ReleasePacket(PacketHandle syncReadPacket) #endif if (packet is not null) { - SNIHandle? sessionHandle = _sessionHandle; + SniHandle? sessionHandle = _sessionHandle; if (sessionHandle is not null) { sessionHandle.ReturnPacket(packet); @@ -256,7 +256,7 @@ internal override void ReleasePacket(PacketHandle syncReadPacket) internal override uint CheckConnection() { - SNIHandle? handle = GetSessionSNIHandleHandleOrThrow(); + SniHandle? handle = GetSessionSNIHandleHandleOrThrow(); return handle is null ? TdsEnums.SNI_SUCCESS : handle.CheckConnection(); } @@ -285,7 +285,7 @@ internal override PacketHandle CreateAndSetAttentionPacket() internal override uint WritePacket(PacketHandle packetHandle, bool sync) { uint result = TdsEnums.SNI_UNINITIALIZED; - SNIHandle sessionHandle = GetSessionSNIHandleHandleOrThrow(); + SniHandle sessionHandle = GetSessionSNIHandleHandleOrThrow(); SNIPacket? packet = packetHandle.ManagedPacket; if (sync) @@ -317,7 +317,7 @@ internal override bool IsValidPacket(PacketHandle packet) internal override PacketHandle GetResetWritePacket(int dataSize) { - SNIHandle sessionHandle = GetSessionSNIHandleHandleOrThrow(); + SniHandle sessionHandle = GetSessionSNIHandleHandleOrThrow(); SNIPacket packet = sessionHandle.RentPacket(headerSize: sessionHandle.ReserveHeaderSize, dataSize: dataSize); #if DEBUG Debug.Assert(packet.IsActive, "packet is not active, a serious pooling error may have occurred"); @@ -345,7 +345,7 @@ internal override uint SniGetConnectionId(ref Guid clientConnectionId) internal override uint DisableSsl() { - SNIHandle sessionHandle = GetSessionSNIHandleHandleOrThrow(); + SniHandle sessionHandle = GetSessionSNIHandleHandleOrThrow(); SqlClientEventSource.Log.TryTraceEvent("TdsParserStateObjectManaged.DisableSsl | Info | Session Id {0}", sessionHandle.ConnectionId); sessionHandle.DisableSsl(); return TdsEnums.SNI_SUCCESS; @@ -353,7 +353,7 @@ internal override uint DisableSsl() internal override uint EnableMars(ref uint info) { - SNIHandle sessionHandle = GetSessionSNIHandleHandleOrThrow(); + SniHandle sessionHandle = GetSessionSNIHandleHandleOrThrow(); _marsConnection = new SNIMarsConnection(sessionHandle); SqlClientEventSource.Log.TryTraceEvent("TdsParserStateObjectManaged.EnableMars | Info | State Object Id {0}, Session Id {1}", _objectID, sessionHandle.ConnectionId); @@ -367,7 +367,7 @@ internal override uint EnableMars(ref uint info) internal override uint EnableSsl(ref uint info, bool tlsFirst, string serverCertificateFilename) { - SNIHandle sessionHandle = GetSessionSNIHandleHandleOrThrow(); + SniHandle sessionHandle = GetSessionSNIHandleHandleOrThrow(); try { SqlClientEventSource.Log.TryTraceEvent("TdsParserStateObjectManaged.EnableSsl | Info | Session Id {0}", sessionHandle.ConnectionId); @@ -392,9 +392,9 @@ internal override uint WaitForSSLHandShakeToComplete(out int protocolVersion) return 0; } - private SNIHandle GetSessionSNIHandleHandleOrThrow() + private SniHandle GetSessionSNIHandleHandleOrThrow() { - SNIHandle? sessionHandle = _sessionHandle; + SniHandle? sessionHandle = _sessionHandle; if (sessionHandle is null) { ThrowClosedConnection(); diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsConnection.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsConnection.netcore.cs index dee845cdfe..a1af1e3ac5 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsConnection.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsConnection.netcore.cs @@ -19,7 +19,7 @@ internal class SNIMarsConnection private readonly byte[] _headerBytes; private readonly SNISMUXHeader _currentHeader; private readonly object _sync; - private SNIHandle _lowerHandle; + private SniHandle _lowerHandle; private ushort _nextSessionId; private int _currentHeaderByteCount; private int _dataBytesLeft; @@ -38,7 +38,7 @@ internal class SNIMarsConnection /// Constructor /// /// Lower handle - public SNIMarsConnection(SNIHandle lowerHandle) + public SNIMarsConnection(SniHandle lowerHandle) { _sync = new object(); _connectionId = Guid.NewGuid(); diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsHandle.netcore.cs index 8159566639..b20d84f4d1 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsHandle.netcore.cs @@ -12,7 +12,7 @@ namespace Microsoft.Data.SqlClient.ManagedSni /// /// MARS handle /// - internal sealed class SNIMarsHandle : SNIHandle + internal sealed class SNIMarsHandle : SniHandle { private const uint ACK_THRESHOLD = 2; diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPacket.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPacket.netcore.cs index 7a32e1ce52..83aa86c672 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPacket.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPacket.netcore.cs @@ -32,7 +32,7 @@ internal sealed class SNIPacket /// refcount = 1 means that a packet is active /// refcount > 1 means that a packet has been reused in some way and is a serious error internal int _refCount; - internal readonly SNIHandle _owner; // used in debug builds to check that packets are being returned to the correct pool + internal readonly SniHandle _owner; // used in debug builds to check that packets are being returned to the correct pool internal string _traceTag; // used in debug builds to assist tracing what steps the packet has been through #if TRACE_HISTORY @@ -59,7 +59,7 @@ public enum Direction /// public bool IsActive => _refCount == 1; - public SNIPacket(SNIHandle owner, int id) + public SNIPacket(SniHandle owner, int id) : this() { #if TRACE_HISTORY diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPhysicalHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPhysicalHandle.netcore.cs index 7b4fe4a868..7ba9f38fdf 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPhysicalHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPhysicalHandle.netcore.cs @@ -10,7 +10,7 @@ namespace Microsoft.Data.SqlClient.ManagedSni { - internal abstract class SNIPhysicalHandle : SNIHandle + internal abstract class SNIPhysicalHandle : SniHandle { protected const int DefaultPoolSize = 4; diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIProxy.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIProxy.netcore.cs index 557daeefa9..90df4c5e66 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIProxy.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIProxy.netcore.cs @@ -44,7 +44,7 @@ internal class SNIProxy /// Used for the HostName in certificate /// Used for the path to the Server Certificate /// SNI handle - internal static SNIHandle CreateConnectionHandle( + internal static SniHandle CreateConnectionHandle( string fullServerName, TimeoutTimer timeout, out byte[] instanceName, @@ -79,7 +79,7 @@ internal static SNIHandle CreateConnectionHandle( return null; } - SNIHandle sniHandle = null; + SniHandle sniHandle = null; switch (details.ResolvedProtocol) { case DataSource.Protocol.Admin: diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNITcpHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNITcpHandle.netcore.cs index 5075637b2b..6f758f3c68 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNITcpHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNITcpHandle.netcore.cs @@ -666,7 +666,7 @@ private static Socket ParallelConnect(IPAddress[] serverAddresses, int port, Tim /// public override uint EnableSsl(uint options) { - using (TrySNIEventScope.Create(nameof(SNIHandle))) + using (TrySNIEventScope.Create(nameof(SniHandle))) { _validateCert = (options & TdsEnums.SNI_SSL_VALIDATE_CERTIFICATE) != 0; diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniHandle.netcore.cs similarity index 99% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIHandle.netcore.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniHandle.netcore.cs index 61de004ce8..b508d7265e 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniHandle.netcore.cs @@ -15,7 +15,7 @@ namespace Microsoft.Data.SqlClient.ManagedSni /// /// SNI connection handle /// - internal abstract class SNIHandle + internal abstract class SniHandle { protected static readonly SslProtocols s_supportedProtocols = SslProtocols.None; diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SessionHandle.netcore.Unix.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SessionHandle.netcore.Unix.cs index 42092ddae5..8465da3684 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SessionHandle.netcore.Unix.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SessionHandle.netcore.Unix.cs @@ -19,10 +19,10 @@ internal readonly ref struct SessionHandle public const int NativeHandleType = 1; public const int ManagedHandleType = 2; - public readonly ManagedSni.SNIHandle ManagedHandle; + public readonly ManagedSni.SniHandle ManagedHandle; public readonly int Type; - public SessionHandle(ManagedSni.SNIHandle managedHandle, int type) + public SessionHandle(ManagedSni.SniHandle managedHandle, int type) { Type = type; ManagedHandle = managedHandle; @@ -30,7 +30,7 @@ public SessionHandle(ManagedSni.SNIHandle managedHandle, int type) public bool IsNull => ManagedHandle is null; - public static SessionHandle FromManagedSession(ManagedSni.SNIHandle managedSessionHandle) => + public static SessionHandle FromManagedSession(ManagedSni.SniHandle managedSessionHandle) => new SessionHandle(managedSessionHandle, ManagedHandleType); } } diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SessionHandle.netcore.Windows.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SessionHandle.netcore.Windows.cs index 2f392f104e..45003c4c73 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SessionHandle.netcore.Windows.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SessionHandle.netcore.Windows.cs @@ -19,12 +19,12 @@ internal readonly ref struct SessionHandle public const int NativeHandleType = 1; public const int ManagedHandleType = 2; - public readonly ManagedSni.SNIHandle ManagedHandle; + public readonly ManagedSni.SniHandle ManagedHandle; public readonly SNIHandle NativeHandle; public readonly int Type; - public SessionHandle(ManagedSni.SNIHandle managedHandle, SNIHandle nativeHandle, int type) + public SessionHandle(ManagedSni.SniHandle managedHandle, SNIHandle nativeHandle, int type) { Type = type; ManagedHandle = managedHandle; @@ -33,7 +33,7 @@ public SessionHandle(ManagedSni.SNIHandle managedHandle, SNIHandle nativeHandle, public bool IsNull => (Type == NativeHandleType) ? NativeHandle is null : ManagedHandle is null; - public static SessionHandle FromManagedSession(ManagedSni.SNIHandle managedSessionHandle) => + public static SessionHandle FromManagedSession(ManagedSni.SniHandle managedSessionHandle) => new SessionHandle(managedSessionHandle, default, ManagedHandleType); public static SessionHandle FromNativeHandle(SNIHandle nativeSessionHandle) => From 9b85b56f2be78c36af42938d1b20061a1ee89a23 Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Tue, 13 May 2025 12:05:09 -0500 Subject: [PATCH 05/26] SNILoadHandle => SniLoadHandle --- .../netcore/src/Microsoft.Data.SqlClient.csproj | 4 ++-- .../ManagedSni/LocalDB.netcore.Windows.cs | 12 ++++++------ .../Data/SqlClient/ManagedSni/SNICommon.netcore.cs | 2 +- .../ManagedSni/SNIMarsConnection.netcore.cs | 2 +- .../SqlClient/ManagedSni/SNIMarsHandle.netcore.cs | 4 ++-- .../Data/SqlClient/ManagedSni/SNIPacket.netcore.cs | 6 +++--- .../Data/SqlClient/ManagedSni/SNIProxy.netcore.cs | 14 +++++++------- ...dHandle.netcore.cs => SniLoadHandle.netcore.cs} | 4 ++-- .../SqlClient/TdsParserStateObjectFactory.Unix.cs | 6 +++--- .../TdsParserStateObjectFactory.Windows.cs | 6 +++--- 10 files changed, 30 insertions(+), 30 deletions(-) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/{SNILoadHandle.netcore.cs => SniLoadHandle.netcore.cs} (93%) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index da7359f509..337b399230 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -284,8 +284,8 @@ Microsoft\Data\SqlClient\ManagedSni\SniHandle.netcore.cs - - Microsoft\Data\SqlClient\ManagedSni\SNILoadHandle.netcore.cs + + Microsoft\Data\SqlClient\ManagedSni\SniLoadHandle.netcore.cs Microsoft\Data\SqlClient\ManagedSni\SNIMarsConnection.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Windows.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Windows.cs index c88034e348..b59e324afa 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Windows.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Windows.cs @@ -54,7 +54,7 @@ private string GetConnectionString(string localDbInstance) int result = localDBStartInstanceFunc(localDbInstance, 0, localDBConnectionString, ref sizeOfbuffer); if (result != TdsEnums.SNI_SUCCESS) { - SNILoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBErrorCode, Strings.SNI_ERROR_50); + SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBErrorCode, Strings.SNI_ERROR_50); SqlClientEventSource.Log.TrySNITraceEvent(nameof(LocalDB), EventType.ERR, "Unsuccessful 'LocalDBStartInstance' method call with {0} result to start '{1}' localDb instance", args0: result, args1: localDbInstance); localDBConnectionString = null; } @@ -132,7 +132,7 @@ private bool LoadUserInstanceDll() // If there was no DLL path found, then there is an error. if (dllPath == null) { - SNILoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, MapLocalDBErrorStateToCode(registryQueryErrorState), MapLocalDBErrorStateToErrorMessage(registryQueryErrorState)); + SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, MapLocalDBErrorStateToCode(registryQueryErrorState), MapLocalDBErrorStateToErrorMessage(registryQueryErrorState)); SqlClientEventSource.Log.TrySNITraceEvent(nameof(LocalDB), EventType.ERR, "User instance DLL path is null."); return false; } @@ -140,7 +140,7 @@ private bool LoadUserInstanceDll() // In case the registry had an empty path for dll if (string.IsNullOrWhiteSpace(dllPath)) { - SNILoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBInvalidSqlUserInstanceDllPath, Strings.SNI_ERROR_55); + SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBInvalidSqlUserInstanceDllPath, Strings.SNI_ERROR_55); SqlClientEventSource.Log.TrySNITraceEvent(nameof(LocalDB), EventType.ERR, "User instance DLL path is invalid. DLL path = {0}", dllPath); return false; } @@ -150,7 +150,7 @@ private bool LoadUserInstanceDll() if (libraryHandle.IsInvalid) { - SNILoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBFailedToLoadDll, Strings.SNI_ERROR_56); + SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBFailedToLoadDll, Strings.SNI_ERROR_56); SqlClientEventSource.Log.TrySNITraceEvent(nameof(LocalDB), EventType.ERR, "Library Handle is invalid. Could not load the dll."); libraryHandle.Dispose(); return false; @@ -161,7 +161,7 @@ private bool LoadUserInstanceDll() if (_startInstanceHandle == IntPtr.Zero) { - SNILoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBBadRuntime, Strings.SNI_ERROR_57); + SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBBadRuntime, Strings.SNI_ERROR_57); SqlClientEventSource.Log.TrySNITraceEvent(nameof(LocalDB), EventType.ERR, "Was not able to load the PROC from DLL. Bad Runtime."); libraryHandle.Dispose(); return false; @@ -172,7 +172,7 @@ private bool LoadUserInstanceDll() if (localDBStartInstanceFunc == null) { - SNILoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBBadRuntime, Strings.SNI_ERROR_57); + SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBBadRuntime, Strings.SNI_ERROR_57); libraryHandle.Dispose(); _startInstanceHandle = IntPtr.Zero; return false; diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs index 46de1892c4..12dfde458f 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs @@ -309,7 +309,7 @@ internal static uint ReportSNIError(SNIProviders provider, uint sniError, Except /// internal static uint ReportSNIError(SniError error) { - SNILoadHandle.SingletonInstance.LastError = error; + SniLoadHandle.SingletonInstance.LastError = error; return TdsEnums.SNI_ERROR; } } diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsConnection.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsConnection.netcore.cs index a1af1e3ac5..694083545e 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsConnection.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsConnection.netcore.cs @@ -288,7 +288,7 @@ public void HandleReceiveComplete(SNIPacket packet, uint sniErrorCode) if (!_sessions.ContainsKey(_currentHeader.sessionId)) { - SNILoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.SMUX_PROV, 0, SNICommon.InvalidParameterError, Strings.SNI_ERROR_5); + SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.SMUX_PROV, 0, SNICommon.InvalidParameterError, Strings.SNI_ERROR_5); HandleReceiveError(packet); SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsConnection), EventType.ERR, "Current Header Session Id {0} not found, MARS Session Id {1} will be destroyed, New SNI error created: {2}", args0: _currentHeader?.sessionId, args1: _lowerHandle?.ConnectionId, args2: sniErrorCode); _lowerHandle.Dispose(); diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsHandle.netcore.cs index b20d84f4d1..5388bd0808 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsHandle.netcore.cs @@ -343,7 +343,7 @@ public void HandleReceiveError(SNIPacket packet) lock (_receivedPacketQueue) { - _connectionError = SNILoadHandle.SingletonInstance.LastError; + _connectionError = SniLoadHandle.SingletonInstance.LastError; SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.ERR, "MARS Session Id {0}, _connectionError to be handled: {1}", args0: ConnectionId, args1: _connectionError); _packetEvent.Set(); } @@ -517,7 +517,7 @@ public override uint Receive(out SNIPacket packet, int timeoutInMilliseconds) SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, Waiting for packet event.", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater); if (!_packetEvent.Wait(timeoutInMilliseconds)) { - SNILoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.SMUX_PROV, 0, SNICommon.ConnTimeoutError, Strings.SNI_ERROR_11); + SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.SMUX_PROV, 0, SNICommon.ConnTimeoutError, Strings.SNI_ERROR_11); SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, _packetEvent wait timed out.", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater); return TdsEnums.SNI_WAIT_TIMEOUT; } diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPacket.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPacket.netcore.cs index 83aa86c672..f0405f1a1a 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPacket.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPacket.netcore.cs @@ -284,7 +284,7 @@ private static void ReadFromStreamAsyncContinuation(Task task, object state Exception e = task.Exception?.InnerException; if (e != null) { - SNILoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.TCP_PROV, SNICommon.InternalExceptionError, e); + SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.TCP_PROV, SNICommon.InternalExceptionError, e); #if DEBUG SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIPacket), EventType.ERR, "Connection Id {0}, Internal Exception occurred while reading data: {1}", args0: packet._owner?.ConnectionId, args1: e?.Message); #endif @@ -298,7 +298,7 @@ private static void ReadFromStreamAsyncContinuation(Task task, object state #endif if (packet._dataLength == 0) { - SNILoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.TCP_PROV, 0, SNICommon.ConnTerminatedError, Strings.SNI_ERROR_2); + SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.TCP_PROV, 0, SNICommon.ConnTerminatedError, Strings.SNI_ERROR_2); #if DEBUG SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIPacket), EventType.ERR, "Connection Id {0}, No data read from stream, connection was terminated.", args0: packet._owner?.ConnectionId); #endif @@ -339,7 +339,7 @@ public async void WriteToStreamAsync(Stream stream, SNIAsyncCallback callback, S } catch (Exception e) { - SNILoadHandle.SingletonInstance.LastError = new SniError(provider, SNICommon.InternalExceptionError, e); + SniLoadHandle.SingletonInstance.LastError = new SniError(provider, SNICommon.InternalExceptionError, e); #if DEBUG SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIPacket), EventType.ERR, "Connection Id {0}, Internal Exception occurred while writing data: {1}", args0: _owner?.ConnectionId, args1: e?.Message); #endif diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIProxy.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIProxy.netcore.cs index 90df4c5e66..7f4cd03b47 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIProxy.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIProxy.netcore.cs @@ -104,7 +104,7 @@ internal static SniHandle CreateConnectionHandle( } catch (Exception e) { - SNILoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, SNICommon.ErrorSpnLookup, e); + SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, SNICommon.ErrorSpnLookup, e); } } @@ -205,7 +205,7 @@ private static SNITCPHandle CreateTcpHandle( string hostName = details.ServerName; if (string.IsNullOrWhiteSpace(hostName)) { - SNILoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.TCP_PROV, 0, SNICommon.InvalidConnStringError, Strings.SNI_ERROR_25); + SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.TCP_PROV, 0, SNICommon.InvalidConnStringError, Strings.SNI_ERROR_25); return null; } @@ -221,7 +221,7 @@ private static SNITCPHandle CreateTcpHandle( } catch (SocketException se) { - SNILoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.TCP_PROV, SNICommon.ErrorLocatingServerInstance, se); + SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.TCP_PROV, SNICommon.ErrorLocatingServerInstance, se); return null; } } @@ -265,7 +265,7 @@ private static SNINpHandle CreateNpHandle(DataSource details, TimeoutTimer timeo /// internal SniError GetLastError() { - return SNILoadHandle.SingletonInstance.LastError; + return SniLoadHandle.SingletonInstance.LastError; } /// @@ -439,7 +439,7 @@ internal static string GetLocalDBInstance(string dataSource, out bool error) } else if (index > 0) { - SNILoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, SNICommon.ErrorLocatingServerInstance, Strings.SNI_ERROR_26); + SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, SNICommon.ErrorLocatingServerInstance, Strings.SNI_ERROR_26); SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIProxy), EventType.ERR, "Incompatible use of prefix with LocalDb: '{0}'", dataSource); error = true; } @@ -458,7 +458,7 @@ internal static string GetLocalDBInstance(string dataSource, out bool error) } else { - SNILoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBNoInstanceName, Strings.SNI_ERROR_51); + SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBNoInstanceName, Strings.SNI_ERROR_51); error = true; } } @@ -585,7 +585,7 @@ private bool InferConnectionDetails() private void ReportSNIError(SNIProviders provider) { - SNILoadHandle.SingletonInstance.LastError = new SniError(provider, 0, SNICommon.InvalidConnStringError, Strings.SNI_ERROR_25); + SniLoadHandle.SingletonInstance.LastError = new SniError(provider, 0, SNICommon.InvalidConnStringError, Strings.SNI_ERROR_25); IsBadDataSource = true; } diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNILoadHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniLoadHandle.netcore.cs similarity index 93% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNILoadHandle.netcore.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniLoadHandle.netcore.cs index d1fefd6d12..f9bd7eac02 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNILoadHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniLoadHandle.netcore.cs @@ -9,9 +9,9 @@ namespace Microsoft.Data.SqlClient.ManagedSni /// /// Global SNI settings and status /// - internal class SNILoadHandle + internal class SniLoadHandle { - public static readonly SNILoadHandle SingletonInstance = new SNILoadHandle(); + public static readonly SniLoadHandle SingletonInstance = new SniLoadHandle(); public readonly EncryptionOptions _encryptionOption = EncryptionOptions.OFF; public ThreadLocal _lastError = new ThreadLocal(static () => new SniError(SNIProviders.INVALID_PROV, 0, TdsEnums.SNI_SUCCESS, string.Empty)); diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectFactory.Unix.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectFactory.Unix.cs index c5fed558f7..f7cb55d451 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectFactory.Unix.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectFactory.Unix.cs @@ -13,14 +13,14 @@ internal sealed class TdsParserStateObjectFactory public static readonly TdsParserStateObjectFactory Singleton = new TdsParserStateObjectFactory(); - public EncryptionOptions EncryptionOptions => ManagedSni.SNILoadHandle.SingletonInstance.Options; + public EncryptionOptions EncryptionOptions => ManagedSni.SniLoadHandle.SingletonInstance.Options; - public uint SNIStatus => ManagedSni.SNILoadHandle.SingletonInstance.Status; + public uint SNIStatus => ManagedSni.SniLoadHandle.SingletonInstance.Status; /// /// Verify client encryption possibility. /// - public bool ClientOSEncryptionSupport => ManagedSni.SNILoadHandle.SingletonInstance.ClientOSEncryptionSupport; + public bool ClientOSEncryptionSupport => ManagedSni.SniLoadHandle.SingletonInstance.ClientOSEncryptionSupport; public TdsParserStateObject CreateTdsParserStateObject(TdsParser parser) { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectFactory.Windows.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectFactory.Windows.cs index b6ad96ffd1..8b8fe9186b 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectFactory.Windows.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectFactory.Windows.cs @@ -27,14 +27,14 @@ internal sealed class TdsParserStateObjectFactory public EncryptionOptions EncryptionOptions => #if NET - UseManagedSNI ? ManagedSni.SNILoadHandle.SingletonInstance.Options : SNILoadHandle.SingletonInstance.Options; + UseManagedSNI ? ManagedSni.SniLoadHandle.SingletonInstance.Options : SNILoadHandle.SingletonInstance.Options; #else SNILoadHandle.SingletonInstance.Options; #endif public uint SNIStatus => #if NET - UseManagedSNI ? ManagedSni.SNILoadHandle.SingletonInstance.Status : SNILoadHandle.SingletonInstance.Status; + UseManagedSNI ? ManagedSni.SniLoadHandle.SingletonInstance.Status : SNILoadHandle.SingletonInstance.Status; #else SNILoadHandle.SingletonInstance.Status; #endif @@ -44,7 +44,7 @@ internal sealed class TdsParserStateObjectFactory /// public bool ClientOSEncryptionSupport => #if NET - UseManagedSNI ? ManagedSni.SNILoadHandle.SingletonInstance.ClientOSEncryptionSupport : SNILoadHandle.SingletonInstance.ClientOSEncryptionSupport; + UseManagedSNI ? ManagedSni.SniLoadHandle.SingletonInstance.ClientOSEncryptionSupport : SNILoadHandle.SingletonInstance.ClientOSEncryptionSupport; #else SNILoadHandle.SingletonInstance.ClientOSEncryptionSupport; #endif From 7315977c63aaa11b9d36de0beaca9fd0429ec5a0 Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Tue, 13 May 2025 12:10:05 -0500 Subject: [PATCH 06/26] SNIMarsConnection => SniMarsConnection --- .../src/Microsoft.Data.SqlClient.csproj | 4 +- .../SqlClient/TdsParserStateObjectManaged.cs | 4 +- .../ManagedSni/SNIMarsHandle.netcore.cs | 4 +- ...etcore.cs => SniMarsConnection.netcore.cs} | 66 +++++++++---------- 4 files changed, 39 insertions(+), 39 deletions(-) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/{SNIMarsConnection.netcore.cs => SniMarsConnection.netcore.cs} (88%) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index 337b399230..fb16b8b13c 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -287,8 +287,8 @@ Microsoft\Data\SqlClient\ManagedSni\SniLoadHandle.netcore.cs - - Microsoft\Data\SqlClient\ManagedSni\SNIMarsConnection.netcore.cs + + Microsoft\Data\SqlClient\ManagedSni\SniMarsConnection.netcore.cs Microsoft\Data\SqlClient\ManagedSni\SNIMarsHandle.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs index 7538c2aaa0..97187fb526 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs @@ -18,7 +18,7 @@ namespace Microsoft.Data.SqlClient.ManagedSni { internal sealed class TdsParserStateObjectManaged : TdsParserStateObject { - private SNIMarsConnection? _marsConnection; + private SniMarsConnection? _marsConnection; private SniHandle? _sessionHandle; public TdsParserStateObjectManaged(TdsParser parser) : base(parser) { } @@ -354,7 +354,7 @@ internal override uint DisableSsl() internal override uint EnableMars(ref uint info) { SniHandle sessionHandle = GetSessionSNIHandleHandleOrThrow(); - _marsConnection = new SNIMarsConnection(sessionHandle); + _marsConnection = new SniMarsConnection(sessionHandle); SqlClientEventSource.Log.TryTraceEvent("TdsParserStateObjectManaged.EnableMars | Info | State Object Id {0}, Session Id {1}", _objectID, sessionHandle.ConnectionId); if (_marsConnection.StartReceive() == TdsEnums.SNI_SUCCESS_IO_PENDING) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsHandle.netcore.cs index 5388bd0808..7572f6e589 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsHandle.netcore.cs @@ -16,7 +16,7 @@ internal sealed class SNIMarsHandle : SniHandle { private const uint ACK_THRESHOLD = 2; - private readonly SNIMarsConnection _connection; + private readonly SniMarsConnection _connection; private readonly uint _status = TdsEnums.SNI_UNINITIALIZED; private readonly Queue _receivedPacketQueue = new Queue(); private readonly Queue _sendPacketQueue = new Queue(); @@ -76,7 +76,7 @@ public override void Dispose() /// MARS session ID /// Callback object /// true if connection is asynchronous - public SNIMarsHandle(SNIMarsConnection connection, ushort sessionId, object callbackObject, bool async) + public SNIMarsHandle(SniMarsConnection connection, ushort sessionId, object callbackObject, bool async) { _sessionId = sessionId; _connection = connection; diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsConnection.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsConnection.netcore.cs similarity index 88% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsConnection.netcore.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsConnection.netcore.cs index 694083545e..1d6282cf4d 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsConnection.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsConnection.netcore.cs @@ -12,7 +12,7 @@ namespace Microsoft.Data.SqlClient.ManagedSni /// /// SNI MARS connection. Multiple MARS streams will be overlaid on this connection. /// - internal class SNIMarsConnection + internal class SniMarsConnection { private readonly Guid _connectionId; private readonly Dictionary _sessions; @@ -38,7 +38,7 @@ internal class SNIMarsConnection /// Constructor /// /// Lower handle - public SNIMarsConnection(SniHandle lowerHandle) + public SniMarsConnection(SniHandle lowerHandle) { _sync = new object(); _connectionId = Guid.NewGuid(); @@ -49,7 +49,7 @@ public SNIMarsConnection(SniHandle lowerHandle) _currentHeaderByteCount = 0; _dataBytesLeft = 0; _lowerHandle = lowerHandle; - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsConnection), EventType.INFO, "Created MARS Session Id {0}", args0: ConnectionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsConnection), EventType.INFO, "Created MARS Session Id {0}", args0: ConnectionId); _lowerHandle.SetAsyncCallbacks(HandleReceiveComplete, HandleSendComplete); } @@ -60,7 +60,7 @@ public SNIMarsHandle CreateMarsSession(object callbackObject, bool async) ushort sessionId = _nextSessionId++; SNIMarsHandle handle = new SNIMarsHandle(this, sessionId, callbackObject, async); _sessions.Add(sessionId, handle); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsConnection), EventType.INFO, "MARS Session Id {0}, SNI MARS Handle Id {1}, created new MARS Session {2}", args0: ConnectionId, args1: handle?.ConnectionId, args2: sessionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsConnection), EventType.INFO, "MARS Session Id {0}, SNI MARS Handle Id {1}, created new MARS Session {2}", args0: ConnectionId, args1: handle?.ConnectionId, args2: sessionId); return handle; } } @@ -71,16 +71,16 @@ public SNIMarsHandle CreateMarsSession(object callbackObject, bool async) /// public uint StartReceive() { - using (TrySNIEventScope.Create(nameof(SNIMarsConnection))) + using (TrySNIEventScope.Create(nameof(SniMarsConnection))) { SNIPacket packet = null; if (ReceiveAsync(ref packet) == TdsEnums.SNI_SUCCESS_IO_PENDING) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsConnection), EventType.INFO, "MARS Session Id {0}, Success IO pending.", args0: ConnectionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsConnection), EventType.INFO, "MARS Session Id {0}, Success IO pending.", args0: ConnectionId); return TdsEnums.SNI_SUCCESS_IO_PENDING; } - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsConnection), EventType.ERR, "MARS Session Id {0}, Connection not usable.", args0: ConnectionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsConnection), EventType.ERR, "MARS Session Id {0}, Connection not usable.", args0: ConnectionId); return SNICommon.ReportSNIError(SNIProviders.SMUX_PROV, 0, SNICommon.ConnNotUsableError, Strings.SNI_ERROR_19); } } @@ -92,7 +92,7 @@ public uint StartReceive() /// SNI error code public uint Send(SNIPacket packet) { - using (TrySNIEventScope.Create(nameof(SNIMarsConnection))) + using (TrySNIEventScope.Create(nameof(SniMarsConnection))) { lock (DemuxerSync) { @@ -108,7 +108,7 @@ public uint Send(SNIPacket packet) /// SNI error code public uint SendAsync(SNIPacket packet) { - using (TrySNIEventScope.Create(nameof(SNIMarsConnection))) + using (TrySNIEventScope.Create(nameof(SniMarsConnection))) { lock (DemuxerSync) { @@ -124,13 +124,13 @@ public uint SendAsync(SNIPacket packet) /// SNI error code public uint ReceiveAsync(ref SNIPacket packet) { - using (TrySNIEventScope.Create(nameof(SNIMarsConnection))) + using (TrySNIEventScope.Create(nameof(SniMarsConnection))) { if (packet != null) { ReturnPacket(packet); #if DEBUG - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsConnection), EventType.INFO, "MARS Session Id {0}, Packet {1} returned", args0: ConnectionId, args1: packet?._id); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsConnection), EventType.INFO, "MARS Session Id {0}, Packet {1} returned", args0: ConnectionId, args1: packet?._id); #endif packet = null; } @@ -139,7 +139,7 @@ public uint ReceiveAsync(ref SNIPacket packet) { var response = _lowerHandle.ReceiveAsync(ref packet); #if DEBUG - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsConnection), EventType.INFO, "MARS Session Id {0}, Received new packet {1}", args0: ConnectionId, args1: packet?._id); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsConnection), EventType.INFO, "MARS Session Id {0}, Received new packet {1}", args0: ConnectionId, args1: packet?._id); #endif return response; } @@ -152,7 +152,7 @@ public uint ReceiveAsync(ref SNIPacket packet) /// SNI error status public uint CheckConnection() { - using (TrySNIEventScope.Create(nameof(SNIMarsConnection))) + using (TrySNIEventScope.Create(nameof(SniMarsConnection))) { lock (DemuxerSync) { @@ -173,11 +173,11 @@ public void HandleReceiveError(SNIPacket packet) { handle.HandleReceiveError(packet); #if DEBUG - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsConnection), EventType.ERR, "MARS Session Id {0}, Packet {1} has Completion Callback", args0: ConnectionId, args1: packet?._id); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsConnection), EventType.ERR, "MARS Session Id {0}, Packet {1} has Completion Callback", args0: ConnectionId, args1: packet?._id); } else { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsConnection), EventType.ERR, "MARS Session Id {0}, Packet {1} does not have Completion Callback, error not handled.", args0: ConnectionId, args1: packet?._id); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsConnection), EventType.ERR, "MARS Session Id {0}, Packet {1} does not have Completion Callback, error not handled.", args0: ConnectionId, args1: packet?._id); #endif } } @@ -202,7 +202,7 @@ public void HandleSendComplete(SNIPacket packet, uint sniErrorCode) /// SNI error code public void HandleReceiveComplete(SNIPacket packet, uint sniErrorCode) { - using (TrySNIEventScope.Create(nameof(SNIMarsConnection))) + using (TrySNIEventScope.Create(nameof(SniMarsConnection))) { SNISMUXHeader currentHeader = null; SNIPacket currentPacket = null; @@ -213,7 +213,7 @@ public void HandleReceiveComplete(SNIPacket packet, uint sniErrorCode) lock (DemuxerSync) { HandleReceiveError(packet); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsConnection), EventType.ERR, "MARS Session Id {0}, Handled receive error code: {1}", args0: _lowerHandle?.ConnectionId, args1: sniErrorCode); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsConnection), EventType.ERR, "MARS Session Id {0}, Handled receive error code: {1}", args0: _lowerHandle?.ConnectionId, args1: sniErrorCode); return; } } @@ -236,7 +236,7 @@ public void HandleReceiveComplete(SNIPacket packet, uint sniErrorCode) if (bytesTaken == 0) { sniErrorCode = ReceiveAsync(ref packet); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsConnection), EventType.INFO, "MARS Session Id {0}, Non-SMUX Header SNI Packet received with code {1}", args0: ConnectionId, args1: sniErrorCode); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsConnection), EventType.INFO, "MARS Session Id {0}, Non-SMUX Header SNI Packet received with code {1}", args0: ConnectionId, args1: sniErrorCode); if (sniErrorCode == TdsEnums.SNI_SUCCESS_IO_PENDING) { @@ -244,7 +244,7 @@ public void HandleReceiveComplete(SNIPacket packet, uint sniErrorCode) } HandleReceiveError(packet); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsConnection), EventType.ERR, "MARS Session Id {0}, Handled receive error code: {1}", args0: _lowerHandle?.ConnectionId, args1: sniErrorCode); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsConnection), EventType.ERR, "MARS Session Id {0}, Handled receive error code: {1}", args0: _lowerHandle?.ConnectionId, args1: sniErrorCode); return; } } @@ -253,7 +253,7 @@ public void HandleReceiveComplete(SNIPacket packet, uint sniErrorCode) _dataBytesLeft = (int)_currentHeader.length; _currentPacket = _lowerHandle.RentPacket(headerSize: 0, dataSize: (int)_currentHeader.length); #if DEBUG - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsConnection), EventType.INFO, "MARS Session Id {0}, _dataBytesLeft {1}, _currentPacket {2}, Reading data of length: _currentHeader.length {3}", args0: _lowerHandle?.ConnectionId, args1: _dataBytesLeft, args2: currentPacket?._id, args3: _currentHeader?.length); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsConnection), EventType.INFO, "MARS Session Id {0}, _dataBytesLeft {1}, _currentPacket {2}, Reading data of length: _currentHeader.length {3}", args0: _lowerHandle?.ConnectionId, args1: _dataBytesLeft, args2: currentPacket?._id, args3: _currentHeader?.length); #endif } @@ -270,7 +270,7 @@ public void HandleReceiveComplete(SNIPacket packet, uint sniErrorCode) if (_dataBytesLeft > 0) { sniErrorCode = ReceiveAsync(ref packet); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsConnection), EventType.INFO, "MARS Session Id {0}, SMUX DATA Header SNI Packet received with code {1}, _dataBytesLeft {2}", args0: ConnectionId, args1: sniErrorCode, args2: _dataBytesLeft); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsConnection), EventType.INFO, "MARS Session Id {0}, SMUX DATA Header SNI Packet received with code {1}, _dataBytesLeft {2}", args0: ConnectionId, args1: sniErrorCode, args2: _dataBytesLeft); if (sniErrorCode == TdsEnums.SNI_SUCCESS_IO_PENDING) { @@ -278,7 +278,7 @@ public void HandleReceiveComplete(SNIPacket packet, uint sniErrorCode) } HandleReceiveError(packet); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsConnection), EventType.ERR, "MARS Session Id {0}, Handled receive error code: {1}", args0: _lowerHandle?.ConnectionId, args1: sniErrorCode); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsConnection), EventType.ERR, "MARS Session Id {0}, Handled receive error code: {1}", args0: _lowerHandle?.ConnectionId, args1: sniErrorCode); return; } } @@ -290,7 +290,7 @@ public void HandleReceiveComplete(SNIPacket packet, uint sniErrorCode) { SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.SMUX_PROV, 0, SNICommon.InvalidParameterError, Strings.SNI_ERROR_5); HandleReceiveError(packet); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsConnection), EventType.ERR, "Current Header Session Id {0} not found, MARS Session Id {1} will be destroyed, New SNI error created: {2}", args0: _currentHeader?.sessionId, args1: _lowerHandle?.ConnectionId, args2: sniErrorCode); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsConnection), EventType.ERR, "Current Header Session Id {0} not found, MARS Session Id {1} will be destroyed, New SNI error created: {2}", args0: _currentHeader?.sessionId, args1: _lowerHandle?.ConnectionId, args2: sniErrorCode); _lowerHandle.Dispose(); _lowerHandle = null; return; @@ -299,19 +299,19 @@ public void HandleReceiveComplete(SNIPacket packet, uint sniErrorCode) if (_currentHeader.flags == (byte)SNISMUXFlags.SMUX_FIN) { _sessions.Remove(_currentHeader.sessionId); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsConnection), EventType.INFO, "SMUX_FIN | MARS Session Id {0}, SMUX_FIN flag received, Current Header Session Id {1} removed", args0: _lowerHandle?.ConnectionId, args1: _currentHeader?.sessionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsConnection), EventType.INFO, "SMUX_FIN | MARS Session Id {0}, SMUX_FIN flag received, Current Header Session Id {1} removed", args0: _lowerHandle?.ConnectionId, args1: _currentHeader?.sessionId); } else { currentSession = _sessions[_currentHeader.sessionId]; - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsConnection), EventType.INFO, "MARS Session Id {0}, Current Session assigned to Session Id {1}", args0: _lowerHandle?.ConnectionId, args1: _currentHeader?.sessionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsConnection), EventType.INFO, "MARS Session Id {0}, Current Session assigned to Session Id {1}", args0: _lowerHandle?.ConnectionId, args1: _currentHeader?.sessionId); } } if (currentHeader.flags == (byte)SNISMUXFlags.SMUX_DATA) { currentSession.HandleReceiveComplete(currentPacket, currentHeader); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsConnection), EventType.INFO, "SMUX_DATA | MARS Session Id {0}, Current Session {1} completed receiving Data", args0: _lowerHandle?.ConnectionId, args1: _currentHeader?.sessionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsConnection), EventType.INFO, "SMUX_DATA | MARS Session Id {0}, Current Session {1} completed receiving Data", args0: _lowerHandle?.ConnectionId, args1: _currentHeader?.sessionId); } if (_currentHeader.flags == (byte)SNISMUXFlags.SMUX_ACK) @@ -319,16 +319,16 @@ public void HandleReceiveComplete(SNIPacket packet, uint sniErrorCode) try { currentSession.HandleAck(currentHeader.highwater); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsConnection), EventType.INFO, "SMUX_ACK | MARS Session Id {0}, Current Session {1} handled ack", args0: _lowerHandle?.ConnectionId, args1: _currentHeader?.sessionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsConnection), EventType.INFO, "SMUX_ACK | MARS Session Id {0}, Current Session {1} handled ack", args0: _lowerHandle?.ConnectionId, args1: _currentHeader?.sessionId); } catch (Exception e) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsConnection), EventType.ERR, "SMUX_ACK | MARS Session Id {0}, Exception occurred: {2}", args0: _currentHeader?.sessionId, args1: e?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsConnection), EventType.ERR, "SMUX_ACK | MARS Session Id {0}, Exception occurred: {2}", args0: _currentHeader?.sessionId, args1: e?.Message); SNICommon.ReportSNIError(SNIProviders.SMUX_PROV, SNICommon.InternalExceptionError, e); } #if DEBUG Debug.Assert(_currentPacket == currentPacket, "current and _current are not the same"); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsConnection), EventType.INFO, "SMUX_ACK | MARS Session Id {0}, Current Packet {1} returned", args0: _lowerHandle?.ConnectionId, args1: currentPacket?._id); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsConnection), EventType.INFO, "SMUX_ACK | MARS Session Id {0}, Current Packet {1} returned", args0: _lowerHandle?.ConnectionId, args1: currentPacket?._id); #endif ReturnPacket(currentPacket); currentPacket = null; @@ -347,7 +347,7 @@ public void HandleReceiveComplete(SNIPacket packet, uint sniErrorCode) } HandleReceiveError(packet); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsConnection), EventType.ERR, "MARS Session Id {0}, packet.DataLeft 0, SNI error {2}", args0: _lowerHandle?.ConnectionId, args1: sniErrorCode); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsConnection), EventType.ERR, "MARS Session Id {0}, packet.DataLeft 0, SNI error {2}", args0: _lowerHandle?.ConnectionId, args1: sniErrorCode); return; } } @@ -360,7 +360,7 @@ public void HandleReceiveComplete(SNIPacket packet, uint sniErrorCode) /// public uint EnableSsl(uint options) { - using (TrySNIEventScope.Create(nameof(SNIMarsConnection))) + using (TrySNIEventScope.Create(nameof(SniMarsConnection))) { return _lowerHandle.EnableSsl(options); } @@ -371,7 +371,7 @@ public uint EnableSsl(uint options) /// public void DisableSsl() { - using (TrySNIEventScope.Create(nameof(SNIMarsConnection))) + using (TrySNIEventScope.Create(nameof(SniMarsConnection))) { _lowerHandle.DisableSsl(); } @@ -393,7 +393,7 @@ public void ReturnPacket(SNIPacket packet) /// public void KillConnection() { - using (TrySNIEventScope.Create(nameof(SNIMarsConnection))) + using (TrySNIEventScope.Create(nameof(SniMarsConnection))) { _lowerHandle.KillConnection(); } From fd9462c35ca70a488ccd6c59b616b3116796c84e Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Tue, 13 May 2025 12:18:56 -0500 Subject: [PATCH 07/26] SNIMarsHandle => SniMarsHandle --- .../src/Microsoft.Data.SqlClient.csproj | 4 +- .../SqlClient/TdsParserStateObjectManaged.cs | 2 +- .../ManagedSni/SniMarsConnection.netcore.cs | 12 +-- ...le.netcore.cs => SniMarsHandle.netcore.cs} | 94 +++++++++---------- 4 files changed, 56 insertions(+), 56 deletions(-) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/{SNIMarsHandle.netcore.cs => SniMarsHandle.netcore.cs} (89%) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index fb16b8b13c..19e8a12822 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -290,8 +290,8 @@ Microsoft\Data\SqlClient\ManagedSni\SniMarsConnection.netcore.cs - - Microsoft\Data\SqlClient\ManagedSni\SNIMarsHandle.netcore.cs + + Microsoft\Data\SqlClient\ManagedSni\SniMarsHandle.netcore.cs Microsoft\Data\SqlClient\ManagedSni\SNINpHandle.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs index 97187fb526..90b30e71f1 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs @@ -51,7 +51,7 @@ protected override void CreateSessionHandle(TdsParserStateObject physicalConnect } } - internal SNIMarsHandle CreateMarsSession(object callbackObject, bool async) + internal SniMarsHandle CreateMarsSession(object callbackObject, bool async) { SqlClientEventSource.Log.TryTraceEvent("TdsParserStateObjectManaged.CreateMarsSession | Info | State Object Id {0}, Session Id {1}, Async = {2}", _objectID, _sessionHandle?.ConnectionId, async); if (_marsConnection is null) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsConnection.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsConnection.netcore.cs index 1d6282cf4d..28651bf6a8 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsConnection.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsConnection.netcore.cs @@ -15,7 +15,7 @@ namespace Microsoft.Data.SqlClient.ManagedSni internal class SniMarsConnection { private readonly Guid _connectionId; - private readonly Dictionary _sessions; + private readonly Dictionary _sessions; private readonly byte[] _headerBytes; private readonly SNISMUXHeader _currentHeader; private readonly object _sync; @@ -42,7 +42,7 @@ public SniMarsConnection(SniHandle lowerHandle) { _sync = new object(); _connectionId = Guid.NewGuid(); - _sessions = new Dictionary(); + _sessions = new Dictionary(); _headerBytes = new byte[SNISMUXHeader.HEADER_LENGTH]; _currentHeader = new SNISMUXHeader(); _nextSessionId = 0; @@ -53,12 +53,12 @@ public SniMarsConnection(SniHandle lowerHandle) _lowerHandle.SetAsyncCallbacks(HandleReceiveComplete, HandleSendComplete); } - public SNIMarsHandle CreateMarsSession(object callbackObject, bool async) + public SniMarsHandle CreateMarsSession(object callbackObject, bool async) { lock (DemuxerSync) { ushort sessionId = _nextSessionId++; - SNIMarsHandle handle = new SNIMarsHandle(this, sessionId, callbackObject, async); + SniMarsHandle handle = new SniMarsHandle(this, sessionId, callbackObject, async); _sessions.Add(sessionId, handle); SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsConnection), EventType.INFO, "MARS Session Id {0}, SNI MARS Handle Id {1}, created new MARS Session {2}", args0: ConnectionId, args1: handle?.ConnectionId, args2: sessionId); return handle; @@ -167,7 +167,7 @@ public uint CheckConnection() public void HandleReceiveError(SNIPacket packet) { Debug.Assert(Monitor.IsEntered(this), "HandleReceiveError was called without being locked."); - foreach (SNIMarsHandle handle in _sessions.Values) + foreach (SniMarsHandle handle in _sessions.Values) { if (packet.HasAsyncIOCompletionCallback) { @@ -206,7 +206,7 @@ public void HandleReceiveComplete(SNIPacket packet, uint sniErrorCode) { SNISMUXHeader currentHeader = null; SNIPacket currentPacket = null; - SNIMarsHandle currentSession = null; + SniMarsHandle currentSession = null; if (sniErrorCode != TdsEnums.SNI_SUCCESS) { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsHandle.netcore.cs similarity index 89% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsHandle.netcore.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsHandle.netcore.cs index 7572f6e589..bac90ff489 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIMarsHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsHandle.netcore.cs @@ -12,7 +12,7 @@ namespace Microsoft.Data.SqlClient.ManagedSni /// /// MARS handle /// - internal sealed class SNIMarsHandle : SniHandle + internal sealed class SniMarsHandle : SniHandle { private const uint ACK_THRESHOLD = 2; @@ -54,16 +54,16 @@ internal sealed class SNIMarsHandle : SniHandle /// public override void Dispose() { - using (TrySNIEventScope.Create(nameof(SNIMarsHandle))) + using (TrySNIEventScope.Create(nameof(SniMarsHandle))) { try { SendControlPacket(SNISMUXFlags.SMUX_FIN); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, Sent SMUX_FIN packet to terminate session.", args0: ConnectionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, Sent SMUX_FIN packet to terminate session.", args0: ConnectionId); } catch (Exception e) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.ERR, "MARS Session Id {0}, Internal exception error = {1}, Member Name={2}", args0: ConnectionId, args1: e?.Message, args2: e?.GetType()?.Name); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.ERR, "MARS Session Id {0}, Internal exception error = {1}, Member Name={2}", args0: ConnectionId, args1: e?.Message, args2: e?.GetType()?.Name); SNICommon.ReportSNIError(SNIProviders.SMUX_PROV, SNICommon.InternalExceptionError, e); } } @@ -76,7 +76,7 @@ public override void Dispose() /// MARS session ID /// Callback object /// true if connection is asynchronous - public SNIMarsHandle(SniMarsConnection connection, ushort sessionId, object callbackObject, bool async) + public SniMarsHandle(SniMarsConnection connection, ushort sessionId, object callbackObject, bool async) { _sessionId = sessionId; _connection = connection; @@ -84,7 +84,7 @@ public SNIMarsHandle(SniMarsConnection connection, ushort sessionId, object call _callbackObject = callbackObject; _handleSendCompleteCallback = HandleSendComplete; SendControlPacket(SNISMUXFlags.SMUX_SYN); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, Sent SMUX_SYN packet to start a new session, session Id {1}", args0: ConnectionId, args1: _sessionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, Sent SMUX_SYN packet to start a new session, session Id {1}", args0: ConnectionId, args1: _sessionId); _status = TdsEnums.SNI_SUCCESS; } @@ -94,11 +94,11 @@ public SNIMarsHandle(SniMarsConnection connection, ushort sessionId, object call /// SMUX header flags private void SendControlPacket(SNISMUXFlags flags) { - using (TrySNIEventScope.Create(nameof(SNIMarsHandle))) + using (TrySNIEventScope.Create(nameof(SniMarsHandle))) { SNIPacket packet = RentPacket(headerSize: SNISMUXHeader.HEADER_LENGTH, dataSize: 0); #if DEBUG - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, Packet rented {1}, packet dataLeft {2}", args0: ConnectionId, args1: packet?._id, args2: packet?.DataLeft); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, Packet rented {1}, packet dataLeft {2}", args0: ConnectionId, args1: packet?._id, args2: packet?.DataLeft); #endif lock (this) { @@ -110,7 +110,7 @@ private void SendControlPacket(SNISMUXFlags flags) _connection.Send(packet); ReturnPacket(packet); #if DEBUG - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, Packet returned {1}, packet dataLeft {2}", args0: ConnectionId, args1: packet?._id, args2: packet?.DataLeft); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, Packet returned {1}, packet dataLeft {2}", args0: ConnectionId, args1: packet?._id, args2: packet?.DataLeft); ; #endif } @@ -142,7 +142,7 @@ private SNIPacket SetPacketSMUXHeader(SNIPacket packet) _currentHeader.Write(packet.GetHeaderBuffer(SNISMUXHeader.HEADER_LENGTH)); packet.SetHeaderActive(); #if DEBUG - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, Setting SMUX_DATA header in current header for packet {1}", args0: ConnectionId, args1: packet?._id); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, Setting SMUX_DATA header in current header for packet {1}", args0: ConnectionId, args1: packet?._id); #endif return packet; } @@ -155,7 +155,7 @@ private SNIPacket SetPacketSMUXHeader(SNIPacket packet) public override uint Send(SNIPacket packet) { Debug.Assert(packet.ReservedHeaderSize == SNISMUXHeader.HEADER_LENGTH, "mars handle attempting to send muxed packet without smux reservation in Send"); - using (TrySNIEventScope.Create(nameof(SNIMarsHandle))) + using (TrySNIEventScope.Create(nameof(SniMarsHandle))) { while (true) { @@ -167,12 +167,12 @@ public override uint Send(SNIPacket packet) } } - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, Waiting for Acknowledgment event.", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, Waiting for Acknowledgment event.", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater); _ackEvent.Wait(); lock (this) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, _sendPacketQueue count found {1}, Acknowledgment event Reset", args0: ConnectionId, args1: _sendPacketQueue?.Count); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, _sendPacketQueue count found {1}, Acknowledgment event Reset", args0: ConnectionId, args1: _sendPacketQueue?.Count); _ackEvent.Reset(); } } @@ -182,7 +182,7 @@ public override uint Send(SNIPacket packet) { muxedPacket = SetPacketSMUXHeader(packet); } - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, SMUX Packet is going to be sent.", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, SMUX Packet is going to be sent.", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater); return _connection.Send(muxedPacket); } } @@ -195,19 +195,19 @@ public override uint Send(SNIPacket packet) private uint InternalSendAsync(SNIPacket packet) { Debug.Assert(packet.ReservedHeaderSize == SNISMUXHeader.HEADER_LENGTH, "mars handle attempting to send muxed packet without smux reservation in InternalSendAsync"); - using (TrySNIEventScope.Create(nameof(SNIMarsHandle))) + using (TrySNIEventScope.Create(nameof(SniMarsHandle))) { lock (this) { if (_sequenceNumber >= _sendHighwater) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, SNI Queue is full", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, SNI Queue is full", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater); return TdsEnums.SNI_QUEUE_FULL; } SNIPacket muxedPacket = SetPacketSMUXHeader(packet); muxedPacket.SetAsyncIOCompletionCallback(_handleSendCompleteCallback); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, Sending packet", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, Sending packet", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater); return _connection.SendAsync(muxedPacket); } } @@ -219,7 +219,7 @@ private uint InternalSendAsync(SNIPacket packet) /// SNI error code private uint SendPendingPackets() { - using (TrySNIEventScope.Create(nameof(SNIMarsHandle))) + using (TrySNIEventScope.Create(nameof(SniMarsHandle))) { SNIPacket packet = null; @@ -236,18 +236,18 @@ private uint SendPendingPackets() if (result != TdsEnums.SNI_SUCCESS && result != TdsEnums.SNI_SUCCESS_IO_PENDING) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.ERR, "MARS Session Id {0}, InternalSendAsync result is not SNI_SUCCESS and is not SNI_SUCCESS_IO_PENDING", args0: ConnectionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.ERR, "MARS Session Id {0}, InternalSendAsync result is not SNI_SUCCESS and is not SNI_SUCCESS_IO_PENDING", args0: ConnectionId); return result; } _sendPacketQueue.Dequeue(); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, _sendPacketQueue dequeued, count {1}", args0: ConnectionId, args1: _sendPacketQueue?.Count); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, _sendPacketQueue dequeued, count {1}", args0: ConnectionId, args1: _sendPacketQueue?.Count); continue; } else { _ackEvent.Set(); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, _sendPacketQueue count found {1}, acknowledgment set", args0: ConnectionId, args1: _sendPacketQueue?.Count); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, _sendPacketQueue count found {1}, acknowledgment set", args0: ConnectionId, args1: _sendPacketQueue?.Count); } } @@ -266,7 +266,7 @@ private uint SendPendingPackets() /// SNI error code public override uint SendAsync(SNIPacket packet) { - using (TrySNIEventScope.Create(nameof(SNIMarsHandle))) + using (TrySNIEventScope.Create(nameof(SniMarsHandle))) { packet.SetAsyncIOCompletionCallback(_handleSendCompleteCallback); lock (this) @@ -275,7 +275,7 @@ public override uint SendAsync(SNIPacket packet) } SendPendingPackets(); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, _sendPacketQueue enqueued, count {1}", args0: ConnectionId, args1: _sendPacketQueue?.Count); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, _sendPacketQueue enqueued, count {1}", args0: ConnectionId, args1: _sendPacketQueue?.Count); return TdsEnums.SNI_SUCCESS_IO_PENDING; } @@ -288,7 +288,7 @@ public override uint SendAsync(SNIPacket packet) /// SNI error code public override uint ReceiveAsync(ref SNIPacket packet) { - using (TrySNIEventScope.Create(nameof(SNIMarsHandle))) + using (TrySNIEventScope.Create(nameof(SniMarsHandle))) { lock (_receivedPacketQueue) { @@ -296,14 +296,14 @@ public override uint ReceiveAsync(ref SNIPacket packet) if (_connectionError != null) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.ERR, "MARS Session Id {0}, _asyncReceives {1}, _receiveHighwater {2}, _sendHighwater {3}, _receiveHighwaterLastAck {4}, _connectionError {5}", args0: ConnectionId, args1: _asyncReceives, args2: _receiveHighwater, args3: _sendHighwater, args4: _receiveHighwaterLastAck, args5: _connectionError); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.ERR, "MARS Session Id {0}, _asyncReceives {1}, _receiveHighwater {2}, _sendHighwater {3}, _receiveHighwaterLastAck {4}, _connectionError {5}", args0: ConnectionId, args1: _asyncReceives, args2: _receiveHighwater, args3: _sendHighwater, args4: _receiveHighwaterLastAck, args5: _connectionError); return SNICommon.ReportSNIError(_connectionError); } if (queueCount == 0) { _asyncReceives++; - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, queueCount 0, _asyncReceives {1}, _receiveHighwater {2}, _sendHighwater {3}, _receiveHighwaterLastAck {4}", args0: ConnectionId, args1: _asyncReceives, args2: _receiveHighwater, args3: _sendHighwater, args4: _receiveHighwaterLastAck); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, queueCount 0, _asyncReceives {1}, _receiveHighwater {2}, _sendHighwater {3}, _receiveHighwaterLastAck {4}", args0: ConnectionId, args1: _asyncReceives, args2: _receiveHighwater, args3: _sendHighwater, args4: _receiveHighwaterLastAck); return TdsEnums.SNI_SUCCESS_IO_PENDING; } @@ -313,7 +313,7 @@ public override uint ReceiveAsync(ref SNIPacket packet) if (queueCount == 1) { #if DEBUG - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, packet dequeued {1}, packet Owner {2}, packet refCount {3}, received Packet Queue count {4}", args0: ConnectionId, args1: packet?._id, args2: packet?._owner, args3: packet?._refCount, args4: _receivedPacketQueue?.Count); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, packet dequeued {1}, packet Owner {2}, packet refCount {3}, received Packet Queue count {4}", args0: ConnectionId, args1: packet?._id, args2: packet?._owner, args3: packet?._refCount, args4: _receivedPacketQueue?.Count); #endif _packetEvent.Reset(); } @@ -324,7 +324,7 @@ public override uint ReceiveAsync(ref SNIPacket packet) _receiveHighwater++; } - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, _asyncReceives {1}, _receiveHighwater {2}, _sendHighwater {3}, _receiveHighwaterLastAck {4}, queueCount {5}", args0: ConnectionId, args1: _asyncReceives, args2: _receiveHighwater, args3: _sendHighwater, args4: _receiveHighwaterLastAck, args5: _receivedPacketQueue?.Count); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, _asyncReceives {1}, _receiveHighwater {2}, _sendHighwater {3}, _receiveHighwaterLastAck {4}, queueCount {5}", args0: ConnectionId, args1: _asyncReceives, args2: _receiveHighwater, args3: _sendHighwater, args4: _receiveHighwaterLastAck, args5: _receivedPacketQueue?.Count); SendAckIfNecessary(); return TdsEnums.SNI_SUCCESS; } @@ -335,7 +335,7 @@ public override uint ReceiveAsync(ref SNIPacket packet) /// public void HandleReceiveError(SNIPacket packet) { - using (TrySNIEventScope.Create(nameof(SNIMarsHandle))) + using (TrySNIEventScope.Create(nameof(SniMarsHandle))) { // SNIMarsHandle should only receive calls to this function from the SNIMarsConnection aggregator class // which should handle ownership of the packet because the individual mars handles are not aware of @@ -344,7 +344,7 @@ public void HandleReceiveError(SNIPacket packet) lock (_receivedPacketQueue) { _connectionError = SniLoadHandle.SingletonInstance.LastError; - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.ERR, "MARS Session Id {0}, _connectionError to be handled: {1}", args0: ConnectionId, args1: _connectionError); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.ERR, "MARS Session Id {0}, _connectionError to be handled: {1}", args0: ConnectionId, args1: _connectionError); _packetEvent.Set(); } @@ -359,7 +359,7 @@ public void HandleReceiveError(SNIPacket packet) /// SNI error code public void HandleSendComplete(SNIPacket packet, uint sniErrorCode) { - using (TrySNIEventScope.Create(nameof(SNIMarsHandle))) + using (TrySNIEventScope.Create(nameof(SniMarsHandle))) { lock (this) { @@ -369,7 +369,7 @@ public void HandleSendComplete(SNIPacket packet, uint sniErrorCode) } _connection.ReturnPacket(packet); #if DEBUG - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, Returned Packet: {1}", args0: ConnectionId, args1: packet?._id); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, Returned Packet: {1}", args0: ConnectionId, args1: packet?._id); #endif } } @@ -380,13 +380,13 @@ public void HandleSendComplete(SNIPacket packet, uint sniErrorCode) /// Send highwater mark public void HandleAck(uint highwater) { - using (TrySNIEventScope.Create(nameof(SNIMarsHandle))) + using (TrySNIEventScope.Create(nameof(SniMarsHandle))) { lock (this) { if (_sendHighwater != highwater) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, Setting _sendHighwater {1} to highwater {2} and send pending packets.", args0: ConnectionId, args1: _sendHighwater, args2: highwater); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, Setting _sendHighwater {1} to highwater {2} and send pending packets.", args0: ConnectionId, args1: _sendHighwater, args2: highwater); _sendHighwater = highwater; SendPendingPackets(); } @@ -401,13 +401,13 @@ public void HandleAck(uint highwater) /// SMUX header public void HandleReceiveComplete(SNIPacket packet, SNISMUXHeader header) { - using (TrySNIEventScope.Create(nameof(SNIMarsHandle))) + using (TrySNIEventScope.Create(nameof(SniMarsHandle))) { lock (this) { if (_sendHighwater != header.highwater) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, header.highwater {1}, _sendHighwater {2}, Handle Ack with header.highwater", args0: ConnectionId, args1: header?.highwater, args2: _sendHighwater); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, header.highwater {1}, _sendHighwater {2}, Handle Ack with header.highwater", args0: ConnectionId, args1: header?.highwater, args2: _sendHighwater); HandleAck(header.highwater); } @@ -417,13 +417,13 @@ public void HandleReceiveComplete(SNIPacket packet, SNISMUXHeader header) { _receivedPacketQueue.Enqueue(packet); _packetEvent.Set(); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, _receivedPacketQueue count {3}, packet event set", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater, args3: _receivedPacketQueue?.Count); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, _receivedPacketQueue count {3}, packet event set", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater, args3: _receivedPacketQueue?.Count); return; } _asyncReceives--; Debug.Assert(_callbackObject != null); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, _asyncReceives {3}", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater, args3: _asyncReceives); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, _asyncReceives {3}", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater, args3: _asyncReceives); ((TdsParserStateObject)_callbackObject).ReadAsyncCallback(PacketHandle.FromManagedPacket(packet), 0); } @@ -435,7 +435,7 @@ public void HandleReceiveComplete(SNIPacket packet, SNISMUXHeader header) { _receiveHighwater++; } - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, _asyncReceives {1}, _receiveHighwater {2}, _sendHighwater {3}, _receiveHighwaterLastAck {4}", args0: ConnectionId, args1: _asyncReceives, args2: _receiveHighwater, args3: _sendHighwater, args4: _receiveHighwaterLastAck); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, _asyncReceives {1}, _receiveHighwater {2}, _sendHighwater {3}, _receiveHighwaterLastAck {4}", args0: ConnectionId, args1: _asyncReceives, args2: _receiveHighwater, args3: _sendHighwater, args4: _receiveHighwaterLastAck); SendAckIfNecessary(); } } @@ -457,7 +457,7 @@ private void SendAckIfNecessary() if (receiveHighwater - receiveHighwaterLastAck > ACK_THRESHOLD) { SendControlPacket(SNISMUXFlags.SMUX_ACK); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, _asyncReceives {1}, _receiveHighwater {2}, _sendHighwater {3}, _receiveHighwaterLastAck {4} Sending acknowledgment ACK_THRESHOLD {5}", args0: ConnectionId, args1: _asyncReceives, args2: _receiveHighwater, args3: _sendHighwater, args4: _receiveHighwaterLastAck, args5: ACK_THRESHOLD); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, _asyncReceives {1}, _receiveHighwater {2}, _sendHighwater {3}, _receiveHighwaterLastAck {4} Sending acknowledgment ACK_THRESHOLD {5}", args0: ConnectionId, args1: _asyncReceives, args2: _receiveHighwater, args3: _sendHighwater, args4: _receiveHighwaterLastAck, args5: ACK_THRESHOLD); } } @@ -469,7 +469,7 @@ private void SendAckIfNecessary() /// SNI error code public override uint Receive(out SNIPacket packet, int timeoutInMilliseconds) { - using (TrySNIEventScope.Create(nameof(SNIMarsHandle))) + using (TrySNIEventScope.Create(nameof(SniMarsHandle))) { packet = null; int queueCount; @@ -481,12 +481,12 @@ public override uint Receive(out SNIPacket packet, int timeoutInMilliseconds) { if (_connectionError != null) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.ERR, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, _connectionError found: {3}.", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater, args3: _connectionError); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.ERR, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, _connectionError found: {3}.", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater, args3: _connectionError); return SNICommon.ReportSNIError(_connectionError); } queueCount = _receivedPacketQueue.Count; - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, W_receivedPacketQueue count {3}.", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater, args3: queueCount); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, W_receivedPacketQueue count {3}.", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater, args3: queueCount); if (queueCount > 0) { @@ -495,7 +495,7 @@ public override uint Receive(out SNIPacket packet, int timeoutInMilliseconds) if (queueCount == 1) { _packetEvent.Reset(); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, packet event reset, _receivedPacketQueue count 1.", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, packet event reset, _receivedPacketQueue count 1.", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater); } result = TdsEnums.SNI_SUCCESS; @@ -510,15 +510,15 @@ public override uint Receive(out SNIPacket packet, int timeoutInMilliseconds) } SendAckIfNecessary(); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, returning with result {3}.", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater, args3: result); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, returning with result {3}.", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater, args3: result); return result; } - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, Waiting for packet event.", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, Waiting for packet event.", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater); if (!_packetEvent.Wait(timeoutInMilliseconds)) { SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.SMUX_PROV, 0, SNICommon.ConnTimeoutError, Strings.SNI_ERROR_11); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIMarsHandle), EventType.INFO, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, _packetEvent wait timed out.", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, _packetEvent wait timed out.", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater); return TdsEnums.SNI_WAIT_TIMEOUT; } } From 43cb86f747664de372768a7850bf742ad246d077 Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Tue, 13 May 2025 12:25:32 -0500 Subject: [PATCH 08/26] SNINpHandle => SniNpHandle --- .../src/Microsoft.Data.SqlClient.csproj | 4 +- .../SqlClient/ManagedSni/SNIProxy.netcore.cs | 6 +- ...ndle.netcore.cs => SniNpHandle.netcore.cs} | 72 +++++++++---------- 3 files changed, 41 insertions(+), 41 deletions(-) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/{SNINpHandle.netcore.cs => SniNpHandle.netcore.cs} (89%) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index 19e8a12822..2de6d50ef2 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -293,8 +293,8 @@ Microsoft\Data\SqlClient\ManagedSni\SniMarsHandle.netcore.cs - - Microsoft\Data\SqlClient\ManagedSni\SNINpHandle.netcore.cs + + Microsoft\Data\SqlClient\ManagedSni\SniNpHandle.netcore.cs Microsoft\Data\SqlClient\ManagedSni\SNIPacket.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIProxy.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIProxy.netcore.cs index 7f4cd03b47..754f0fd596 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIProxy.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIProxy.netcore.cs @@ -248,7 +248,7 @@ private static SNITCPHandle CreateTcpHandle( /// Host name in certificate /// Used for the path to the Server Certificate /// SNINpHandle - private static SNINpHandle CreateNpHandle(DataSource details, TimeoutTimer timeout, bool parallel, bool tlsFirst, string hostNameInCertificate, string serverCertificateFilename) + private static SniNpHandle CreateNpHandle(DataSource details, TimeoutTimer timeout, bool parallel, bool tlsFirst, string hostNameInCertificate, string serverCertificateFilename) { if (parallel) { @@ -256,7 +256,7 @@ private static SNINpHandle CreateNpHandle(DataSource details, TimeoutTimer timeo SNICommon.ReportSNIError(SNIProviders.NP_PROV, 0, SNICommon.MultiSubnetFailoverWithNonTcpProtocol, Strings.SNI_ERROR_49); return null; } - return new SNINpHandle(details.PipeHostName, details.PipeName, timeout, tlsFirst, hostNameInCertificate, serverCertificateFilename); + return new SniNpHandle(details.PipeHostName, details.PipeName, timeout, tlsFirst, hostNameInCertificate, serverCertificateFilename); } /// @@ -619,7 +619,7 @@ private bool InferNamedPipesInformation() else { PipeHostName = ServerName = _dataSourceAfterTrimmingProtocol; - PipeName = SNINpHandle.DefaultPipePath; + PipeName = SniNpHandle.DefaultPipePath; } InferLocalServerName(); diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNINpHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs similarity index 89% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNINpHandle.netcore.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs index 69aedd00e1..cd52bf9860 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNINpHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs @@ -17,7 +17,7 @@ namespace Microsoft.Data.SqlClient.ManagedSni /// /// Named Pipe connection handle /// - internal sealed class SNINpHandle : SNIPhysicalHandle + internal sealed class SniNpHandle : SNIPhysicalHandle { internal const string DefaultPipePath = @"sql\query"; // e.g. \\HOSTNAME\pipe\sql\query // private const int MAX_PIPE_INSTANCES = 255; // TODO: Investigate pipe instance limit. @@ -40,11 +40,11 @@ internal sealed class SNINpHandle : SNIPhysicalHandle private int _bufferSize = TdsEnums.DEFAULT_LOGIN_PACKET_SIZE; private readonly Guid _connectionId = Guid.NewGuid(); - public SNINpHandle(string serverName, string pipeName, TimeoutTimer timeout, bool tlsFirst, string hostNameInCertificate, string serverCertificateFilename) + public SniNpHandle(string serverName, string pipeName, TimeoutTimer timeout, bool tlsFirst, string hostNameInCertificate, string serverCertificateFilename) { - using (TrySNIEventScope.Create(nameof(SNINpHandle))) + using (TrySNIEventScope.Create(nameof(SniNpHandle))) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNINpHandle), EventType.INFO, "Connection Id {0}, Setting server name = {1}, pipe name = {2}", args0: _connectionId, args1: serverName, args2: pipeName); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.INFO, "Connection Id {0}, Setting server name = {1}, pipe name = {2}", args0: _connectionId, args1: serverName, args2: pipeName); _sendSync = new object(); _targetServer = serverName; @@ -61,7 +61,7 @@ public SNINpHandle(string serverName, string pipeName, TimeoutTimer timeout, boo if (timeout.IsInfinite) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNINpHandle), EventType.INFO, + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.INFO, "Connection Id {0}, Setting server name = {1}, pipe name = {2}. Connecting with infinite timeout.", args0: _connectionId, args1: serverName, @@ -71,7 +71,7 @@ public SNINpHandle(string serverName, string pipeName, TimeoutTimer timeout, boo else { int timeoutMilliseconds = timeout.MillisecondsRemainingInt; - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNINpHandle), EventType.INFO, + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.INFO, "Connection Id {0}, Setting server name = {1}, pipe name = {2}. Connecting within the {3} specified milliseconds.", args0: _connectionId, args1: serverName, @@ -84,14 +84,14 @@ public SNINpHandle(string serverName, string pipeName, TimeoutTimer timeout, boo { SNICommon.ReportSNIError(SNIProviders.NP_PROV, SNICommon.ConnOpenFailedError, te); _status = TdsEnums.SNI_ERROR; - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNINpHandle), EventType.ERR, "Connection Id {0}, Connection Timed out. Error Code 1 Exception = {1}", args0: _connectionId, args1: te?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.ERR, "Connection Id {0}, Connection Timed out. Error Code 1 Exception = {1}", args0: _connectionId, args1: te?.Message); return; } catch (IOException ioe) { SNICommon.ReportSNIError(SNIProviders.NP_PROV, SNICommon.ConnOpenFailedError, ioe); _status = TdsEnums.SNI_ERROR; - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNINpHandle), EventType.ERR, "Connection Id {0}, IO Exception occurred. Error Code 1 Exception = {1}", args0: _connectionId, args1: ioe?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.ERR, "Connection Id {0}, IO Exception occurred. Error Code 1 Exception = {1}", args0: _connectionId, args1: ioe?.Message); return; } @@ -99,7 +99,7 @@ public SNINpHandle(string serverName, string pipeName, TimeoutTimer timeout, boo { SNICommon.ReportSNIError(SNIProviders.NP_PROV, 0, SNICommon.ConnOpenFailedError, Strings.SNI_ERROR_40); _status = TdsEnums.SNI_ERROR; - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNINpHandle), EventType.ERR, "Connection Id {0}, Pipe Stream not operational. Error Code 1 Exception = {1}", args0: _connectionId, args1: Strings.SNI_ERROR_1); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.ERR, "Connection Id {0}, Pipe Stream not operational. Error Code 1 Exception = {1}", args0: _connectionId, args1: Strings.SNI_ERROR_1); return; } @@ -138,16 +138,16 @@ public override int ProtocolVersion public override uint CheckConnection() { - using (TrySNIEventScope.Create(nameof(SNINpHandle))) + using (TrySNIEventScope.Create(nameof(SniNpHandle))) { if (!_stream.CanWrite || !_stream.CanRead) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNINpHandle), EventType.ERR, "Connection Id {0}, Cannot write or read to/from the stream", args0: _connectionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.ERR, "Connection Id {0}, Cannot write or read to/from the stream", args0: _connectionId); return TdsEnums.SNI_ERROR; } else { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNINpHandle), EventType.INFO, "Connection Id {0}, Can read and write to/from stream.", args0: _connectionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.INFO, "Connection Id {0}, Can read and write to/from stream.", args0: _connectionId); return TdsEnums.SNI_SUCCESS; } } @@ -177,13 +177,13 @@ public override void Dispose() //Release any references held by _stream. _stream = null; - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNINpHandle), EventType.INFO, "Connection Id {0}, All streams disposed and references cleared.", args0: _connectionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.INFO, "Connection Id {0}, All streams disposed and references cleared.", args0: _connectionId); } } public override uint Receive(out SNIPacket packet, int timeout) { - using (TrySNIEventScope.Create(nameof(SNINpHandle))) + using (TrySNIEventScope.Create(nameof(SniNpHandle))) { SNIPacket errorPacket; lock (this) @@ -193,14 +193,14 @@ public override uint Receive(out SNIPacket packet, int timeout) { packet = RentPacket(headerSize: 0, dataSize: _bufferSize); packet.ReadFromStream(_stream); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNINpHandle), EventType.INFO, "Connection Id {0}, Rented and read packet, dataLeft {1}", args0: _connectionId, args1: packet?.DataLeft); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.INFO, "Connection Id {0}, Rented and read packet, dataLeft {1}", args0: _connectionId, args1: packet?.DataLeft); if (packet.Length == 0) { errorPacket = packet; packet = null; var e = new Win32Exception(); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNINpHandle), EventType.ERR, "Connection Id {0}, Packet length found 0, Win32 exception raised: {1}", args0: _connectionId, args1: e?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.ERR, "Connection Id {0}, Packet length found 0, Win32 exception raised: {1}", args0: _connectionId, args1: e?.Message); return ReportErrorAndReleasePacket(errorPacket, (uint)e.NativeErrorCode, 0, e.Message); } } @@ -208,14 +208,14 @@ public override uint Receive(out SNIPacket packet, int timeout) { errorPacket = packet; packet = null; - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNINpHandle), EventType.ERR, "Connection Id {0}, ObjectDisposedException occurred: {1}.", args0: _connectionId, args1: ode?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.ERR, "Connection Id {0}, ObjectDisposedException occurred: {1}.", args0: _connectionId, args1: ode?.Message); return ReportErrorAndReleasePacket(errorPacket, ode); } catch (IOException ioe) { errorPacket = packet; packet = null; - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNINpHandle), EventType.ERR, "Connection Id {0}, IOException occurred: {1}.", args0: _connectionId, args1: ioe?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.ERR, "Connection Id {0}, IOException occurred: {1}.", args0: _connectionId, args1: ioe?.Message); return ReportErrorAndReleasePacket(errorPacket, ioe); } return TdsEnums.SNI_SUCCESS; @@ -225,7 +225,7 @@ public override uint Receive(out SNIPacket packet, int timeout) public override uint ReceiveAsync(ref SNIPacket packet) { - using (TrySNIEventScope.Create(nameof(SNINpHandle))) + using (TrySNIEventScope.Create(nameof(SniNpHandle))) { SNIPacket errorPacket; packet = RentPacket(headerSize: 0, dataSize: _bufferSize); @@ -233,21 +233,21 @@ public override uint ReceiveAsync(ref SNIPacket packet) try { packet.ReadFromStreamAsync(_stream); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNINpHandle), EventType.INFO, "Connection Id {0}, Rented and read packet asynchronously, dataLeft {1}", args0: _connectionId, args1: packet?.DataLeft); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.INFO, "Connection Id {0}, Rented and read packet asynchronously, dataLeft {1}", args0: _connectionId, args1: packet?.DataLeft); return TdsEnums.SNI_SUCCESS_IO_PENDING; } catch (ObjectDisposedException ode) { errorPacket = packet; packet = null; - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNINpHandle), EventType.ERR, "Connection Id {0}, ObjectDisposedException occurred: {1}.", args0: _connectionId, args1: ode?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.ERR, "Connection Id {0}, ObjectDisposedException occurred: {1}.", args0: _connectionId, args1: ode?.Message); return ReportErrorAndReleasePacket(errorPacket, ode); } catch (IOException ioe) { errorPacket = packet; packet = null; - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNINpHandle), EventType.ERR, "Connection Id {0}, IOException occurred: {1}.", args0: _connectionId, args1: ioe?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.ERR, "Connection Id {0}, IOException occurred: {1}.", args0: _connectionId, args1: ioe?.Message); return ReportErrorAndReleasePacket(errorPacket, ioe); } } @@ -255,7 +255,7 @@ public override uint ReceiveAsync(ref SNIPacket packet) public override uint Send(SNIPacket packet) { - using (TrySNIEventScope.Create(nameof(SNINpHandle))) + using (TrySNIEventScope.Create(nameof(SniNpHandle))) { bool releaseLock = false; try @@ -281,18 +281,18 @@ public override uint Send(SNIPacket packet) { try { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNINpHandle), EventType.INFO, "Connection Id {0}, Packet writing to stream, dataLeft {1}", args0: _connectionId, args1: packet?.DataLeft); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.INFO, "Connection Id {0}, Packet writing to stream, dataLeft {1}", args0: _connectionId, args1: packet?.DataLeft); packet.WriteToStream(_stream); return TdsEnums.SNI_SUCCESS; } catch (ObjectDisposedException ode) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNINpHandle), EventType.ERR, "Connection Id {0}, ObjectDisposedException occurred: {1}.", args0: _connectionId, args1: ode?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.ERR, "Connection Id {0}, ObjectDisposedException occurred: {1}.", args0: _connectionId, args1: ode?.Message); return ReportErrorAndReleasePacket(packet, ode); } catch (IOException ioe) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNINpHandle), EventType.ERR, "Connection Id {0}, IOException occurred: {1}.", args0: _connectionId, args1: ioe?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.ERR, "Connection Id {0}, IOException occurred: {1}.", args0: _connectionId, args1: ioe?.Message); return ReportErrorAndReleasePacket(packet, ioe); } } @@ -309,9 +309,9 @@ public override uint Send(SNIPacket packet) public override uint SendAsync(SNIPacket packet) { - using (TrySNIEventScope.Create(nameof(SNINpHandle))) + using (TrySNIEventScope.Create(nameof(SniNpHandle))) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNINpHandle), EventType.INFO, "Connection Id {0}, Packet writing to stream, dataLeft {1}", args0: _connectionId, args1: packet?.DataLeft); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.INFO, "Connection Id {0}, Packet writing to stream, dataLeft {1}", args0: _connectionId, args1: packet?.DataLeft); packet.WriteToStreamAsync(_stream, _sendCallback, SNIProviders.NP_PROV); return TdsEnums.SNI_SUCCESS_IO_PENDING; } @@ -325,7 +325,7 @@ public override void SetAsyncCallbacks(SNIAsyncCallback receiveCallback, SNIAsyn public override uint EnableSsl(uint options) { - using (TrySNIEventScope.Create(nameof(SNINpHandle))) + using (TrySNIEventScope.Create(nameof(SniNpHandle))) { _validateCert = (options & TdsEnums.SNI_SSL_VALIDATE_CERTIFICATE) != 0; try @@ -346,12 +346,12 @@ public override uint EnableSsl(uint options) } catch (AuthenticationException aue) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNINpHandle), EventType.ERR, "Connection Id {0}, AuthenticationException message = {1}.", args0: ConnectionId, args1: aue?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.ERR, "Connection Id {0}, AuthenticationException message = {1}.", args0: ConnectionId, args1: aue?.Message); return SNICommon.ReportSNIError(SNIProviders.NP_PROV, SNICommon.InternalExceptionError, aue); } catch (InvalidOperationException ioe) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNINpHandle), EventType.ERR, "Connection Id {0}, InvalidOperationException message = {1}.", args0: ConnectionId, args1: ioe?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.ERR, "Connection Id {0}, InvalidOperationException message = {1}.", args0: ConnectionId, args1: ioe?.Message); return SNICommon.ReportSNIError(SNIProviders.NP_PROV, SNICommon.InternalExceptionError, ioe); } _stream = _sslStream; @@ -379,15 +379,15 @@ public override void DisableSsl() /// true if valid private bool ValidateServerCertificate(object sender, X509Certificate serverCertificate, X509Chain chain, SslPolicyErrors policyErrors) { - using (TrySNIEventScope.Create(nameof(SNINpHandle))) + using (TrySNIEventScope.Create(nameof(SniNpHandle))) { if (!_validateCert) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNINpHandle), EventType.INFO, "Connection Id {0}, Certificate validation not requested.", args0: ConnectionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.INFO, "Connection Id {0}, Certificate validation not requested.", args0: ConnectionId); return true; } - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNINpHandle), EventType.INFO, "Connection Id {0}, Proceeding to SSL certificate validation.", args0: ConnectionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.INFO, "Connection Id {0}, Proceeding to SSL certificate validation.", args0: ConnectionId); return SNICommon.ValidateSslServerCertificate(_connectionId, _targetServer, _hostNameInCertificate, serverCertificate, _serverCertificateFilename, policyErrors); } } @@ -407,7 +407,7 @@ private uint ReportErrorAndReleasePacket(SNIPacket packet, Exception sniExceptio { ReturnPacket(packet); } - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNINpHandle), EventType.INFO, "Connection Id {0}, Packet returned, error occurred: {1}", args0: ConnectionId, args1: sniException?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.INFO, "Connection Id {0}, Packet returned, error occurred: {1}", args0: ConnectionId, args1: sniException?.Message); return SNICommon.ReportSNIError(SNIProviders.NP_PROV, SNICommon.InternalExceptionError, sniException); } @@ -417,7 +417,7 @@ private uint ReportErrorAndReleasePacket(SNIPacket packet, uint nativeError, uin { ReturnPacket(packet); } - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNINpHandle), EventType.INFO, "Connection Id {0}, Packet returned, error occurred: {1}", args0: ConnectionId, args1: errorMessage); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.INFO, "Connection Id {0}, Packet returned, error occurred: {1}", args0: ConnectionId, args1: errorMessage); return SNICommon.ReportSNIError(SNIProviders.NP_PROV, nativeError, sniError, errorMessage); } From c182939e8b31c8df5fe52310ea10bf7ac9646d42 Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Tue, 13 May 2025 12:37:03 -0500 Subject: [PATCH 09/26] SNIPacket => SniPacket --- .../src/Microsoft.Data.SqlClient.csproj | 4 +- .../SqlClient/TdsParserStateObjectManaged.cs | 16 +++---- .../SqlClient/ManagedSni/SNICommon.netcore.cs | 2 +- .../ManagedSni/SNIPhysicalHandle.netcore.cs | 12 +++--- .../ManagedSni/SNITcpHandle.netcore.cs | 16 +++---- .../SqlClient/ManagedSni/SniHandle.netcore.cs | 12 +++--- .../ManagedSni/SniMarsConnection.netcore.cs | 22 +++++----- .../ManagedSni/SniMarsHandle.netcore.cs | 34 +++++++-------- .../ManagedSni/SniNpHandle.netcore.cs | 16 +++---- ...Packet.netcore.cs => SniPacket.netcore.cs} | 42 +++++++++---------- .../SqlClient/PacketHandle.netcore.Unix.cs | 6 +-- .../SqlClient/PacketHandle.netcore.Windows.cs | 6 +-- 12 files changed, 94 insertions(+), 94 deletions(-) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/{SNIPacket.netcore.cs => SniPacket.netcore.cs} (92%) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index 2de6d50ef2..96a949ca25 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -296,8 +296,8 @@ Microsoft\Data\SqlClient\ManagedSni\SniNpHandle.netcore.cs - - Microsoft\Data\SqlClient\ManagedSni\SNIPacket.netcore.cs + + Microsoft\Data\SqlClient\ManagedSni\SniPacket.netcore.cs Microsoft\Data\SqlClient\ManagedSni\SNIPhysicalHandle.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs index 90b30e71f1..8d6589682c 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs @@ -33,7 +33,7 @@ internal TdsParserStateObjectManaged(TdsParser parser, TdsParserStateObject phys protected override bool CheckPacket(PacketHandle packet, TaskCompletionSource source) { - SNIPacket p = packet.ManagedPacket; + SniPacket p = packet.ManagedPacket; return p.IsInvalid || source != null; } @@ -119,7 +119,7 @@ internal override void AssignPendingDNSInfo(string userProtocol, string DNSCache // No-op } - internal void ReadAsyncCallback(SNIPacket packet, uint error) + internal void ReadAsyncCallback(SniPacket packet, uint error) { SniHandle? sessionHandle = _sessionHandle; if (sessionHandle is not null) @@ -139,7 +139,7 @@ internal void ReadAsyncCallback(SNIPacket packet, uint error) } } - internal void WriteAsyncCallback(SNIPacket packet, uint sniError) + internal void WriteAsyncCallback(SniPacket packet, uint sniError) { SniHandle? sessionHandle = _sessionHandle; if (sessionHandle is not null) @@ -216,7 +216,7 @@ internal override PacketHandle ReadSyncOverAsync(int timeoutRemaining, out uint { SniHandle sessionHandle = GetSessionSNIHandleHandleOrThrow(); - error = sessionHandle.Receive(out SNIPacket packet, timeoutRemaining); + error = sessionHandle.Receive(out SniPacket packet, timeoutRemaining); SqlClientEventSource.Log.TryTraceEvent("TdsParserStateObjectManaged.ReadSyncOverAsync | Info | State Object Id {0}, Session Id {1}", _objectID, sessionHandle.ConnectionId); #if DEBUG @@ -233,7 +233,7 @@ internal override PacketHandle ReadSyncOverAsync(int timeoutRemaining, out uint internal override void ReleasePacket(PacketHandle syncReadPacket) { - SNIPacket packet = syncReadPacket.ManagedPacket; + SniPacket packet = syncReadPacket.ManagedPacket; SqlClientEventSource.Log.TryTraceEvent("TdsParserStateObjectManaged.ReleasePacket | Info | State Object Id {0}, Session Id {1}, Packet DataLeft {2}", _objectID, _sessionHandle?.ConnectionId, packet?.DataLeft); #if DEBUG SqlClientEventSource.Log.TryAdvancedTraceEvent("TdsParserStateObjectManaged.ReleasePacket | TRC | State Object Id {0}, Session Id {1}, Packet {2} will be released, Packet Owner Id {3}, Packet dataLeft {4}", _objectID, _sessionHandle?.ConnectionId, packet?._id, packet?._owner.ConnectionId, packet?.DataLeft); @@ -262,7 +262,7 @@ internal override uint CheckConnection() internal override PacketHandle ReadAsync(SessionHandle handle, out uint error) { - SNIPacket? packet = null; + SniPacket? packet = null; error = handle.ManagedHandle.ReceiveAsync(ref packet); SqlClientEventSource.Log.TryTraceEvent("TdsParserStateObjectManaged.ReadAsync | Info | State Object Id {0}, Session Id {1}, Packet DataLeft {2}", _objectID, _sessionHandle?.ConnectionId, packet?.DataLeft); @@ -286,7 +286,7 @@ internal override uint WritePacket(PacketHandle packetHandle, bool sync) { uint result = TdsEnums.SNI_UNINITIALIZED; SniHandle sessionHandle = GetSessionSNIHandleHandleOrThrow(); - SNIPacket? packet = packetHandle.ManagedPacket; + SniPacket? packet = packetHandle.ManagedPacket; if (sync) { @@ -318,7 +318,7 @@ internal override bool IsValidPacket(PacketHandle packet) internal override PacketHandle GetResetWritePacket(int dataSize) { SniHandle sessionHandle = GetSessionSNIHandleHandleOrThrow(); - SNIPacket packet = sessionHandle.RentPacket(headerSize: sessionHandle.ReserveHeaderSize, dataSize: dataSize); + SniPacket packet = sessionHandle.RentPacket(headerSize: sessionHandle.ReserveHeaderSize, dataSize: dataSize); #if DEBUG Debug.Assert(packet.IsActive, "packet is not active, a serious pooling error may have occurred"); #endif diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs index 12dfde458f..c9056e36e3 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs @@ -19,7 +19,7 @@ namespace Microsoft.Data.SqlClient.ManagedSni /// /// SNI packet /// SNI error code - internal delegate void SNIAsyncCallback(SNIPacket packet, uint sniErrorCode); + internal delegate void SNIAsyncCallback(SniPacket packet, uint sniErrorCode); /// /// SNI provider identifiers diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPhysicalHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPhysicalHandle.netcore.cs index 7ba9f38fdf..540062f366 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPhysicalHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPhysicalHandle.netcore.cs @@ -17,21 +17,21 @@ internal abstract class SNIPhysicalHandle : SniHandle #if DEBUG private static int s_packetId; #endif - private ObjectPool _pool; + private ObjectPool _pool; protected SNIPhysicalHandle(int poolSize = DefaultPoolSize) { - _pool = new ObjectPool(poolSize); + _pool = new ObjectPool(poolSize); } - public override SNIPacket RentPacket(int headerSize, int dataSize) + public override SniPacket RentPacket(int headerSize, int dataSize) { - SNIPacket packet; + SniPacket packet; if (!_pool.TryGet(out packet)) { #if DEBUG int id = Interlocked.Increment(ref s_packetId); - packet = new SNIPacket(this, id); + packet = new SniPacket(this, id); #else packet = new SNIPacket(); #endif @@ -57,7 +57,7 @@ public override SNIPacket RentPacket(int headerSize, int dataSize) return packet; } - public override void ReturnPacket(SNIPacket packet) + public override void ReturnPacket(SniPacket packet) { #if DEBUG Debug.Assert(packet != null, "releasing null SNIPacket"); diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNITcpHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNITcpHandle.netcore.cs index 6f758f3c68..235bbf0ca8 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNITcpHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNITcpHandle.netcore.cs @@ -752,7 +752,7 @@ public override void SetBufferSize(int bufferSize) /// /// SNI packet /// SNI error code - public override uint Send(SNIPacket packet) + public override uint Send(SniPacket packet) { bool releaseLock = false; try @@ -819,9 +819,9 @@ public override uint Send(SNIPacket packet) /// - If less than -1 or equal to 0, results in a timeout error. /// /// SNI error code indicating the result of the operation. - public override uint Receive(out SNIPacket packet, int timeoutInMilliseconds) + public override uint Receive(out SniPacket packet, int timeoutInMilliseconds) { - SNIPacket errorPacket; + SniPacket errorPacket; lock (this) { packet = null; @@ -918,7 +918,7 @@ public override void SetAsyncCallbacks(SNIAsyncCallback receiveCallback, SNIAsyn /// /// SNI packet /// SNI error code - public override uint SendAsync(SNIPacket packet) + public override uint SendAsync(SniPacket packet) { using (TrySNIEventScope.Create(nameof(SNITCPHandle))) { @@ -933,9 +933,9 @@ public override uint SendAsync(SNIPacket packet) /// /// SNI packet /// SNI error code - public override uint ReceiveAsync(ref SNIPacket packet) + public override uint ReceiveAsync(ref SniPacket packet) { - SNIPacket errorPacket; + SniPacket errorPacket; packet = RentPacket(headerSize: 0, dataSize: _bufferSize); packet.SetAsyncIOCompletionCallback(_receiveCallback); try @@ -1002,7 +1002,7 @@ private uint ReportTcpSNIError(uint nativeError, uint sniError, string errorMess return SNICommon.ReportSNIError(SNIProviders.TCP_PROV, nativeError, sniError, errorMessage); } - private uint ReportErrorAndReleasePacket(SNIPacket packet, Exception sniException) + private uint ReportErrorAndReleasePacket(SniPacket packet, Exception sniException) { if (packet != null) { @@ -1011,7 +1011,7 @@ private uint ReportErrorAndReleasePacket(SNIPacket packet, Exception sniExceptio return ReportTcpSNIError(sniException); } - private uint ReportErrorAndReleasePacket(SNIPacket packet, uint nativeError, uint sniError, string errorMessage) + private uint ReportErrorAndReleasePacket(SniPacket packet, uint nativeError, uint sniError, string errorMessage) { if (packet != null) { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniHandle.netcore.cs index b508d7265e..327c6649dd 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniHandle.netcore.cs @@ -60,14 +60,14 @@ protected static void AuthenticateAsClient(SslStream sslStream, string serverNam /// /// SNI packet /// SNI error code - public abstract uint Send(SNIPacket packet); + public abstract uint Send(SniPacket packet); /// /// Send a packet asynchronously /// /// SNI packet /// SNI error code - public abstract uint SendAsync(SNIPacket packet); + public abstract uint SendAsync(SniPacket packet); /// /// Receive a packet synchronously @@ -75,14 +75,14 @@ protected static void AuthenticateAsClient(SslStream sslStream, string serverNam /// SNI packet /// Timeout in Milliseconds /// SNI error code - public abstract uint Receive(out SNIPacket packet, int timeoutInMilliseconds); + public abstract uint Receive(out SniPacket packet, int timeoutInMilliseconds); /// /// Receive a packet asynchronously /// /// SNI packet /// SNI error code - public abstract uint ReceiveAsync(ref SNIPacket packet); + public abstract uint ReceiveAsync(ref SniPacket packet); /// /// Enable SSL @@ -112,9 +112,9 @@ protected static void AuthenticateAsClient(SslStream sslStream, string serverNam public virtual int ReserveHeaderSize => 0; - public abstract SNIPacket RentPacket(int headerSize, int dataSize); + public abstract SniPacket RentPacket(int headerSize, int dataSize); - public abstract void ReturnPacket(SNIPacket packet); + public abstract void ReturnPacket(SniPacket packet); /// /// Gets a value that indicates the security protocol used to authenticate this connection. diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsConnection.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsConnection.netcore.cs index 28651bf6a8..e037978521 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsConnection.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsConnection.netcore.cs @@ -23,7 +23,7 @@ internal class SniMarsConnection private ushort _nextSessionId; private int _currentHeaderByteCount; private int _dataBytesLeft; - private SNIPacket _currentPacket; + private SniPacket _currentPacket; /// /// Connection ID @@ -73,7 +73,7 @@ public uint StartReceive() { using (TrySNIEventScope.Create(nameof(SniMarsConnection))) { - SNIPacket packet = null; + SniPacket packet = null; if (ReceiveAsync(ref packet) == TdsEnums.SNI_SUCCESS_IO_PENDING) { @@ -90,7 +90,7 @@ public uint StartReceive() /// /// SNI packet /// SNI error code - public uint Send(SNIPacket packet) + public uint Send(SniPacket packet) { using (TrySNIEventScope.Create(nameof(SniMarsConnection))) { @@ -106,7 +106,7 @@ public uint Send(SNIPacket packet) /// /// SNI packet /// SNI error code - public uint SendAsync(SNIPacket packet) + public uint SendAsync(SniPacket packet) { using (TrySNIEventScope.Create(nameof(SniMarsConnection))) { @@ -122,7 +122,7 @@ public uint SendAsync(SNIPacket packet) /// /// SNI packet /// SNI error code - public uint ReceiveAsync(ref SNIPacket packet) + public uint ReceiveAsync(ref SniPacket packet) { using (TrySNIEventScope.Create(nameof(SniMarsConnection))) { @@ -164,7 +164,7 @@ public uint CheckConnection() /// /// Process a receive error /// - public void HandleReceiveError(SNIPacket packet) + public void HandleReceiveError(SniPacket packet) { Debug.Assert(Monitor.IsEntered(this), "HandleReceiveError was called without being locked."); foreach (SniMarsHandle handle in _sessions.Values) @@ -190,7 +190,7 @@ public void HandleReceiveError(SNIPacket packet) /// /// SNI packet /// SNI error code - public void HandleSendComplete(SNIPacket packet, uint sniErrorCode) + public void HandleSendComplete(SniPacket packet, uint sniErrorCode) { packet.InvokeAsyncIOCompletionCallback(sniErrorCode); } @@ -200,12 +200,12 @@ public void HandleSendComplete(SNIPacket packet, uint sniErrorCode) /// /// SNI packet /// SNI error code - public void HandleReceiveComplete(SNIPacket packet, uint sniErrorCode) + public void HandleReceiveComplete(SniPacket packet, uint sniErrorCode) { using (TrySNIEventScope.Create(nameof(SniMarsConnection))) { SNISMUXHeader currentHeader = null; - SNIPacket currentPacket = null; + SniPacket currentPacket = null; SniMarsHandle currentSession = null; if (sniErrorCode != TdsEnums.SNI_SUCCESS) @@ -377,12 +377,12 @@ public void DisableSsl() } } - public SNIPacket RentPacket(int headerSize, int dataSize) + public SniPacket RentPacket(int headerSize, int dataSize) { return _lowerHandle.RentPacket(headerSize, dataSize); } - public void ReturnPacket(SNIPacket packet) + public void ReturnPacket(SniPacket packet) { _lowerHandle.ReturnPacket(packet); } diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsHandle.netcore.cs index bac90ff489..9ad6d93284 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsHandle.netcore.cs @@ -18,8 +18,8 @@ internal sealed class SniMarsHandle : SniHandle private readonly SniMarsConnection _connection; private readonly uint _status = TdsEnums.SNI_UNINITIALIZED; - private readonly Queue _receivedPacketQueue = new Queue(); - private readonly Queue _sendPacketQueue = new Queue(); + private readonly Queue _receivedPacketQueue = new Queue(); + private readonly Queue _sendPacketQueue = new Queue(); private readonly object _callbackObject; private readonly Guid _connectionId; private readonly ushort _sessionId; @@ -96,7 +96,7 @@ private void SendControlPacket(SNISMUXFlags flags) { using (TrySNIEventScope.Create(nameof(SniMarsHandle))) { - SNIPacket packet = RentPacket(headerSize: SNISMUXHeader.HEADER_LENGTH, dataSize: 0); + SniPacket packet = RentPacket(headerSize: SNISMUXHeader.HEADER_LENGTH, dataSize: 0); #if DEBUG SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, Packet rented {1}, packet dataLeft {2}", args0: ConnectionId, args1: packet?._id, args2: packet?.DataLeft); #endif @@ -134,7 +134,7 @@ private void SetupSMUXHeader(int length, SNISMUXFlags flags) /// /// SNI packet /// The packet with the SMUx header set. - private SNIPacket SetPacketSMUXHeader(SNIPacket packet) + private SniPacket SetPacketSMUXHeader(SniPacket packet) { Debug.Assert(packet.ReservedHeaderSize == SNISMUXHeader.HEADER_LENGTH, "mars handle attempting to smux packet without smux reservation"); @@ -152,7 +152,7 @@ private SNIPacket SetPacketSMUXHeader(SNIPacket packet) /// /// SNI packet /// SNI error code - public override uint Send(SNIPacket packet) + public override uint Send(SniPacket packet) { Debug.Assert(packet.ReservedHeaderSize == SNISMUXHeader.HEADER_LENGTH, "mars handle attempting to send muxed packet without smux reservation in Send"); using (TrySNIEventScope.Create(nameof(SniMarsHandle))) @@ -177,7 +177,7 @@ public override uint Send(SNIPacket packet) } } - SNIPacket muxedPacket = null; + SniPacket muxedPacket = null; lock (this) { muxedPacket = SetPacketSMUXHeader(packet); @@ -192,7 +192,7 @@ public override uint Send(SNIPacket packet) /// /// SNI packet /// SNI error code - private uint InternalSendAsync(SNIPacket packet) + private uint InternalSendAsync(SniPacket packet) { Debug.Assert(packet.ReservedHeaderSize == SNISMUXHeader.HEADER_LENGTH, "mars handle attempting to send muxed packet without smux reservation in InternalSendAsync"); using (TrySNIEventScope.Create(nameof(SniMarsHandle))) @@ -205,7 +205,7 @@ private uint InternalSendAsync(SNIPacket packet) return TdsEnums.SNI_QUEUE_FULL; } - SNIPacket muxedPacket = SetPacketSMUXHeader(packet); + SniPacket muxedPacket = SetPacketSMUXHeader(packet); muxedPacket.SetAsyncIOCompletionCallback(_handleSendCompleteCallback); SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, Sending packet", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater); return _connection.SendAsync(muxedPacket); @@ -221,7 +221,7 @@ private uint SendPendingPackets() { using (TrySNIEventScope.Create(nameof(SniMarsHandle))) { - SNIPacket packet = null; + SniPacket packet = null; while (true) { @@ -264,7 +264,7 @@ private uint SendPendingPackets() /// /// SNI packet /// SNI error code - public override uint SendAsync(SNIPacket packet) + public override uint SendAsync(SniPacket packet) { using (TrySNIEventScope.Create(nameof(SniMarsHandle))) { @@ -286,7 +286,7 @@ public override uint SendAsync(SNIPacket packet) /// /// SNI packet /// SNI error code - public override uint ReceiveAsync(ref SNIPacket packet) + public override uint ReceiveAsync(ref SniPacket packet) { using (TrySNIEventScope.Create(nameof(SniMarsHandle))) { @@ -333,7 +333,7 @@ public override uint ReceiveAsync(ref SNIPacket packet) /// /// Handle receive error /// - public void HandleReceiveError(SNIPacket packet) + public void HandleReceiveError(SniPacket packet) { using (TrySNIEventScope.Create(nameof(SniMarsHandle))) { @@ -357,7 +357,7 @@ public void HandleReceiveError(SNIPacket packet) /// /// SNI packet /// SNI error code - public void HandleSendComplete(SNIPacket packet, uint sniErrorCode) + public void HandleSendComplete(SniPacket packet, uint sniErrorCode) { using (TrySNIEventScope.Create(nameof(SniMarsHandle))) { @@ -399,7 +399,7 @@ public void HandleAck(uint highwater) /// /// SNI packet /// SMUX header - public void HandleReceiveComplete(SNIPacket packet, SNISMUXHeader header) + public void HandleReceiveComplete(SniPacket packet, SNISMUXHeader header) { using (TrySNIEventScope.Create(nameof(SniMarsHandle))) { @@ -467,7 +467,7 @@ private void SendAckIfNecessary() /// SNI packet /// Timeout in Milliseconds /// SNI error code - public override uint Receive(out SNIPacket packet, int timeoutInMilliseconds) + public override uint Receive(out SniPacket packet, int timeoutInMilliseconds) { using (TrySNIEventScope.Create(nameof(SniMarsHandle))) { @@ -555,9 +555,9 @@ public override void SetBufferSize(int bufferSize) public override void DisableSsl() => _connection.DisableSsl(); - public override SNIPacket RentPacket(int headerSize, int dataSize) => _connection.RentPacket(headerSize, dataSize); + public override SniPacket RentPacket(int headerSize, int dataSize) => _connection.RentPacket(headerSize, dataSize); - public override void ReturnPacket(SNIPacket packet) => _connection.ReturnPacket(packet); + public override void ReturnPacket(SniPacket packet) => _connection.ReturnPacket(packet); #if DEBUG diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs index cd52bf9860..fa61f6693f 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs @@ -181,11 +181,11 @@ public override void Dispose() } } - public override uint Receive(out SNIPacket packet, int timeout) + public override uint Receive(out SniPacket packet, int timeout) { using (TrySNIEventScope.Create(nameof(SniNpHandle))) { - SNIPacket errorPacket; + SniPacket errorPacket; lock (this) { packet = null; @@ -223,11 +223,11 @@ public override uint Receive(out SNIPacket packet, int timeout) } } - public override uint ReceiveAsync(ref SNIPacket packet) + public override uint ReceiveAsync(ref SniPacket packet) { using (TrySNIEventScope.Create(nameof(SniNpHandle))) { - SNIPacket errorPacket; + SniPacket errorPacket; packet = RentPacket(headerSize: 0, dataSize: _bufferSize); packet.SetAsyncIOCompletionCallback(_receiveCallback); try @@ -253,7 +253,7 @@ public override uint ReceiveAsync(ref SNIPacket packet) } } - public override uint Send(SNIPacket packet) + public override uint Send(SniPacket packet) { using (TrySNIEventScope.Create(nameof(SniNpHandle))) { @@ -307,7 +307,7 @@ public override uint Send(SNIPacket packet) } } - public override uint SendAsync(SNIPacket packet) + public override uint SendAsync(SniPacket packet) { using (TrySNIEventScope.Create(nameof(SniNpHandle))) { @@ -401,7 +401,7 @@ public override void SetBufferSize(int bufferSize) _bufferSize = bufferSize; } - private uint ReportErrorAndReleasePacket(SNIPacket packet, Exception sniException) + private uint ReportErrorAndReleasePacket(SniPacket packet, Exception sniException) { if (packet != null) { @@ -411,7 +411,7 @@ private uint ReportErrorAndReleasePacket(SNIPacket packet, Exception sniExceptio return SNICommon.ReportSNIError(SNIProviders.NP_PROV, SNICommon.InternalExceptionError, sniException); } - private uint ReportErrorAndReleasePacket(SNIPacket packet, uint nativeError, uint sniError, string errorMessage) + private uint ReportErrorAndReleasePacket(SniPacket packet, uint nativeError, uint sniError, string errorMessage) { if (packet != null) { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPacket.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniPacket.netcore.cs similarity index 92% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPacket.netcore.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniPacket.netcore.cs index f0405f1a1a..83b126b14b 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPacket.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniPacket.netcore.cs @@ -16,7 +16,7 @@ namespace Microsoft.Data.SqlClient.ManagedSni /// /// SNI Packet /// - internal sealed class SNIPacket + internal sealed class SniPacket { private static readonly Action, object> s_readCallback = ReadFromStreamAsyncContinuation; private int _dataLength; // the length of the data in the data segment, advanced by Append-ing data, does not include smux header length @@ -59,7 +59,7 @@ public enum Direction /// public bool IsActive => _refCount == 1; - public SNIPacket(SniHandle owner, int id) + public SniPacket(SniHandle owner, int id) : this() { #if TRACE_HISTORY @@ -67,22 +67,22 @@ public SNIPacket(SniHandle owner, int id) #endif _id = id; _owner = owner; - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIPacket), EventType.INFO, "Connection Id {0}, Packet Id {1} instantiated,", args0: _owner?.ConnectionId, args1: _id); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniPacket), EventType.INFO, "Connection Id {0}, Packet Id {1} instantiated,", args0: _owner?.ConnectionId, args1: _id); } // the finalizer is only included in debug builds and is used to ensure that all packets are correctly recycled // it is not an error if a packet is dropped but it is undesirable so all efforts should be made to make sure we // do not drop them for the GC to pick up - ~SNIPacket() + ~SniPacket() { if (_data != null) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIPacket), EventType.ERR, "Finalizer called for unreleased SNIPacket, Connection Id {0}, Packet Id {1}, _refCount {2}, DataLeft {3}, tag {4}", args0: _owner?.ConnectionId, args1: _id, args2: _refCount, args3: DataLeft, args4: _traceTag); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniPacket), EventType.ERR, "Finalizer called for unreleased SNIPacket, Connection Id {0}, Packet Id {1}, _refCount {2}, DataLeft {3}, tag {4}", args0: _owner?.ConnectionId, args1: _id, args2: _refCount, args3: DataLeft, args4: _traceTag); } } #endif - public SNIPacket() + public SniPacket() { } @@ -135,7 +135,7 @@ public void Allocate(int headerLength, int dataLength) _dataOffset = 0; _headerLength = headerLength; #if DEBUG - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIPacket), EventType.INFO, "Connection Id {0}, Packet Id {1} allocated with _headerLength {2}, _dataCapacity {3}", args0: _owner?.ConnectionId, args1: _id, args2: _headerLength, args3: _dataCapacity); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniPacket), EventType.INFO, "Connection Id {0}, Packet Id {1} allocated with _headerLength {2}, _dataCapacity {3}", args0: _owner?.ConnectionId, args1: _id, args2: _headerLength, args3: _dataCapacity); #endif } @@ -156,12 +156,12 @@ public void GetData(byte[] buffer, ref int dataSize) /// Packet /// Data to take /// Amount of data taken - public int TakeData(SNIPacket packet, int size) + public int TakeData(SniPacket packet, int size) { int dataSize = TakeData(packet._data, packet._headerLength + packet._dataLength, size); packet._dataLength += dataSize; #if DEBUG - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIPacket), EventType.INFO, "Connection Id {0}, Packet Id {1} took data from Packet Id {2} dataSize {3}, _dataLength {4}", args0: _owner?.ConnectionId, args1: _id, args2: packet?._id, args3: dataSize, args4: packet._dataLength); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniPacket), EventType.INFO, "Connection Id {0}, Packet Id {1} took data from Packet Id {2} dataSize {3}, _dataLength {4}", args0: _owner?.ConnectionId, args1: _id, args2: packet?._id, args3: dataSize, args4: packet._dataLength); #endif return dataSize; } @@ -176,7 +176,7 @@ public void AppendData(byte[] data, int size) Buffer.BlockCopy(data, 0, _data, _headerLength + _dataLength, size); _dataLength += size; #if DEBUG - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIPacket), EventType.INFO, "Connection Id {0}, Packet Id {1} was appended with size {2}, _dataLength {3}", args0: _owner?.ConnectionId, args1: _id, args2: size, args3: _dataLength); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniPacket), EventType.INFO, "Connection Id {0}, Packet Id {1} was appended with size {2}, _dataLength {3}", args0: _owner?.ConnectionId, args1: _id, args2: size, args3: _dataLength); #endif } @@ -202,7 +202,7 @@ public int TakeData(byte[] buffer, int dataOffset, int size) Buffer.BlockCopy(_data, _headerLength + _dataOffset, buffer, dataOffset, size); _dataOffset += size; #if DEBUG - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIPacket), EventType.INFO, "Connection Id {0}, Packet Id {1} took data size {2}, _dataLength {3}, _dataOffset {4}", args0: _owner?.ConnectionId, args1: _id, args2: size, args3: _dataLength, args4: _dataOffset); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniPacket), EventType.INFO, "Connection Id {0}, Packet Id {1} took data size {2}, _dataLength {3}, _dataOffset {4}", args0: _owner?.ConnectionId, args1: _id, args2: size, args3: _dataLength, args4: _dataOffset); #endif return size; } @@ -222,7 +222,7 @@ public void SetHeaderActive() _dataLength += _headerLength; _headerLength = 0; #if DEBUG - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIPacket), EventType.INFO, "Connection Id {0}, Packet Id {1} _dataLength {2} header set to active.", args0: _owner?.ConnectionId, args1: _id, args2: _dataLength); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniPacket), EventType.INFO, "Connection Id {0}, Packet Id {1} _dataLength {2} header set to active.", args0: _owner?.ConnectionId, args1: _id, args2: _dataLength); #endif } @@ -240,7 +240,7 @@ public void Release() _dataCapacity = 0; } #if DEBUG - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIPacket), EventType.INFO, "Connection Id {0}, Packet Id {1} _headerLength {2} and _dataLength {3} released.", args0: _owner?.ConnectionId, args1: _id, args2: _headerLength, args3: _dataLength); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniPacket), EventType.INFO, "Connection Id {0}, Packet Id {1} _headerLength {2} and _dataLength {3} released.", args0: _owner?.ConnectionId, args1: _id, args2: _headerLength, args3: _dataLength); #endif _dataLength = 0; _dataOffset = 0; @@ -257,7 +257,7 @@ public void ReadFromStream(Stream stream) { _dataLength = stream.Read(_data, _headerLength, _dataCapacity); #if DEBUG - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIPacket), EventType.INFO, "Connection Id {0}, Packet Id {1} _dataLength {2} read from stream.", args0: _owner?.ConnectionId, args1: _id, args2: _dataLength); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniPacket), EventType.INFO, "Connection Id {0}, Packet Id {1} _dataLength {2} read from stream.", args0: _owner?.ConnectionId, args1: _id, args2: _dataLength); #endif } @@ -279,14 +279,14 @@ public void ReadFromStreamAsync(Stream stream) private static void ReadFromStreamAsyncContinuation(Task task, object state) { - SNIPacket packet = (SNIPacket)state; + SniPacket packet = (SniPacket)state; bool error = false; Exception e = task.Exception?.InnerException; if (e != null) { SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.TCP_PROV, SNICommon.InternalExceptionError, e); #if DEBUG - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIPacket), EventType.ERR, "Connection Id {0}, Internal Exception occurred while reading data: {1}", args0: packet._owner?.ConnectionId, args1: e?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniPacket), EventType.ERR, "Connection Id {0}, Internal Exception occurred while reading data: {1}", args0: packet._owner?.ConnectionId, args1: e?.Message); #endif error = true; } @@ -294,13 +294,13 @@ private static void ReadFromStreamAsyncContinuation(Task task, object state { packet._dataLength = task.Result; #if DEBUG - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIPacket), EventType.INFO, "Connection Id {0}, Packet Id {1} _dataLength {2} read from stream.", args0: packet._owner?.ConnectionId, args1: packet._id, args2: packet._dataLength); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniPacket), EventType.INFO, "Connection Id {0}, Packet Id {1} _dataLength {2} read from stream.", args0: packet._owner?.ConnectionId, args1: packet._id, args2: packet._dataLength); #endif if (packet._dataLength == 0) { SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.TCP_PROV, 0, SNICommon.ConnTerminatedError, Strings.SNI_ERROR_2); #if DEBUG - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIPacket), EventType.ERR, "Connection Id {0}, No data read from stream, connection was terminated.", args0: packet._owner?.ConnectionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniPacket), EventType.ERR, "Connection Id {0}, No data read from stream, connection was terminated.", args0: packet._owner?.ConnectionId); #endif error = true; } @@ -317,7 +317,7 @@ public void WriteToStream(Stream stream) { stream.Write(_data, _headerLength, _dataLength); #if DEBUG - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIPacket), EventType.INFO, "Connection Id {0}, Packet Id {1} _dataLength {2} written to stream.", args0: _owner?.ConnectionId, args1: _id, args2: _dataLength); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniPacket), EventType.INFO, "Connection Id {0}, Packet Id {1} _dataLength {2} written to stream.", args0: _owner?.ConnectionId, args1: _id, args2: _dataLength); #endif } @@ -334,14 +334,14 @@ public async void WriteToStreamAsync(Stream stream, SNIAsyncCallback callback, S { await stream.WriteAsync(_data, 0, _dataLength, CancellationToken.None).ConfigureAwait(false); #if DEBUG - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIPacket), EventType.INFO, "Connection Id {0}, Packet Id {1} _dataLength {2} written to stream.", args0: _owner?.ConnectionId, args1: _id, args2: _dataLength); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniPacket), EventType.INFO, "Connection Id {0}, Packet Id {1} _dataLength {2} written to stream.", args0: _owner?.ConnectionId, args1: _id, args2: _dataLength); #endif } catch (Exception e) { SniLoadHandle.SingletonInstance.LastError = new SniError(provider, SNICommon.InternalExceptionError, e); #if DEBUG - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIPacket), EventType.ERR, "Connection Id {0}, Internal Exception occurred while writing data: {1}", args0: _owner?.ConnectionId, args1: e?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniPacket), EventType.ERR, "Connection Id {0}, Internal Exception occurred while writing data: {1}", args0: _owner?.ConnectionId, args1: e?.Message); #endif status = TdsEnums.SNI_ERROR; } diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PacketHandle.netcore.Unix.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PacketHandle.netcore.Unix.cs index 8e3089a919..fd985a2c12 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PacketHandle.netcore.Unix.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PacketHandle.netcore.Unix.cs @@ -22,16 +22,16 @@ internal readonly ref struct PacketHandle public const int NativePacketType = 2; public const int ManagedPacketType = 3; - public readonly ManagedSni.SNIPacket ManagedPacket; + public readonly ManagedSni.SniPacket ManagedPacket; public readonly int Type; - private PacketHandle(ManagedSni.SNIPacket managedPacket, int type) + private PacketHandle(ManagedSni.SniPacket managedPacket, int type) { Type = type; ManagedPacket = managedPacket; } - public static PacketHandle FromManagedPacket(ManagedSni.SNIPacket managedPacket) => + public static PacketHandle FromManagedPacket(ManagedSni.SniPacket managedPacket) => new PacketHandle(managedPacket, ManagedPacketType); } } diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PacketHandle.netcore.Windows.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PacketHandle.netcore.Windows.cs index 9575db5d63..45bdf0b75b 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PacketHandle.netcore.Windows.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PacketHandle.netcore.Windows.cs @@ -24,12 +24,12 @@ internal readonly ref struct PacketHandle public const int NativePacketType = 2; public const int ManagedPacketType = 3; - public readonly ManagedSni.SNIPacket ManagedPacket; + public readonly ManagedSni.SniPacket ManagedPacket; public readonly SNIPacket NativePacket; public readonly IntPtr NativePointer; public readonly int Type; - private PacketHandle(IntPtr nativePointer, SNIPacket nativePacket, ManagedSni.SNIPacket managedPacket, int type) + private PacketHandle(IntPtr nativePointer, SNIPacket nativePacket, ManagedSni.SniPacket managedPacket, int type) { Type = type; ManagedPacket = managedPacket; @@ -37,7 +37,7 @@ private PacketHandle(IntPtr nativePointer, SNIPacket nativePacket, ManagedSni.SN NativePacket = nativePacket; } - public static PacketHandle FromManagedPacket(ManagedSni.SNIPacket managedPacket) => + public static PacketHandle FromManagedPacket(ManagedSni.SniPacket managedPacket) => new PacketHandle(default, default, managedPacket, ManagedPacketType); public static PacketHandle FromNativePointer(IntPtr nativePointer) => From af092681363dd1a922c10aa357d832cb118dd656 Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Tue, 13 May 2025 12:40:41 -0500 Subject: [PATCH 10/26] SNIPhysicalHandle => SniPhysicalHandle --- .../netcore/src/Microsoft.Data.SqlClient.csproj | 4 ++-- .../Data/SqlClient/ManagedSni/SNITcpHandle.netcore.cs | 2 +- .../Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs | 2 +- ...PhysicalHandle.netcore.cs => SniPhysicalHandle.netcore.cs} | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/{SNIPhysicalHandle.netcore.cs => SniPhysicalHandle.netcore.cs} (96%) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index 96a949ca25..cbf2b79153 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -299,8 +299,8 @@ Microsoft\Data\SqlClient\ManagedSni\SniPacket.netcore.cs - - Microsoft\Data\SqlClient\ManagedSni\SNIPhysicalHandle.netcore.cs + + Microsoft\Data\SqlClient\ManagedSni\SniPhysicalHandle.netcore.cs Microsoft\Data\SqlClient\ManagedSni\SNIProxy.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNITcpHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNITcpHandle.netcore.cs index 235bbf0ca8..572ff2098c 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNITcpHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNITcpHandle.netcore.cs @@ -20,7 +20,7 @@ namespace Microsoft.Data.SqlClient.ManagedSni /// /// TCP connection handle /// - internal sealed class SNITCPHandle : SNIPhysicalHandle + internal sealed class SNITCPHandle : SniPhysicalHandle { private readonly string _targetServer; private readonly object _sendSync; diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs index fa61f6693f..ca456675c1 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs @@ -17,7 +17,7 @@ namespace Microsoft.Data.SqlClient.ManagedSni /// /// Named Pipe connection handle /// - internal sealed class SniNpHandle : SNIPhysicalHandle + internal sealed class SniNpHandle : SniPhysicalHandle { internal const string DefaultPipePath = @"sql\query"; // e.g. \\HOSTNAME\pipe\sql\query // private const int MAX_PIPE_INSTANCES = 255; // TODO: Investigate pipe instance limit. diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPhysicalHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniPhysicalHandle.netcore.cs similarity index 96% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPhysicalHandle.netcore.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniPhysicalHandle.netcore.cs index 540062f366..1334b07292 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIPhysicalHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniPhysicalHandle.netcore.cs @@ -10,7 +10,7 @@ namespace Microsoft.Data.SqlClient.ManagedSni { - internal abstract class SNIPhysicalHandle : SniHandle + internal abstract class SniPhysicalHandle : SniHandle { protected const int DefaultPoolSize = 4; @@ -19,7 +19,7 @@ internal abstract class SNIPhysicalHandle : SniHandle #endif private ObjectPool _pool; - protected SNIPhysicalHandle(int poolSize = DefaultPoolSize) + protected SniPhysicalHandle(int poolSize = DefaultPoolSize) { _pool = new ObjectPool(poolSize); } From 8689b48f40a73cb40d88ead3e6703acf551e85b5 Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Tue, 13 May 2025 12:46:29 -0500 Subject: [PATCH 11/26] SNIProxy => SniProxy --- .../netcore/src/Microsoft.Data.SqlClient.csproj | 4 ++-- .../src/Microsoft/Data/SqlClient/TdsParser.Unix.cs | 2 +- .../src/Microsoft/Data/SqlClient/TdsParser.Windows.cs | 2 +- .../Data/SqlClient/TdsParserStateObjectManaged.cs | 2 +- .../{SNIProxy.netcore.cs => SniProxy.netcore.cs} | 8 ++++---- 5 files changed, 9 insertions(+), 9 deletions(-) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/{SNIProxy.netcore.cs => SniProxy.netcore.cs} (99%) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index cbf2b79153..7e25898f2f 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -302,8 +302,8 @@ Microsoft\Data\SqlClient\ManagedSni\SniPhysicalHandle.netcore.cs - - Microsoft\Data\SqlClient\ManagedSni\SNIProxy.netcore.cs + + Microsoft\Data\SqlClient\ManagedSni\SniProxy.netcore.cs Microsoft\Data\SqlClient\ManagedSni\SNIStream.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Unix.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Unix.cs index fbb341cef2..d71332a25a 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Unix.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Unix.cs @@ -26,7 +26,7 @@ private void WaitForSSLHandShakeToComplete(ref uint error, ref int protocolVersi private SNIErrorDetails GetSniErrorDetails() { SNIErrorDetails details; - SniError sniError = SNIProxy.Instance.GetLastError(); + SniError sniError = SniProxy.Instance.GetLastError(); details.sniErrorNumber = sniError.sniError; details.errorMessage = sniError.errorMessage; details.nativeError = sniError.nativeError; diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Windows.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Windows.cs index 12f793cff1..25bc6f87c5 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Windows.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.Windows.cs @@ -69,7 +69,7 @@ private SNIErrorDetails GetSniErrorDetails() if (TdsParserStateObjectFactory.UseManagedSNI) { - SniError sniError = SNIProxy.Instance.GetLastError(); + SniError sniError = SniProxy.Instance.GetLastError(); details.sniErrorNumber = sniError.sniError; details.errorMessage = sniError.errorMessage; details.nativeError = sniError.nativeError; diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs index 8d6589682c..83a87b719e 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs @@ -93,7 +93,7 @@ internal override void CreatePhysicalSNIHandle( string hostNameInCertificate, string serverCertificateFilename) { - SniHandle? sessionHandle = SNIProxy.CreateConnectionHandle(serverName, timeout, out instanceName, ref spns, serverSPN, + SniHandle? sessionHandle = SniProxy.CreateConnectionHandle(serverName, timeout, out instanceName, ref spns, serverSPN, flushCache, async, parallel, isIntegratedSecurity, iPAddressPreference, cachedFQDN, ref pendingDNSInfo, tlsFirst, hostNameInCertificate, serverCertificateFilename); diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIProxy.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniProxy.netcore.cs similarity index 99% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIProxy.netcore.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniProxy.netcore.cs index 754f0fd596..182043d91f 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIProxy.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniProxy.netcore.cs @@ -15,15 +15,15 @@ namespace Microsoft.Data.SqlClient.ManagedSni /// /// Managed SNI proxy implementation. Contains many SNI entry points used by SqlClient. /// - internal class SNIProxy + internal class SniProxy { private const int DefaultSqlServerPort = 1433; private const int DefaultSqlServerDacPort = 1434; private const string SqlServerSpnHeader = "MSSQLSvc"; - private static readonly SNIProxy s_singleton = new SNIProxy(); + private static readonly SniProxy s_singleton = new SniProxy(); - internal static SNIProxy Instance => s_singleton; + internal static SniProxy Instance => s_singleton; /// /// Create a SNI connection handle @@ -440,7 +440,7 @@ internal static string GetLocalDBInstance(string dataSource, out bool error) else if (index > 0) { SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, SNICommon.ErrorLocatingServerInstance, Strings.SNI_ERROR_26); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNIProxy), EventType.ERR, "Incompatible use of prefix with LocalDb: '{0}'", dataSource); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniProxy), EventType.ERR, "Incompatible use of prefix with LocalDb: '{0}'", dataSource); error = true; } else if (index == 0) From 3665a8191fd24497bcea1b1cd3c48e32ee0a4bf5 Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Tue, 13 May 2025 12:51:24 -0500 Subject: [PATCH 12/26] SNITcpHandle => SniTcpHandle --- .../src/Microsoft.Data.SqlClient.csproj | 4 +- .../SqlClient/ManagedSni/SNICommon.netcore.cs | 2 +- .../SqlClient/ManagedSni/SniProxy.netcore.cs | 4 +- ...dle.netcore.cs => SniTcpHandle.netcore.cs} | 114 +++++++++--------- 4 files changed, 62 insertions(+), 62 deletions(-) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/{SNITcpHandle.netcore.cs => SniTcpHandle.netcore.cs} (93%) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index 7e25898f2f..3752e1c823 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -311,8 +311,8 @@ Microsoft\Data\SqlClient\ManagedSni\SNIStreams.ValueTask.netcore.cs - - Microsoft\Data\SqlClient\ManagedSni\SNITcpHandle.netcore.cs + + Microsoft\Data\SqlClient\ManagedSni\SniTcpHandle.netcore.cs Microsoft\Data\SqlClient\ManagedSni\SslOverTdsStream.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs index c9056e36e3..c7151eceef 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs @@ -181,7 +181,7 @@ internal static bool ValidateSslServerCertificate(Guid connectionId, string targ catch (Exception e) { // if this fails, then fall back to the HostNameInCertificate or TargetServer validation. - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.INFO, "Connection Id {0}, Exception occurred loading specified ServerCertificate: {1}, treating it as if ServerCertificate has not been specified.", args0: connectionId, args1: e.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.INFO, "Connection Id {0}, Exception occurred loading specified ServerCertificate: {1}, treating it as if ServerCertificate has not been specified.", args0: connectionId, args1: e.Message); } } diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniProxy.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniProxy.netcore.cs index 182043d91f..1d15cba8bb 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniProxy.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniProxy.netcore.cs @@ -187,7 +187,7 @@ private static string[] GetSqlServerSPNs(string hostNameOrAddress, string portOr /// Host name in certificate /// Used for the path to the Server Certificate /// SNITCPHandle - private static SNITCPHandle CreateTcpHandle( + private static SniTcpHandle CreateTcpHandle( DataSource details, TimeoutTimer timeout, bool parallel, @@ -234,7 +234,7 @@ private static SNITCPHandle CreateTcpHandle( port = isAdminConnection ? DefaultSqlServerDacPort : DefaultSqlServerPort; } - return new SNITCPHandle(hostName, port, timeout, parallel, ipPreference, cachedFQDN, ref pendingDNSInfo, + return new SniTcpHandle(hostName, port, timeout, parallel, ipPreference, cachedFQDN, ref pendingDNSInfo, tlsFirst, hostNameInCertificate, serverCertificateFilename); } diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNITcpHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniTcpHandle.netcore.cs similarity index 93% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNITcpHandle.netcore.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniTcpHandle.netcore.cs index 572ff2098c..edd758cef4 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNITcpHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniTcpHandle.netcore.cs @@ -20,7 +20,7 @@ namespace Microsoft.Data.SqlClient.ManagedSni /// /// TCP connection handle /// - internal sealed class SNITCPHandle : SniPhysicalHandle + internal sealed class SniTcpHandle : SniPhysicalHandle { private readonly string _targetServer; private readonly object _sendSync; @@ -70,7 +70,7 @@ public override void Dispose() //Release any references held by _stream. _stream = null; - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.INFO, "Connection Id {0}, All streams disposed.", args0: _connectionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.INFO, "Connection Id {0}, All streams disposed.", args0: _connectionId); } } @@ -124,7 +124,7 @@ public override int ProtocolVersion /// Support TDS8.0 /// Host Name in Certificate /// Used for the path to the Server Certificate - public SNITCPHandle( + public SniTcpHandle( string serverName, int port, TimeoutTimer timeout, @@ -136,9 +136,9 @@ public SNITCPHandle( string hostNameInCertificate, string serverCertificateFilename) { - using (TrySNIEventScope.Create(nameof(SNITCPHandle))) + using (TrySNIEventScope.Create(nameof(SniTcpHandle))) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.INFO, "Connection Id {0}, Setting server name = {1}", args0: _connectionId, args1: serverName); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.INFO, "Connection Id {0}, Setting server name = {1}", args0: _connectionId, args1: serverName); _targetServer = serverName; _tlsFirst = tlsFirst; @@ -153,7 +153,7 @@ public SNITCPHandle( { bool reportError = true; - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.INFO, "Connection Id {0}, Connecting to serverName {1} and port {2}", args0: _connectionId, args1: serverName, args2: port); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.INFO, "Connection Id {0}, Connecting to serverName {1} and port {2}", args0: _connectionId, args1: serverName, args2: port); // We will always first try to connect with serverName as before and let DNS resolve the serverName. // If DNS resolution fails, we will try with IPs in the DNS cache if they exist. We try with cached IPs based on IPAddressPreference. // Exceptions will be thrown to the caller and be handled as before. @@ -179,13 +179,13 @@ public SNITCPHandle( { if (hasCachedDNSInfo == false) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.ERR, "Connection Id {0}, Cached DNS Info not found, exception occurred thrown: {1}", args0: _connectionId, args1: ex?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.ERR, "Connection Id {0}, Cached DNS Info not found, exception occurred thrown: {1}", args0: _connectionId, args1: ex?.Message); throw; } else { int portRetry = string.IsNullOrEmpty(cachedDNSInfo.Port) ? port : int.Parse(cachedDNSInfo.Port); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.INFO, "Connection Id {0}, Retrying with cached DNS IP Address {1} and port {2}", args0: _connectionId, args1: cachedDNSInfo.AddrIPv4, args2: cachedDNSInfo.Port); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.INFO, "Connection Id {0}, Retrying with cached DNS IP Address {1} and port {2}", args0: _connectionId, args1: cachedDNSInfo.AddrIPv4, args2: cachedDNSInfo.Port); string firstCachedIP; string secondCachedIP; @@ -221,7 +221,7 @@ public SNITCPHandle( if (exRetry is SocketException || exRetry is ArgumentNullException || exRetry is ArgumentException || exRetry is ArgumentOutOfRangeException || exRetry is AggregateException) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.INFO, "Connection Id {0}, Retrying exception {1}", args0: _connectionId, args1: exRetry?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.INFO, "Connection Id {0}, Retrying exception {1}", args0: _connectionId, args1: exRetry?.Message); if (parallel) { _socket = TryConnectParallel(secondCachedIP, portRetry, timeout, ref reportError, cachedFQDN, ref pendingDNSInfo); @@ -233,7 +233,7 @@ public SNITCPHandle( } else { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.ERR, "Connection Id {0}, Retry failed, exception occurred: {1}", args0: _connectionId, args1: exRetry?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.ERR, "Connection Id {0}, Retry failed, exception occurred: {1}", args0: _connectionId, args1: exRetry?.Message); throw; } } @@ -255,10 +255,10 @@ public SNITCPHandle( if (reportError) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.ERR, "Connection Id {0} could not be opened, exception occurred: {1}", args0: _connectionId, args1: Strings.SNI_ERROR_40); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.ERR, "Connection Id {0} could not be opened, exception occurred: {1}", args0: _connectionId, args1: Strings.SNI_ERROR_40); ReportTcpSNIError(0, SNICommon.ConnOpenFailedError, Strings.SNI_ERROR_40); } - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.ERR, "Connection Id {0} Socket could not be opened.", args0: _connectionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.ERR, "Connection Id {0} Socket could not be opened.", args0: _connectionId); return; } @@ -275,20 +275,20 @@ public SNITCPHandle( } catch (SocketException se) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.ERR, "Connection Id {0} Socket exception occurred: Error Code {1}, Message {2}", args0: _connectionId, args1: se?.SocketErrorCode, args2: se?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.ERR, "Connection Id {0} Socket exception occurred: Error Code {1}, Message {2}", args0: _connectionId, args1: se?.SocketErrorCode, args2: se?.Message); ReportTcpSNIError(se); return; } catch (Exception e) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.ERR, "Connection Id {0} Exception occurred: {1}", args0: _connectionId, args1: e?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.ERR, "Connection Id {0} Exception occurred: {1}", args0: _connectionId, args1: e?.Message); ReportTcpSNIError(e); return; } _stream = _tcpStream; _status = TdsEnums.SNI_SUCCESS; - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.INFO, "Connection Id {0} Socket opened successfully, TCP stream ready.", args0: _connectionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.INFO, "Connection Id {0} Socket opened successfully, TCP stream ready.", args0: _connectionId); } } @@ -297,7 +297,7 @@ public SNITCPHandle( // Only write to the DNS cache when we receive IsSupported flag as true in the Feature Ext Ack from server. private Socket TryConnectParallel(string hostName, int port, TimeoutTimer timeout, ref bool callerReportError, string cachedFQDN, ref SQLDNSInfo pendingDNSInfo) { - using (TrySNIEventScope.Create(nameof(SNITCPHandle))) + using (TrySNIEventScope.Create(nameof(SniTcpHandle))) { Socket availableSocket = null; bool isInfiniteTimeOut = timeout.IsInfinite; @@ -310,7 +310,7 @@ private Socket TryConnectParallel(string hostName, int port, TimeoutTimer timeou { // Fail if above 64 to match legacy behavior callerReportError = false; - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.ERR, "Connection Id {0} serverAddresses.Length {1} Exception: {2}", args0: _connectionId, args1: serverAddresses.Length, args2: Strings.SNI_ERROR_47); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.ERR, "Connection Id {0} serverAddresses.Length {1} Exception: {2}", args0: _connectionId, args1: serverAddresses.Length, args2: Strings.SNI_ERROR_47); ReportTcpSNIError(0, SNICommon.MultiSubnetFailoverWithMoreThan64IPs, Strings.SNI_ERROR_47); return availableSocket; } @@ -366,9 +366,9 @@ private static IEnumerable GetHostAddressesSortedByPreference(string // Only write to the DNS cache when we receive IsSupported flag as true in the Feature Ext Ack from server. private static Socket Connect(string serverName, int port, TimeoutTimer timeout, SqlConnectionIPAddressPreference ipPreference, string cachedFQDN, ref SQLDNSInfo pendingDNSInfo) { - using (TrySNIEventScope.Create(nameof(SNITCPHandle))) + using (TrySNIEventScope.Create(nameof(SniTcpHandle))) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.INFO, "IP preference : {0}", Enum.GetName(typeof(SqlConnectionIPAddressPreference), ipPreference)); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.INFO, "IP preference : {0}", Enum.GetName(typeof(SqlConnectionIPAddressPreference), ipPreference)); bool isInfiniteTimeout = timeout.IsInfinite; IEnumerable ipAddresses = GetHostAddressesSortedByPreference(serverName, ipPreference); @@ -388,7 +388,7 @@ private static Socket Connect(string serverName, int port, TimeoutTimer timeout, // enable keep-alive on socket SetKeepAliveValues(ref socket); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.INFO, + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.INFO, "Connecting to IP address {0} and port {1} using {2} address family. Is infinite timeout: {3}", ipAddress, port, @@ -434,7 +434,7 @@ private static Socket Connect(string serverName, int port, TimeoutTimer timeout, checkWriteLst = new List(1) { socket }; checkErrorLst = new List(1) { socket }; - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.INFO, + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.INFO, "Determining the status of the socket during the remaining timeout of {0} microseconds.", socketSelectTimeout); @@ -468,7 +468,7 @@ private static Socket Connect(string serverName, int port, TimeoutTimer timeout, { SqlClientEventSource.Log.TryAdvancedTraceEvent( "{0}.{1}{2}THIS EXCEPTION IS BEING SWALLOWED: {3}", - nameof(SNITCPHandle), nameof(Connect), EventType.ERR, e); + nameof(SniTcpHandle), nameof(Connect), EventType.ERR, e); } finally { @@ -483,7 +483,7 @@ private static Socket Connect(string serverName, int port, TimeoutTimer timeout, private static Socket ParallelConnect(IPAddress[] serverAddresses, int port, TimeoutTimer timeout, string cachedFQDN, ref SQLDNSInfo pendingDNSInfo) { - using (TrySNIEventScope.Create(nameof(SNITCPHandle))) + using (TrySNIEventScope.Create(nameof(SniTcpHandle))) { if (serverAddresses == null) { @@ -508,7 +508,7 @@ private static Socket ParallelConnect(IPAddress[] serverAddresses, int port, Tim // enable keep-alive on socket SetKeepAliveValues(ref socket); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.INFO, + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.INFO, "Connecting to IP address {0} and port {1} using {2} address family. Is infinite timeout: {3}", address, port, @@ -564,7 +564,7 @@ private static Socket ParallelConnect(IPAddress[] serverAddresses, int port, Tim checkErrorLst.Clear(); checkErrorLst.AddRange(socketsInFlight); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.INFO, + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.INFO, "Watching pending sockets during the remaining timeout of {0} microseconds.", socketSelectTimeout); @@ -578,14 +578,14 @@ private static Socket ParallelConnect(IPAddress[] serverAddresses, int port, Tim // Socket.Select can throw if one of the sockets has issues. That socket will be in checkErrorLst. // Log the error and let that socket be removed from socketsInFlight below. SqlClientEventSource.Log.TryAdvancedTraceEvent( - "{0}.{1}{2}THIS EXCEPTION IS BEING SWALLOWED: {3}", nameof(SNITCPHandle), nameof(ParallelConnect), EventType.ERR, e); + "{0}.{1}{2}THIS EXCEPTION IS BEING SWALLOWED: {3}", nameof(SniTcpHandle), nameof(ParallelConnect), EventType.ERR, e); lastError = e; } if (timeout.IsExpired) { SqlClientEventSource.Log.TryAdvancedTraceEvent( - "{0}.{1}{2}ParallelConnect timeout expired.", nameof(SNITCPHandle), nameof(ParallelConnect), EventType.INFO); + "{0}.{1}{2}ParallelConnect timeout expired.", nameof(SniTcpHandle), nameof(ParallelConnect), EventType.INFO); break; } @@ -596,7 +596,7 @@ private static Socket ParallelConnect(IPAddress[] serverAddresses, int port, Tim if (!checkErrorLst.Contains(s) && s.Connected) { connectedSocket = s; - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.INFO, + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.INFO, "Connected to endpoint: {0}", connectedSocket.RemoteEndPoint); connectedSocket.Blocking = true; string iPv4String = null; @@ -622,7 +622,7 @@ private static Socket ParallelConnect(IPAddress[] serverAddresses, int port, Tim foreach (Socket socket in checkErrorLst) { SqlClientEventSource.Log.TryAdvancedTraceEvent( - "{0}.{1}{2}Failed to connect to endpoint: {3}. Error: {4}", nameof(SNITCPHandle), + "{0}.{1}{2}Failed to connect to endpoint: {3}. Error: {4}", nameof(SniTcpHandle), nameof(ParallelConnect), EventType.INFO, sockets[socket], lastError); socketsInFlight.Remove(socket); } @@ -631,7 +631,7 @@ private static Socket ParallelConnect(IPAddress[] serverAddresses, int port, Tim foreach (Socket socket in checkWriteLst) { SqlClientEventSource.Log.TryAdvancedTraceEvent( - "{0}.{1}{2}Failed to connect to endpoint: {3}. Error: {4}", nameof(SNITCPHandle), + "{0}.{1}{2}Failed to connect to endpoint: {3}. Error: {4}", nameof(SniTcpHandle), nameof(ParallelConnect), EventType.INFO, sockets[socket], lastError); socketsInFlight.Remove(socket); } @@ -644,7 +644,7 @@ private static Socket ParallelConnect(IPAddress[] serverAddresses, int port, Tim if (socket != connectedSocket) { SqlClientEventSource.Log.TryAdvancedTraceEvent( - "{0}.{1}{2}Disposing non-selected socket for endpoint: {3}", nameof(SNITCPHandle), + "{0}.{1}{2}Disposing non-selected socket for endpoint: {3}", nameof(SniTcpHandle), nameof(ParallelConnect), EventType.INFO, sockets[socket]); socket?.Dispose(); } @@ -654,7 +654,7 @@ private static Socket ParallelConnect(IPAddress[] serverAddresses, int port, Tim { SqlClientEventSource.Log.TryAdvancedTraceEvent( "{0}.{1}{2}No socket connections succeeded. Last error: {3}", - nameof(SNITCPHandle), nameof(ParallelConnect), EventType.ERR, lastError); + nameof(SniTcpHandle), nameof(ParallelConnect), EventType.ERR, lastError); } return connectedSocket; @@ -687,17 +687,17 @@ public override uint EnableSsl(uint options) } catch (AuthenticationException aue) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.ERR, "Connection Id {0}, Authentication exception occurred: {1}", args0: _connectionId, args1: aue?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.ERR, "Connection Id {0}, Authentication exception occurred: {1}", args0: _connectionId, args1: aue?.Message); return ReportTcpSNIError(aue, SniError.CertificateValidationErrorCode); } catch (InvalidOperationException ioe) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.ERR, "Connection Id {0}, Invalid Operation Exception occurred: {1}", args0: _connectionId, args1: ioe?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.ERR, "Connection Id {0}, Invalid Operation Exception occurred: {1}", args0: _connectionId, args1: ioe?.Message); return ReportTcpSNIError(ioe); } _stream = _sslStream; - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.INFO, "Connection Id {0}, SSL enabled successfully.", args0: _connectionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.INFO, "Connection Id {0}, SSL enabled successfully.", args0: _connectionId); return TdsEnums.SNI_SUCCESS; } } @@ -707,14 +707,14 @@ public override uint EnableSsl(uint options) /// public override void DisableSsl() { - using (TrySNIEventScope.Create(nameof(SNITCPHandle))) + using (TrySNIEventScope.Create(nameof(SniTcpHandle))) { _sslStream.Dispose(); _sslStream = null; _sslOverTdsStream?.Dispose(); _sslOverTdsStream = null; _stream = _tcpStream; - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.INFO, "Connection Id {0}, SSL Disabled. Communication will continue on TCP Stream.", args0: _connectionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.INFO, "Connection Id {0}, SSL Disabled. Communication will continue on TCP Stream.", args0: _connectionId); } } @@ -730,11 +730,11 @@ private bool ValidateServerCertificate(object sender, X509Certificate serverCert { if (!_validateCert) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.INFO, "Connection Id {0}, Certificate will not be validated.", args0: _connectionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.INFO, "Connection Id {0}, Certificate will not be validated.", args0: _connectionId); return true; } - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.INFO, "Connection Id {0}, Certificate will be validated for Target Server name", args0: _connectionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.INFO, "Connection Id {0}, Certificate will be validated for Target Server name", args0: _connectionId); return SNICommon.ValidateSslServerCertificate(_connectionId, _targetServer, _hostNameInCertificate, serverCertificate, _serverCertificateFilename, policyErrors); } @@ -779,22 +779,22 @@ public override uint Send(SniPacket packet) try { packet.WriteToStream(_stream); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.INFO, "Connection Id {0}, Data sent to stream synchronously", args0: _connectionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.INFO, "Connection Id {0}, Data sent to stream synchronously", args0: _connectionId); return TdsEnums.SNI_SUCCESS; } catch (ObjectDisposedException ode) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.ERR, "Connection Id {0}, ObjectDisposedException occurred: {1}", args0: _connectionId, args1: ode?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.ERR, "Connection Id {0}, ObjectDisposedException occurred: {1}", args0: _connectionId, args1: ode?.Message); return ReportTcpSNIError(ode); } catch (SocketException se) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.ERR, "Connection Id {0}, SocketException occurred: {1}", args0: _connectionId, args1: se?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.ERR, "Connection Id {0}, SocketException occurred: {1}", args0: _connectionId, args1: se?.Message); return ReportTcpSNIError(se); } catch (IOException ioe) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.ERR, "Connection Id {0}, IOException occurred: {1}", args0: _connectionId, args1: ioe?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.ERR, "Connection Id {0}, IOException occurred: {1}", args0: _connectionId, args1: ioe?.Message); return ReportTcpSNIError(ioe); } } @@ -828,7 +828,7 @@ public override uint Receive(out SniPacket packet, int timeoutInMilliseconds) if (_socket == null) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.ERR, "Connection Id {0}, Socket is null.", args0: _connectionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.ERR, "Connection Id {0}, Socket is null.", args0: _connectionId); return ReportTcpSNIError(0, SNICommon.ConnOpenFailedError, Strings.SNI_ERROR_10); } @@ -845,7 +845,7 @@ public override uint Receive(out SniPacket packet, int timeoutInMilliseconds) else { // otherwise it is timeout for 0 or less than -1 - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.ERR, "Connection Id {0}, Error 258, Timeout error occurred.", args0: _connectionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.ERR, "Connection Id {0}, Error 258, Timeout error occurred.", args0: _connectionId); ReportTcpSNIError(0, SNICommon.ConnTimeoutError, Strings.SNI_ERROR_11); return TdsEnums.SNI_WAIT_TIMEOUT; } @@ -858,25 +858,25 @@ public override uint Receive(out SniPacket packet, int timeoutInMilliseconds) errorPacket = packet; packet = null; var e = new Win32Exception(); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.ERR, "Connection Id {0}, Win32 exception occurred: {1}", args0: _connectionId, args1: e?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.ERR, "Connection Id {0}, Win32 exception occurred: {1}", args0: _connectionId, args1: e?.Message); return ReportErrorAndReleasePacket(errorPacket, (uint)e.NativeErrorCode, 0, e.Message); } - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.INFO, "Connection Id {0}, Data read from stream synchronously", args0: _connectionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.INFO, "Connection Id {0}, Data read from stream synchronously", args0: _connectionId); return TdsEnums.SNI_SUCCESS; } catch (ObjectDisposedException ode) { errorPacket = packet; packet = null; - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.ERR, "Connection Id {0}, ObjectDisposedException occurred: {1}", args0: _connectionId, args1: ode?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.ERR, "Connection Id {0}, ObjectDisposedException occurred: {1}", args0: _connectionId, args1: ode?.Message); return ReportErrorAndReleasePacket(errorPacket, ode); } catch (SocketException se) { errorPacket = packet; packet = null; - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.ERR, "Connection Id {0}, Socket exception occurred: {1}", args0: _connectionId, args1: se?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.ERR, "Connection Id {0}, Socket exception occurred: {1}", args0: _connectionId, args1: se?.Message); return ReportErrorAndReleasePacket(errorPacket, se); } catch (IOException ioe) @@ -886,11 +886,11 @@ public override uint Receive(out SniPacket packet, int timeoutInMilliseconds) uint errorCode = ReportErrorAndReleasePacket(errorPacket, ioe); if (ioe.InnerException is SocketException socketException && socketException.SocketErrorCode == SocketError.TimedOut) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.ERR, "Connection Id {0}, IO exception occurred with Wait Timeout (error 258): {1}", args0: _connectionId, args1: ioe?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.ERR, "Connection Id {0}, IO exception occurred with Wait Timeout (error 258): {1}", args0: _connectionId, args1: ioe?.Message); errorCode = TdsEnums.SNI_WAIT_TIMEOUT; } - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.ERR, "Connection Id {0}, IO exception occurred: {1}", args0: _connectionId, args1: ioe?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.ERR, "Connection Id {0}, IO exception occurred: {1}", args0: _connectionId, args1: ioe?.Message); return errorCode; } finally @@ -920,10 +920,10 @@ public override void SetAsyncCallbacks(SNIAsyncCallback receiveCallback, SNIAsyn /// SNI error code public override uint SendAsync(SniPacket packet) { - using (TrySNIEventScope.Create(nameof(SNITCPHandle))) + using (TrySNIEventScope.Create(nameof(SniTcpHandle))) { packet.WriteToStreamAsync(_stream, _sendCallback, SNIProviders.TCP_PROV); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.INFO, "Connection Id {0}, Data sent to stream asynchronously", args0: _connectionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.INFO, "Connection Id {0}, Data sent to stream asynchronously", args0: _connectionId); return TdsEnums.SNI_SUCCESS_IO_PENDING; } } @@ -941,7 +941,7 @@ public override uint ReceiveAsync(ref SniPacket packet) try { packet.ReadFromStreamAsync(_stream); - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.INFO, "Connection Id {0}, Data received from stream asynchronously", args0: _connectionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.INFO, "Connection Id {0}, Data received from stream asynchronously", args0: _connectionId); return TdsEnums.SNI_SUCCESS_IO_PENDING; } catch (Exception e) when (e is ObjectDisposedException || e is SocketException || e is IOException) @@ -972,18 +972,18 @@ public override uint CheckConnection() // return true we can safely determine that the connection is no longer active. if (!_socket.Connected || (_socket.Poll(100, SelectMode.SelectRead) && _socket.Available == 0)) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.INFO, "Connection Id {0}, Socket not usable.", args0: _connectionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.INFO, "Connection Id {0}, Socket not usable.", args0: _connectionId); return TdsEnums.SNI_ERROR; } } catch (SocketException se) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.INFO, "Connection Id {0}, Socket Exception occurred: {1}", args0: _connectionId, args1: se?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.INFO, "Connection Id {0}, Socket Exception occurred: {1}", args0: _connectionId, args1: se?.Message); return ReportTcpSNIError(se); } catch (ObjectDisposedException ode) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.INFO, "Connection Id {0}, ObjectDisposedException occurred: {1}", args0: _connectionId, args1: ode?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.INFO, "Connection Id {0}, ObjectDisposedException occurred: {1}", args0: _connectionId, args1: ode?.Message); return ReportTcpSNIError(ode); } From e763ca5dad6c3e5090a6c8e44af7b7c696f012a5 Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Tue, 13 May 2025 12:57:03 -0500 Subject: [PATCH 13/26] Extract SniAsyncCallback to its own file --- .../netcore/src/Microsoft.Data.SqlClient.csproj | 3 +++ .../Data/SqlClient/ManagedSni/SNICommon.netcore.cs | 7 ------- .../ManagedSni/SniAsyncCallback.netcore.cs | 13 +++++++++++++ .../Data/SqlClient/ManagedSni/SniHandle.netcore.cs | 2 +- .../SqlClient/ManagedSni/SniMarsHandle.netcore.cs | 4 ++-- .../SqlClient/ManagedSni/SniNpHandle.netcore.cs | 6 +++--- .../Data/SqlClient/ManagedSni/SniPacket.netcore.cs | 6 +++--- .../SqlClient/ManagedSni/SniTcpHandle.netcore.cs | 6 +++--- 8 files changed, 28 insertions(+), 19 deletions(-) create mode 100644 src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniAsyncCallback.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index 3752e1c823..b9b29f634c 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -275,6 +275,9 @@ Microsoft\Data\SqlClient\ManagedSni\ConcurrentQueueSemaphore.netcore.cs + + Microsoft\Data\SqlClient\ManagedSni\SniAsyncCallback.netcore.cs + Microsoft\Data\SqlClient\ManagedSni\SniError.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs index c7151eceef..7790070f1a 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs @@ -14,13 +14,6 @@ namespace Microsoft.Data.SqlClient.ManagedSni { - /// - /// SNI Asynchronous callback - /// - /// SNI packet - /// SNI error code - internal delegate void SNIAsyncCallback(SniPacket packet, uint sniErrorCode); - /// /// SNI provider identifiers /// diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniAsyncCallback.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniAsyncCallback.netcore.cs new file mode 100644 index 0000000000..47e80450c0 --- /dev/null +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniAsyncCallback.netcore.cs @@ -0,0 +1,13 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Microsoft.Data.SqlClient.ManagedSni +{ + /// + /// SNI Asynchronous callback + /// + /// SNI packet + /// SNI error code + internal delegate void SniAsyncCallback(SniPacket packet, uint sniErrorCode); +} diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniHandle.netcore.cs index 327c6649dd..145cc0aef7 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniHandle.netcore.cs @@ -47,7 +47,7 @@ protected static void AuthenticateAsClient(SslStream sslStream, string serverNam /// /// Receive callback /// Send callback - public abstract void SetAsyncCallbacks(SNIAsyncCallback receiveCallback, SNIAsyncCallback sendCallback); + public abstract void SetAsyncCallbacks(SniAsyncCallback receiveCallback, SniAsyncCallback sendCallback); /// /// Set buffer size diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsHandle.netcore.cs index 9ad6d93284..85309bf4e4 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsHandle.netcore.cs @@ -26,7 +26,7 @@ internal sealed class SniMarsHandle : SniHandle private readonly ManualResetEventSlim _packetEvent = new ManualResetEventSlim(false); private readonly ManualResetEventSlim _ackEvent = new ManualResetEventSlim(false); private readonly SNISMUXHeader _currentHeader = new SNISMUXHeader(); - private readonly SNIAsyncCallback _handleSendCompleteCallback; + private readonly SniAsyncCallback _handleSendCompleteCallback; private uint _sendHighwater = 4; private int _asyncReceives = 0; @@ -539,7 +539,7 @@ public override uint CheckConnection() /// /// Receive callback /// Send callback - public override void SetAsyncCallbacks(SNIAsyncCallback receiveCallback, SNIAsyncCallback sendCallback) + public override void SetAsyncCallbacks(SniAsyncCallback receiveCallback, SniAsyncCallback sendCallback) { } diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs index ca456675c1..2a5430459b 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs @@ -32,8 +32,8 @@ internal sealed class SniNpHandle : SniPhysicalHandle private SslOverTdsStream _sslOverTdsStream; private SslStream _sslStream; - private SNIAsyncCallback _receiveCallback; - private SNIAsyncCallback _sendCallback; + private SniAsyncCallback _receiveCallback; + private SniAsyncCallback _sendCallback; private bool _validateCert = true; private readonly uint _status = TdsEnums.SNI_UNINITIALIZED; @@ -317,7 +317,7 @@ public override uint SendAsync(SniPacket packet) } } - public override void SetAsyncCallbacks(SNIAsyncCallback receiveCallback, SNIAsyncCallback sendCallback) + public override void SetAsyncCallbacks(SniAsyncCallback receiveCallback, SniAsyncCallback sendCallback) { _receiveCallback = receiveCallback; _sendCallback = sendCallback; diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniPacket.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniPacket.netcore.cs index 83b126b14b..0a1f78208a 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniPacket.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniPacket.netcore.cs @@ -25,7 +25,7 @@ internal sealed class SniPacket private int _headerLength; // the amount of space at the start of the array reserved for the smux header, this is zeroed in SetHeader // _headerOffset is not needed because it is always 0 private byte[] _data; - private SNIAsyncCallback _asyncIOCompletionCallback; + private SniAsyncCallback _asyncIOCompletionCallback; #if DEBUG internal readonly int _id; // in debug mode every packet is assigned a unique id so that the entire lifetime can be tracked when debugging /// refcount = 0 means that a packet should only exist in the pool @@ -114,7 +114,7 @@ public SniPacket() /// Set async receive callback /// /// Completion callback - public void SetAsyncIOCompletionCallback(SNIAsyncCallback asyncIOCompletionCallback) => _asyncIOCompletionCallback = asyncIOCompletionCallback; + public void SetAsyncIOCompletionCallback(SniAsyncCallback asyncIOCompletionCallback) => _asyncIOCompletionCallback = asyncIOCompletionCallback; /// /// Invoke the receive callback @@ -327,7 +327,7 @@ public void WriteToStream(Stream stream) /// Stream to write to /// SNI Asynchronous Callback /// SNI provider identifier - public async void WriteToStreamAsync(Stream stream, SNIAsyncCallback callback, SNIProviders provider) + public async void WriteToStreamAsync(Stream stream, SniAsyncCallback callback, SNIProviders provider) { uint status = TdsEnums.SNI_SUCCESS; try diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniTcpHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniTcpHandle.netcore.cs index edd758cef4..11dea6427f 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniTcpHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniTcpHandle.netcore.cs @@ -33,8 +33,8 @@ internal sealed class SniTcpHandle : SniPhysicalHandle private Stream _stream; private SslStream _sslStream; private SslOverTdsStream _sslOverTdsStream; - private SNIAsyncCallback _receiveCallback; - private SNIAsyncCallback _sendCallback; + private SniAsyncCallback _receiveCallback; + private SniAsyncCallback _sendCallback; private bool _validateCert = true; private int _bufferSize = TdsEnums.DEFAULT_LOGIN_PACKET_SIZE; @@ -907,7 +907,7 @@ public override uint Receive(out SniPacket packet, int timeoutInMilliseconds) /// /// Receive callback /// Send callback - public override void SetAsyncCallbacks(SNIAsyncCallback receiveCallback, SNIAsyncCallback sendCallback) + public override void SetAsyncCallbacks(SniAsyncCallback receiveCallback, SniAsyncCallback sendCallback) { _receiveCallback = receiveCallback; _sendCallback = sendCallback; From cc284dd18d4f571cbb936cd86423db8443415921 Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Tue, 13 May 2025 13:07:40 -0500 Subject: [PATCH 14/26] Extract SniProviders to its own file --- .../src/Microsoft.Data.SqlClient.csproj | 3 ++ .../SqlClient/TdsParserStateObjectManaged.cs | 2 +- .../ManagedSni/LocalDB.netcore.Windows.cs | 12 ++--- .../SqlClient/ManagedSni/SNICommon.netcore.cs | 23 ++-------- .../SqlClient/ManagedSni/SniError.netcore.cs | 6 +-- .../ManagedSni/SniLoadHandle.netcore.cs | 2 +- .../ManagedSni/SniMarsConnection.netcore.cs | 6 +-- .../ManagedSni/SniMarsHandle.netcore.cs | 4 +- .../ManagedSni/SniNpHandle.netcore.cs | 16 +++---- .../SqlClient/ManagedSni/SniPacket.netcore.cs | 6 +-- .../ManagedSni/SniProviders.netcore.cs | 26 +++++++++++ .../SqlClient/ManagedSni/SniProxy.netcore.cs | 44 +++++++++---------- .../ManagedSni/SniTcpHandle.netcore.cs | 6 +-- 13 files changed, 84 insertions(+), 72 deletions(-) create mode 100644 src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniProviders.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index b9b29f634c..9fc78d9c68 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -305,6 +305,9 @@ Microsoft\Data\SqlClient\ManagedSni\SniPhysicalHandle.netcore.cs + + Microsoft\Data\SqlClient\ManagedSni\SniProviders.netcore.cs + Microsoft\Data\SqlClient\ManagedSni\SniProxy.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs index 83a87b719e..a44969e1bd 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs @@ -376,7 +376,7 @@ internal override uint EnableSsl(ref uint info, bool tlsFirst, string serverCert catch (Exception e) { SqlClientEventSource.Log.TryTraceEvent("TdsParserStateObjectManaged.EnableSsl | Err | Session Id {0}, SNI Handshake failed with exception: {1}", sessionHandle.ConnectionId, e.Message); - return SNICommon.ReportSNIError(SNIProviders.SSL_PROV, SNICommon.HandshakeFailureError, e); + return SNICommon.ReportSNIError(SniProviders.SSL_PROV, SNICommon.HandshakeFailureError, e); } } diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Windows.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Windows.cs index b59e324afa..3ea38d03e9 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Windows.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Windows.cs @@ -54,7 +54,7 @@ private string GetConnectionString(string localDbInstance) int result = localDBStartInstanceFunc(localDbInstance, 0, localDBConnectionString, ref sizeOfbuffer); if (result != TdsEnums.SNI_SUCCESS) { - SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBErrorCode, Strings.SNI_ERROR_50); + SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.INVALID_PROV, 0, SNICommon.LocalDBErrorCode, Strings.SNI_ERROR_50); SqlClientEventSource.Log.TrySNITraceEvent(nameof(LocalDB), EventType.ERR, "Unsuccessful 'LocalDBStartInstance' method call with {0} result to start '{1}' localDb instance", args0: result, args1: localDbInstance); localDBConnectionString = null; } @@ -132,7 +132,7 @@ private bool LoadUserInstanceDll() // If there was no DLL path found, then there is an error. if (dllPath == null) { - SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, MapLocalDBErrorStateToCode(registryQueryErrorState), MapLocalDBErrorStateToErrorMessage(registryQueryErrorState)); + SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.INVALID_PROV, 0, MapLocalDBErrorStateToCode(registryQueryErrorState), MapLocalDBErrorStateToErrorMessage(registryQueryErrorState)); SqlClientEventSource.Log.TrySNITraceEvent(nameof(LocalDB), EventType.ERR, "User instance DLL path is null."); return false; } @@ -140,7 +140,7 @@ private bool LoadUserInstanceDll() // In case the registry had an empty path for dll if (string.IsNullOrWhiteSpace(dllPath)) { - SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBInvalidSqlUserInstanceDllPath, Strings.SNI_ERROR_55); + SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.INVALID_PROV, 0, SNICommon.LocalDBInvalidSqlUserInstanceDllPath, Strings.SNI_ERROR_55); SqlClientEventSource.Log.TrySNITraceEvent(nameof(LocalDB), EventType.ERR, "User instance DLL path is invalid. DLL path = {0}", dllPath); return false; } @@ -150,7 +150,7 @@ private bool LoadUserInstanceDll() if (libraryHandle.IsInvalid) { - SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBFailedToLoadDll, Strings.SNI_ERROR_56); + SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.INVALID_PROV, 0, SNICommon.LocalDBFailedToLoadDll, Strings.SNI_ERROR_56); SqlClientEventSource.Log.TrySNITraceEvent(nameof(LocalDB), EventType.ERR, "Library Handle is invalid. Could not load the dll."); libraryHandle.Dispose(); return false; @@ -161,7 +161,7 @@ private bool LoadUserInstanceDll() if (_startInstanceHandle == IntPtr.Zero) { - SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBBadRuntime, Strings.SNI_ERROR_57); + SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.INVALID_PROV, 0, SNICommon.LocalDBBadRuntime, Strings.SNI_ERROR_57); SqlClientEventSource.Log.TrySNITraceEvent(nameof(LocalDB), EventType.ERR, "Was not able to load the PROC from DLL. Bad Runtime."); libraryHandle.Dispose(); return false; @@ -172,7 +172,7 @@ private bool LoadUserInstanceDll() if (localDBStartInstanceFunc == null) { - SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBBadRuntime, Strings.SNI_ERROR_57); + SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.INVALID_PROV, 0, SNICommon.LocalDBBadRuntime, Strings.SNI_ERROR_57); libraryHandle.Dispose(); _startInstanceHandle = IntPtr.Zero; return false; diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs index 7790070f1a..bbd61611ed 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs @@ -14,24 +14,7 @@ namespace Microsoft.Data.SqlClient.ManagedSni { - /// - /// SNI provider identifiers - /// - internal enum SNIProviders - { - HTTP_PROV = 0, // HTTP Provider - NP_PROV = 1, // Named Pipes Provider - SESSION_PROV = 2, // Session Provider - SIGN_PROV = 3, // Sign Provider - SM_PROV = 4, // Shared Memory Provider - SMUX_PROV = 5, // SMUX Provider - SSL_PROV = 6, // SSL Provider - TCP_PROV = 7, // TCP Provider - VIA_PROV = 8, // Virtual Interface Architecture Provider - CTAIP_PROV = 9, - MAX_PROVS = 10, // Number of providers - INVALID_PROV = 11 // SQL Network Interfaces - } + /// /// SMUX packet header @@ -275,7 +258,7 @@ internal static IPAddress[] GetDnsIpAddresses(string serverName) /// SNI error code /// Error message /// - internal static uint ReportSNIError(SNIProviders provider, uint nativeError, uint sniError, string errorMessage) + internal static uint ReportSNIError(SniProviders provider, uint nativeError, uint sniError, string errorMessage) { SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNICommon), EventType.ERR, "Provider = {0}, native Error = {1}, SNI Error = {2}, Error Message = {3}", args0: provider, args1: nativeError, args2: sniError, args3: errorMessage); return ReportSNIError(new SniError(provider, nativeError, sniError, errorMessage)); @@ -289,7 +272,7 @@ internal static uint ReportSNIError(SNIProviders provider, uint nativeError, uin /// SNI Exception /// Native SNI error code /// - internal static uint ReportSNIError(SNIProviders provider, uint sniError, Exception sniException, uint nativeErrorCode = 0) + internal static uint ReportSNIError(SniProviders provider, uint sniError, Exception sniException, uint nativeErrorCode = 0) { SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNICommon), EventType.ERR, "Provider = {0}, SNI Error = {1}, Exception = {2}", args0: provider, args1: sniError, args2: sniException?.Message); return ReportSNIError(new SniError(provider, sniError, sniException, nativeErrorCode)); diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniError.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniError.netcore.cs index 1aea18a925..1b7f9138c5 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniError.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniError.netcore.cs @@ -14,7 +14,7 @@ internal class SniError // Error numbers from native SNI implementation internal const uint CertificateValidationErrorCode = 2148074277; - public readonly SNIProviders provider; + public readonly SniProviders provider; public readonly string errorMessage; public readonly uint nativeError; public readonly uint sniError; @@ -22,7 +22,7 @@ internal class SniError public readonly uint lineNumber; public readonly Exception exception; - public SniError(SNIProviders provider, uint nativeError, uint sniErrorCode, string errorMessage) + public SniError(SniProviders provider, uint nativeError, uint sniErrorCode, string errorMessage) { lineNumber = 0; function = string.Empty; @@ -33,7 +33,7 @@ public SniError(SNIProviders provider, uint nativeError, uint sniErrorCode, stri exception = null; } - public SniError(SNIProviders provider, uint sniErrorCode, Exception sniException, uint nativeErrorCode = 0) + public SniError(SniProviders provider, uint sniErrorCode, Exception sniException, uint nativeErrorCode = 0) { lineNumber = 0; function = string.Empty; diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniLoadHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniLoadHandle.netcore.cs index f9bd7eac02..c34d8462a9 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniLoadHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniLoadHandle.netcore.cs @@ -14,7 +14,7 @@ internal class SniLoadHandle public static readonly SniLoadHandle SingletonInstance = new SniLoadHandle(); public readonly EncryptionOptions _encryptionOption = EncryptionOptions.OFF; - public ThreadLocal _lastError = new ThreadLocal(static () => new SniError(SNIProviders.INVALID_PROV, 0, TdsEnums.SNI_SUCCESS, string.Empty)); + public ThreadLocal _lastError = new ThreadLocal(static () => new SniError(SniProviders.INVALID_PROV, 0, TdsEnums.SNI_SUCCESS, string.Empty)); private readonly uint _status = TdsEnums.SNI_SUCCESS; diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsConnection.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsConnection.netcore.cs index e037978521..ad87bc5059 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsConnection.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsConnection.netcore.cs @@ -81,7 +81,7 @@ public uint StartReceive() return TdsEnums.SNI_SUCCESS_IO_PENDING; } SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsConnection), EventType.ERR, "MARS Session Id {0}, Connection not usable.", args0: ConnectionId); - return SNICommon.ReportSNIError(SNIProviders.SMUX_PROV, 0, SNICommon.ConnNotUsableError, Strings.SNI_ERROR_19); + return SNICommon.ReportSNIError(SniProviders.SMUX_PROV, 0, SNICommon.ConnNotUsableError, Strings.SNI_ERROR_19); } } @@ -288,7 +288,7 @@ public void HandleReceiveComplete(SniPacket packet, uint sniErrorCode) if (!_sessions.ContainsKey(_currentHeader.sessionId)) { - SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.SMUX_PROV, 0, SNICommon.InvalidParameterError, Strings.SNI_ERROR_5); + SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.SMUX_PROV, 0, SNICommon.InvalidParameterError, Strings.SNI_ERROR_5); HandleReceiveError(packet); SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsConnection), EventType.ERR, "Current Header Session Id {0} not found, MARS Session Id {1} will be destroyed, New SNI error created: {2}", args0: _currentHeader?.sessionId, args1: _lowerHandle?.ConnectionId, args2: sniErrorCode); _lowerHandle.Dispose(); @@ -324,7 +324,7 @@ public void HandleReceiveComplete(SniPacket packet, uint sniErrorCode) catch (Exception e) { SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsConnection), EventType.ERR, "SMUX_ACK | MARS Session Id {0}, Exception occurred: {2}", args0: _currentHeader?.sessionId, args1: e?.Message); - SNICommon.ReportSNIError(SNIProviders.SMUX_PROV, SNICommon.InternalExceptionError, e); + SNICommon.ReportSNIError(SniProviders.SMUX_PROV, SNICommon.InternalExceptionError, e); } #if DEBUG Debug.Assert(_currentPacket == currentPacket, "current and _current are not the same"); diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsHandle.netcore.cs index 85309bf4e4..af4c11838c 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsHandle.netcore.cs @@ -64,7 +64,7 @@ public override void Dispose() catch (Exception e) { SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.ERR, "MARS Session Id {0}, Internal exception error = {1}, Member Name={2}", args0: ConnectionId, args1: e?.Message, args2: e?.GetType()?.Name); - SNICommon.ReportSNIError(SNIProviders.SMUX_PROV, SNICommon.InternalExceptionError, e); + SNICommon.ReportSNIError(SniProviders.SMUX_PROV, SNICommon.InternalExceptionError, e); } } } @@ -517,7 +517,7 @@ public override uint Receive(out SniPacket packet, int timeoutInMilliseconds) SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, Waiting for packet event.", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater); if (!_packetEvent.Wait(timeoutInMilliseconds)) { - SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.SMUX_PROV, 0, SNICommon.ConnTimeoutError, Strings.SNI_ERROR_11); + SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.SMUX_PROV, 0, SNICommon.ConnTimeoutError, Strings.SNI_ERROR_11); SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, _packetEvent wait timed out.", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater); return TdsEnums.SNI_WAIT_TIMEOUT; } diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs index 2a5430459b..10c338ec0f 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs @@ -82,14 +82,14 @@ public SniNpHandle(string serverName, string pipeName, TimeoutTimer timeout, boo } catch (TimeoutException te) { - SNICommon.ReportSNIError(SNIProviders.NP_PROV, SNICommon.ConnOpenFailedError, te); + SNICommon.ReportSNIError(SniProviders.NP_PROV, SNICommon.ConnOpenFailedError, te); _status = TdsEnums.SNI_ERROR; SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.ERR, "Connection Id {0}, Connection Timed out. Error Code 1 Exception = {1}", args0: _connectionId, args1: te?.Message); return; } catch (IOException ioe) { - SNICommon.ReportSNIError(SNIProviders.NP_PROV, SNICommon.ConnOpenFailedError, ioe); + SNICommon.ReportSNIError(SniProviders.NP_PROV, SNICommon.ConnOpenFailedError, ioe); _status = TdsEnums.SNI_ERROR; SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.ERR, "Connection Id {0}, IO Exception occurred. Error Code 1 Exception = {1}", args0: _connectionId, args1: ioe?.Message); return; @@ -97,7 +97,7 @@ public SniNpHandle(string serverName, string pipeName, TimeoutTimer timeout, boo if (!_pipeStream.IsConnected || !_pipeStream.CanWrite || !_pipeStream.CanRead) { - SNICommon.ReportSNIError(SNIProviders.NP_PROV, 0, SNICommon.ConnOpenFailedError, Strings.SNI_ERROR_40); + SNICommon.ReportSNIError(SniProviders.NP_PROV, 0, SNICommon.ConnOpenFailedError, Strings.SNI_ERROR_40); _status = TdsEnums.SNI_ERROR; SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.ERR, "Connection Id {0}, Pipe Stream not operational. Error Code 1 Exception = {1}", args0: _connectionId, args1: Strings.SNI_ERROR_1); return; @@ -312,7 +312,7 @@ public override uint SendAsync(SniPacket packet) using (TrySNIEventScope.Create(nameof(SniNpHandle))) { SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.INFO, "Connection Id {0}, Packet writing to stream, dataLeft {1}", args0: _connectionId, args1: packet?.DataLeft); - packet.WriteToStreamAsync(_stream, _sendCallback, SNIProviders.NP_PROV); + packet.WriteToStreamAsync(_stream, _sendCallback, SniProviders.NP_PROV); return TdsEnums.SNI_SUCCESS_IO_PENDING; } } @@ -347,12 +347,12 @@ public override uint EnableSsl(uint options) catch (AuthenticationException aue) { SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.ERR, "Connection Id {0}, AuthenticationException message = {1}.", args0: ConnectionId, args1: aue?.Message); - return SNICommon.ReportSNIError(SNIProviders.NP_PROV, SNICommon.InternalExceptionError, aue); + return SNICommon.ReportSNIError(SniProviders.NP_PROV, SNICommon.InternalExceptionError, aue); } catch (InvalidOperationException ioe) { SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.ERR, "Connection Id {0}, InvalidOperationException message = {1}.", args0: ConnectionId, args1: ioe?.Message); - return SNICommon.ReportSNIError(SNIProviders.NP_PROV, SNICommon.InternalExceptionError, ioe); + return SNICommon.ReportSNIError(SniProviders.NP_PROV, SNICommon.InternalExceptionError, ioe); } _stream = _sslStream; return TdsEnums.SNI_SUCCESS; @@ -408,7 +408,7 @@ private uint ReportErrorAndReleasePacket(SniPacket packet, Exception sniExceptio ReturnPacket(packet); } SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.INFO, "Connection Id {0}, Packet returned, error occurred: {1}", args0: ConnectionId, args1: sniException?.Message); - return SNICommon.ReportSNIError(SNIProviders.NP_PROV, SNICommon.InternalExceptionError, sniException); + return SNICommon.ReportSNIError(SniProviders.NP_PROV, SNICommon.InternalExceptionError, sniException); } private uint ReportErrorAndReleasePacket(SniPacket packet, uint nativeError, uint sniError, string errorMessage) @@ -418,7 +418,7 @@ private uint ReportErrorAndReleasePacket(SniPacket packet, uint nativeError, uin ReturnPacket(packet); } SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.INFO, "Connection Id {0}, Packet returned, error occurred: {1}", args0: ConnectionId, args1: errorMessage); - return SNICommon.ReportSNIError(SNIProviders.NP_PROV, nativeError, sniError, errorMessage); + return SNICommon.ReportSNIError(SniProviders.NP_PROV, nativeError, sniError, errorMessage); } #if DEBUG diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniPacket.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniPacket.netcore.cs index 0a1f78208a..98fd8438f9 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniPacket.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniPacket.netcore.cs @@ -284,7 +284,7 @@ private static void ReadFromStreamAsyncContinuation(Task task, object state Exception e = task.Exception?.InnerException; if (e != null) { - SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.TCP_PROV, SNICommon.InternalExceptionError, e); + SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.TCP_PROV, SNICommon.InternalExceptionError, e); #if DEBUG SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniPacket), EventType.ERR, "Connection Id {0}, Internal Exception occurred while reading data: {1}", args0: packet._owner?.ConnectionId, args1: e?.Message); #endif @@ -298,7 +298,7 @@ private static void ReadFromStreamAsyncContinuation(Task task, object state #endif if (packet._dataLength == 0) { - SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.TCP_PROV, 0, SNICommon.ConnTerminatedError, Strings.SNI_ERROR_2); + SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.TCP_PROV, 0, SNICommon.ConnTerminatedError, Strings.SNI_ERROR_2); #if DEBUG SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniPacket), EventType.ERR, "Connection Id {0}, No data read from stream, connection was terminated.", args0: packet._owner?.ConnectionId); #endif @@ -327,7 +327,7 @@ public void WriteToStream(Stream stream) /// Stream to write to /// SNI Asynchronous Callback /// SNI provider identifier - public async void WriteToStreamAsync(Stream stream, SniAsyncCallback callback, SNIProviders provider) + public async void WriteToStreamAsync(Stream stream, SniAsyncCallback callback, SniProviders provider) { uint status = TdsEnums.SNI_SUCCESS; try diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniProviders.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniProviders.netcore.cs new file mode 100644 index 0000000000..623e76c80b --- /dev/null +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniProviders.netcore.cs @@ -0,0 +1,26 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Microsoft.Data.SqlClient.ManagedSni +{ + /// + /// SNI provider identifiers + /// + internal enum SniProviders + { + // @TODO: Rename to follow enum naming conventions, remove PROV suffix - we get it, it's in the Providers enum. + HTTP_PROV = 0, // HTTP Provider + NP_PROV = 1, // Named Pipes Provider + SESSION_PROV = 2, // Session Provider + SIGN_PROV = 3, // Sign Provider + SM_PROV = 4, // Shared Memory Provider + SMUX_PROV = 5, // SMUX Provider + SSL_PROV = 6, // SSL Provider + TCP_PROV = 7, // TCP Provider + VIA_PROV = 8, // Virtual Interface Architecture Provider + CTAIP_PROV = 9, + MAX_PROVS = 10, // Number of providers + INVALID_PROV = 11 // SQL Network Interfaces + } +} diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniProxy.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniProxy.netcore.cs index 1d15cba8bb..84cd209e36 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniProxy.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniProxy.netcore.cs @@ -104,7 +104,7 @@ internal static SniHandle CreateConnectionHandle( } catch (Exception e) { - SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, SNICommon.ErrorSpnLookup, e); + SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.INVALID_PROV, SNICommon.ErrorSpnLookup, e); } } @@ -205,7 +205,7 @@ private static SniTcpHandle CreateTcpHandle( string hostName = details.ServerName; if (string.IsNullOrWhiteSpace(hostName)) { - SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.TCP_PROV, 0, SNICommon.InvalidConnStringError, Strings.SNI_ERROR_25); + SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.TCP_PROV, 0, SNICommon.InvalidConnStringError, Strings.SNI_ERROR_25); return null; } @@ -221,7 +221,7 @@ private static SniTcpHandle CreateTcpHandle( } catch (SocketException se) { - SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.TCP_PROV, SNICommon.ErrorLocatingServerInstance, se); + SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.TCP_PROV, SNICommon.ErrorLocatingServerInstance, se); return null; } } @@ -253,7 +253,7 @@ private static SniNpHandle CreateNpHandle(DataSource details, TimeoutTimer timeo if (parallel) { // Connecting to a SQL Server instance using the MultiSubnetFailover connection option is only supported when using the TCP protocol - SNICommon.ReportSNIError(SNIProviders.NP_PROV, 0, SNICommon.MultiSubnetFailoverWithNonTcpProtocol, Strings.SNI_ERROR_49); + SNICommon.ReportSNIError(SniProviders.NP_PROV, 0, SNICommon.MultiSubnetFailoverWithNonTcpProtocol, Strings.SNI_ERROR_49); return null; } return new SniNpHandle(details.PipeHostName, details.PipeName, timeout, tlsFirst, hostNameInCertificate, serverCertificateFilename); @@ -382,11 +382,11 @@ private DataSource(string dataSource) if (_dataSourceAfterTrimmingProtocol.Contains(Slash)) // Pipe paths only allow back slashes { if (ResolvedProtocol == Protocol.None) - ReportSNIError(SNIProviders.INVALID_PROV); + ReportSNIError(SniProviders.INVALID_PROV); else if (ResolvedProtocol == Protocol.NP) - ReportSNIError(SNIProviders.NP_PROV); + ReportSNIError(SniProviders.NP_PROV); else if (ResolvedProtocol == Protocol.TCP) - ReportSNIError(SNIProviders.TCP_PROV); + ReportSNIError(SniProviders.TCP_PROV); } } @@ -439,7 +439,7 @@ internal static string GetLocalDBInstance(string dataSource, out bool error) } else if (index > 0) { - SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, SNICommon.ErrorLocatingServerInstance, Strings.SNI_ERROR_26); + SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.INVALID_PROV, 0, SNICommon.ErrorLocatingServerInstance, Strings.SNI_ERROR_26); SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniProxy), EventType.ERR, "Incompatible use of prefix with LocalDb: '{0}'", dataSource); error = true; } @@ -458,7 +458,7 @@ internal static string GetLocalDBInstance(string dataSource, out bool error) } else { - SniLoadHandle.SingletonInstance.LastError = new SniError(SNIProviders.INVALID_PROV, 0, SNICommon.LocalDBNoInstanceName, Strings.SNI_ERROR_51); + SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.INVALID_PROV, 0, SNICommon.LocalDBNoInstanceName, Strings.SNI_ERROR_51); error = true; } } @@ -525,7 +525,7 @@ private bool InferConnectionDetails() // Bad Data Source like "server, " if (string.IsNullOrEmpty(parameter)) { - ReportSNIError(SNIProviders.INVALID_PROV); + ReportSNIError(SniProviders.INVALID_PROV); return false; } @@ -537,21 +537,21 @@ private bool InferConnectionDetails() else if (ResolvedProtocol != Protocol.TCP) { // Parameter has been specified for non-TCP protocol. This is not allowed. - ReportSNIError(SNIProviders.INVALID_PROV); + ReportSNIError(SniProviders.INVALID_PROV); return false; } int port; if (!int.TryParse(parameter, out port)) { - ReportSNIError(SNIProviders.TCP_PROV); + ReportSNIError(SniProviders.TCP_PROV); return false; } // If the user explicitly specified a invalid port in the connection string. if (port < 1) { - ReportSNIError(SNIProviders.TCP_PROV); + ReportSNIError(SniProviders.TCP_PROV); return false; } @@ -565,13 +565,13 @@ private bool InferConnectionDetails() if (string.IsNullOrWhiteSpace(InstanceName)) { - ReportSNIError(SNIProviders.INVALID_PROV); + ReportSNIError(SniProviders.INVALID_PROV); return false; } if (DefaultSqlServerInstanceName.Equals(InstanceName)) { - ReportSNIError(SNIProviders.INVALID_PROV); + ReportSNIError(SniProviders.INVALID_PROV); return false; } @@ -583,7 +583,7 @@ private bool InferConnectionDetails() return true; } - private void ReportSNIError(SNIProviders provider) + private void ReportSNIError(SniProviders provider) { SniLoadHandle.SingletonInstance.LastError = new SniError(provider, 0, SNICommon.InvalidConnStringError, Strings.SNI_ERROR_25); IsBadDataSource = true; @@ -612,7 +612,7 @@ private bool InferNamedPipesInformation() } else { - ReportSNIError(SNIProviders.NP_PROV); + ReportSNIError(SniProviders.NP_PROV); return false; } } @@ -635,7 +635,7 @@ private bool InferNamedPipesInformation() // Another valid Sql named pipe for an named instance is \\.\pipe\MSSQL$MYINSTANCE\sql\query if (tokensByBackSlash.Length < 6) { - ReportSNIError(SNIProviders.NP_PROV); + ReportSNIError(SniProviders.NP_PROV); return false; } @@ -643,14 +643,14 @@ private bool InferNamedPipesInformation() if (string.IsNullOrEmpty(host)) { - ReportSNIError(SNIProviders.NP_PROV); + ReportSNIError(SniProviders.NP_PROV); return false; } //Check if the "pipe" keyword is the first part of path if (!PipeToken.Equals(tokensByBackSlash[3])) { - ReportSNIError(SNIProviders.NP_PROV); + ReportSNIError(SniProviders.NP_PROV); return false; } @@ -682,7 +682,7 @@ private bool InferNamedPipesInformation() } catch (UriFormatException) { - ReportSNIError(SNIProviders.NP_PROV); + ReportSNIError(SniProviders.NP_PROV); return false; } @@ -694,7 +694,7 @@ private bool InferNamedPipesInformation() else if (ResolvedProtocol != Protocol.NP) { // In case the path began with a "\\" and protocol was not Named Pipes - ReportSNIError(SNIProviders.NP_PROV); + ReportSNIError(SniProviders.NP_PROV); return false; } return true; diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniTcpHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniTcpHandle.netcore.cs index 11dea6427f..582661e2ca 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniTcpHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniTcpHandle.netcore.cs @@ -922,7 +922,7 @@ public override uint SendAsync(SniPacket packet) { using (TrySNIEventScope.Create(nameof(SniTcpHandle))) { - packet.WriteToStreamAsync(_stream, _sendCallback, SNIProviders.TCP_PROV); + packet.WriteToStreamAsync(_stream, _sendCallback, SniProviders.TCP_PROV); SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.INFO, "Connection Id {0}, Data sent to stream asynchronously", args0: _connectionId); return TdsEnums.SNI_SUCCESS_IO_PENDING; } @@ -993,13 +993,13 @@ public override uint CheckConnection() private uint ReportTcpSNIError(Exception sniException, uint nativeErrorCode = 0) { _status = TdsEnums.SNI_ERROR; - return SNICommon.ReportSNIError(SNIProviders.TCP_PROV, SNICommon.InternalExceptionError, sniException, nativeErrorCode); + return SNICommon.ReportSNIError(SniProviders.TCP_PROV, SNICommon.InternalExceptionError, sniException, nativeErrorCode); } private uint ReportTcpSNIError(uint nativeError, uint sniError, string errorMessage) { _status = TdsEnums.SNI_ERROR; - return SNICommon.ReportSNIError(SNIProviders.TCP_PROV, nativeError, sniError, errorMessage); + return SNICommon.ReportSNIError(SniProviders.TCP_PROV, nativeError, sniError, errorMessage); } private uint ReportErrorAndReleasePacket(SniPacket packet, Exception sniException) From 389a7e9b714562b0b6cc06fe13f2fc03ea73b8f8 Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Tue, 13 May 2025 13:12:52 -0500 Subject: [PATCH 15/26] Extract SniSmuxHeader to its own file --- .../src/Microsoft.Data.SqlClient.csproj | 3 + .../SqlClient/ManagedSni/SNICommon.netcore.cs | 59 ----------------- .../ManagedSni/SniSmuxHeader.netcore.cs | 65 +++++++++++++++++++ 3 files changed, 68 insertions(+), 59 deletions(-) create mode 100644 src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniSmuxHeader.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index 9fc78d9c68..a05a7a6df4 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -311,6 +311,9 @@ Microsoft\Data\SqlClient\ManagedSni\SniProxy.netcore.cs + + Microsoft\Data\SqlClient\ManagedSni\SniSmuxHeader.netcore.cs + Microsoft\Data\SqlClient\ManagedSni\SNIStream.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs index bbd61611ed..184491126b 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Buffers.Binary; using System.Diagnostics; using System.Net; using System.Net.Security; @@ -14,64 +13,6 @@ namespace Microsoft.Data.SqlClient.ManagedSni { - - - /// - /// SMUX packet header - /// - internal sealed class SNISMUXHeader - { - public const int HEADER_LENGTH = 16; - - public byte SMID; - public byte flags; - public ushort sessionId; - public uint length; - public uint sequenceNumber; - public uint highwater; - - public void Read(byte[] bytes) - { - SMID = bytes[0]; - flags = bytes[1]; - Span span = bytes.AsSpan(); - sessionId = BinaryPrimitives.ReadUInt16LittleEndian(span.Slice(2)); - length = BinaryPrimitives.ReadUInt32LittleEndian(span.Slice(4)) - SNISMUXHeader.HEADER_LENGTH; - sequenceNumber = BinaryPrimitives.ReadUInt32LittleEndian(span.Slice(8)); - highwater = BinaryPrimitives.ReadUInt32LittleEndian(span.Slice(12)); - } - - public void Write(Span bytes) - { - uint value = highwater; - // access the highest element first to cause the largest range check in the jit, then fill in the rest of the value and carry on as normal - bytes[15] = (byte)((value >> 24) & 0xff); - bytes[12] = (byte)(value & 0xff); // BitConverter.GetBytes(_currentHeader.highwater).CopyTo(headerBytes, 12); - bytes[13] = (byte)((value >> 8) & 0xff); - bytes[14] = (byte)((value >> 16) & 0xff); - - bytes[0] = SMID; // BitConverter.GetBytes(_currentHeader.SMID).CopyTo(headerBytes, 0); - bytes[1] = flags; // BitConverter.GetBytes(_currentHeader.flags).CopyTo(headerBytes, 1); - - value = sessionId; - bytes[2] = (byte)(value & 0xff); // BitConverter.GetBytes(_currentHeader.sessionId).CopyTo(headerBytes, 2); - bytes[3] = (byte)((value >> 8) & 0xff); - - value = length; - bytes[4] = (byte)(value & 0xff); // BitConverter.GetBytes(_currentHeader.length).CopyTo(headerBytes, 4); - bytes[5] = (byte)((value >> 8) & 0xff); - bytes[6] = (byte)((value >> 16) & 0xff); - bytes[7] = (byte)((value >> 24) & 0xff); - - value = sequenceNumber; - bytes[8] = (byte)(value & 0xff); // BitConverter.GetBytes(_currentHeader.sequenceNumber).CopyTo(headerBytes, 8); - bytes[9] = (byte)((value >> 8) & 0xff); - bytes[10] = (byte)((value >> 16) & 0xff); - bytes[11] = (byte)((value >> 24) & 0xff); - - } - } - /// /// SMUX packet flags /// diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniSmuxHeader.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniSmuxHeader.netcore.cs new file mode 100644 index 0000000000..601a09741d --- /dev/null +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniSmuxHeader.netcore.cs @@ -0,0 +1,65 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Buffers.Binary; + +namespace Microsoft.Data.SqlClient.ManagedSni +{ + /// + /// SMUX packet header + /// + internal sealed class SNISMUXHeader + { + public const int HEADER_LENGTH = 16; + + public byte SMID; + public byte flags; + public ushort sessionId; + public uint length; + public uint sequenceNumber; + public uint highwater; + + public void Read(byte[] bytes) + { + SMID = bytes[0]; + flags = bytes[1]; + Span span = bytes.AsSpan(); + sessionId = BinaryPrimitives.ReadUInt16LittleEndian(span.Slice(2)); + length = BinaryPrimitives.ReadUInt32LittleEndian(span.Slice(4)) - SNISMUXHeader.HEADER_LENGTH; + sequenceNumber = BinaryPrimitives.ReadUInt32LittleEndian(span.Slice(8)); + highwater = BinaryPrimitives.ReadUInt32LittleEndian(span.Slice(12)); + } + + public void Write(Span bytes) + { + uint value = highwater; + // access the highest element first to cause the largest range check in the jit, then fill in the rest of the value and carry on as normal + bytes[15] = (byte)((value >> 24) & 0xff); + bytes[12] = (byte)(value & 0xff); // BitConverter.GetBytes(_currentHeader.highwater).CopyTo(headerBytes, 12); + bytes[13] = (byte)((value >> 8) & 0xff); + bytes[14] = (byte)((value >> 16) & 0xff); + + bytes[0] = SMID; // BitConverter.GetBytes(_currentHeader.SMID).CopyTo(headerBytes, 0); + bytes[1] = flags; // BitConverter.GetBytes(_currentHeader.flags).CopyTo(headerBytes, 1); + + value = sessionId; + bytes[2] = (byte)(value & 0xff); // BitConverter.GetBytes(_currentHeader.sessionId).CopyTo(headerBytes, 2); + bytes[3] = (byte)((value >> 8) & 0xff); + + value = length; + bytes[4] = (byte)(value & 0xff); // BitConverter.GetBytes(_currentHeader.length).CopyTo(headerBytes, 4); + bytes[5] = (byte)((value >> 8) & 0xff); + bytes[6] = (byte)((value >> 16) & 0xff); + bytes[7] = (byte)((value >> 24) & 0xff); + + value = sequenceNumber; + bytes[8] = (byte)(value & 0xff); // BitConverter.GetBytes(_currentHeader.sequenceNumber).CopyTo(headerBytes, 8); + bytes[9] = (byte)((value >> 8) & 0xff); + bytes[10] = (byte)((value >> 16) & 0xff); + bytes[11] = (byte)((value >> 24) & 0xff); + + } + } +} From 11fc3871f91098f1f8e1bfff524bb7a8396b96ab Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Tue, 13 May 2025 13:21:32 -0500 Subject: [PATCH 16/26] Extract SniSmuxFlags to its own file --- .../src/Microsoft.Data.SqlClient.csproj | 3 ++ .../SqlClient/ManagedSni/SNICommon.netcore.cs | 12 ------- .../ManagedSni/SniMarsConnection.netcore.cs | 8 ++--- .../ManagedSni/SniMarsHandle.netcore.cs | 14 ++++---- .../ManagedSni/SniSmuxFlags.netcore.cs | 36 +++++++++++++++++++ 5 files changed, 50 insertions(+), 23 deletions(-) create mode 100644 src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniSmuxFlags.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index a05a7a6df4..9bea583e63 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -311,6 +311,9 @@ Microsoft\Data\SqlClient\ManagedSni\SniProxy.netcore.cs + + Microsoft\Data\SqlClient\ManagedSni\SniSmuxFlags.netcore.cs + Microsoft\Data\SqlClient\ManagedSni\SniSmuxHeader.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs index 184491126b..8bc48cd353 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs @@ -13,18 +13,6 @@ namespace Microsoft.Data.SqlClient.ManagedSni { - /// - /// SMUX packet flags - /// - [Flags] - internal enum SNISMUXFlags - { - SMUX_SYN = 1, // Begin SMUX connection - SMUX_ACK = 2, // Acknowledge SMUX packets - SMUX_FIN = 4, // End SMUX connection - SMUX_DATA = 8 // SMUX data packet - } - internal class SNICommon { // Each error number maps to SNI_ERROR_* in String.resx diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsConnection.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsConnection.netcore.cs index ad87bc5059..44ed0b5a30 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsConnection.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsConnection.netcore.cs @@ -260,7 +260,7 @@ public void HandleReceiveComplete(SniPacket packet, uint sniErrorCode) currentHeader = _currentHeader; currentPacket = _currentPacket; - if (_currentHeader.flags == (byte)SNISMUXFlags.SMUX_DATA) + if (_currentHeader.flags == (byte)SniSmuxFlags.SMUX_DATA) { if (_dataBytesLeft > 0) { @@ -296,7 +296,7 @@ public void HandleReceiveComplete(SniPacket packet, uint sniErrorCode) return; } - if (_currentHeader.flags == (byte)SNISMUXFlags.SMUX_FIN) + if (_currentHeader.flags == (byte)SniSmuxFlags.SMUX_FIN) { _sessions.Remove(_currentHeader.sessionId); SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsConnection), EventType.INFO, "SMUX_FIN | MARS Session Id {0}, SMUX_FIN flag received, Current Header Session Id {1} removed", args0: _lowerHandle?.ConnectionId, args1: _currentHeader?.sessionId); @@ -308,13 +308,13 @@ public void HandleReceiveComplete(SniPacket packet, uint sniErrorCode) } } - if (currentHeader.flags == (byte)SNISMUXFlags.SMUX_DATA) + if (currentHeader.flags == (byte)SniSmuxFlags.SMUX_DATA) { currentSession.HandleReceiveComplete(currentPacket, currentHeader); SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsConnection), EventType.INFO, "SMUX_DATA | MARS Session Id {0}, Current Session {1} completed receiving Data", args0: _lowerHandle?.ConnectionId, args1: _currentHeader?.sessionId); } - if (_currentHeader.flags == (byte)SNISMUXFlags.SMUX_ACK) + if (_currentHeader.flags == (byte)SniSmuxFlags.SMUX_ACK) { try { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsHandle.netcore.cs index af4c11838c..697899b9a8 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsHandle.netcore.cs @@ -58,7 +58,7 @@ public override void Dispose() { try { - SendControlPacket(SNISMUXFlags.SMUX_FIN); + SendControlPacket(SniSmuxFlags.SMUX_FIN); SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, Sent SMUX_FIN packet to terminate session.", args0: ConnectionId); } catch (Exception e) @@ -83,7 +83,7 @@ public SniMarsHandle(SniMarsConnection connection, ushort sessionId, object call _connectionId = connection.ConnectionId; _callbackObject = callbackObject; _handleSendCompleteCallback = HandleSendComplete; - SendControlPacket(SNISMUXFlags.SMUX_SYN); + SendControlPacket(SniSmuxFlags.SMUX_SYN); SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, Sent SMUX_SYN packet to start a new session, session Id {1}", args0: ConnectionId, args1: _sessionId); _status = TdsEnums.SNI_SUCCESS; } @@ -92,7 +92,7 @@ public SniMarsHandle(SniMarsConnection connection, ushort sessionId, object call /// Send control packet /// /// SMUX header flags - private void SendControlPacket(SNISMUXFlags flags) + private void SendControlPacket(SniSmuxFlags flags) { using (TrySNIEventScope.Create(nameof(SniMarsHandle))) { @@ -116,7 +116,7 @@ private void SendControlPacket(SNISMUXFlags flags) } } - private void SetupSMUXHeader(int length, SNISMUXFlags flags) + private void SetupSMUXHeader(int length, SniSmuxFlags flags) { Debug.Assert(Monitor.IsEntered(this), "must take lock on self before updating smux header"); @@ -124,7 +124,7 @@ private void SetupSMUXHeader(int length, SNISMUXFlags flags) _currentHeader.flags = (byte)flags; _currentHeader.sessionId = _sessionId; _currentHeader.length = (uint)SNISMUXHeader.HEADER_LENGTH + (uint)length; - _currentHeader.sequenceNumber = ((flags == SNISMUXFlags.SMUX_FIN) || (flags == SNISMUXFlags.SMUX_ACK)) ? _sequenceNumber - 1 : _sequenceNumber++; + _currentHeader.sequenceNumber = ((flags == SniSmuxFlags.SMUX_FIN) || (flags == SniSmuxFlags.SMUX_ACK)) ? _sequenceNumber - 1 : _sequenceNumber++; _currentHeader.highwater = _receiveHighwater; _receiveHighwaterLastAck = _currentHeader.highwater; } @@ -138,7 +138,7 @@ private SniPacket SetPacketSMUXHeader(SniPacket packet) { Debug.Assert(packet.ReservedHeaderSize == SNISMUXHeader.HEADER_LENGTH, "mars handle attempting to smux packet without smux reservation"); - SetupSMUXHeader(packet.Length, SNISMUXFlags.SMUX_DATA); + SetupSMUXHeader(packet.Length, SniSmuxFlags.SMUX_DATA); _currentHeader.Write(packet.GetHeaderBuffer(SNISMUXHeader.HEADER_LENGTH)); packet.SetHeaderActive(); #if DEBUG @@ -456,7 +456,7 @@ private void SendAckIfNecessary() if (receiveHighwater - receiveHighwaterLastAck > ACK_THRESHOLD) { - SendControlPacket(SNISMUXFlags.SMUX_ACK); + SendControlPacket(SniSmuxFlags.SMUX_ACK); SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, _asyncReceives {1}, _receiveHighwater {2}, _sendHighwater {3}, _receiveHighwaterLastAck {4} Sending acknowledgment ACK_THRESHOLD {5}", args0: ConnectionId, args1: _asyncReceives, args2: _receiveHighwater, args3: _sendHighwater, args4: _receiveHighwaterLastAck, args5: ACK_THRESHOLD); } } diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniSmuxFlags.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniSmuxFlags.netcore.cs new file mode 100644 index 0000000000..5611bcb7cb --- /dev/null +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniSmuxFlags.netcore.cs @@ -0,0 +1,36 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; + +namespace Microsoft.Data.SqlClient.ManagedSni +{ + /// + /// SMUX packet flags + /// + [Flags] + internal enum SniSmuxFlags + { + // @TODO: Should probably drop the SMUX prefix - it's pretty obvious since it's in the SmuxFlags enum. + /// + /// Begin SMUX connection. + /// + SMUX_SYN = 1, + + /// + /// Acknowledge SMUX packets. + /// + SMUX_ACK = 2, + + /// + /// End SMUX connection. + /// + SMUX_FIN = 4, + + /// + /// SMUX data packet. + /// + SMUX_DATA = 8 + } +} From c18012ebaa52942e6c5e99aaba510b7cf4deccf5 Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Tue, 13 May 2025 13:25:49 -0500 Subject: [PATCH 17/26] SNICommon => SniCommon --- .../src/Microsoft.Data.SqlClient.csproj | 4 +-- .../SqlClient/TdsParserStateObjectManaged.cs | 2 +- .../ManagedSni/LocalDB.netcore.Windows.cs | 20 ++++++------- .../Data/SqlClient/ManagedSni/SSRP.netcore.cs | 4 +-- ...Common.netcore.cs => SniCommon.netcore.cs} | 28 +++++++++---------- .../ManagedSni/SniMarsConnection.netcore.cs | 6 ++-- .../ManagedSni/SniMarsHandle.netcore.cs | 8 +++--- .../ManagedSni/SniNpHandle.netcore.cs | 16 +++++------ .../SqlClient/ManagedSni/SniPacket.netcore.cs | 6 ++-- .../SqlClient/ManagedSni/SniProxy.netcore.cs | 14 +++++----- .../ManagedSni/SniTcpHandle.netcore.cs | 18 ++++++------ 11 files changed, 63 insertions(+), 63 deletions(-) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/{SNICommon.netcore.cs => SniCommon.netcore.cs} (93%) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index 9bea583e63..9aedee9e72 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -281,8 +281,8 @@ Microsoft\Data\SqlClient\ManagedSni\SniError.netcore.cs - - Microsoft\Data\SqlClient\ManagedSni\SNICommon.netcore.cs + + Microsoft\Data\SqlClient\ManagedSni\SniCommon.netcore.cs Microsoft\Data\SqlClient\ManagedSni\SniHandle.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs index a44969e1bd..a403f8b556 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs @@ -376,7 +376,7 @@ internal override uint EnableSsl(ref uint info, bool tlsFirst, string serverCert catch (Exception e) { SqlClientEventSource.Log.TryTraceEvent("TdsParserStateObjectManaged.EnableSsl | Err | Session Id {0}, SNI Handshake failed with exception: {1}", sessionHandle.ConnectionId, e.Message); - return SNICommon.ReportSNIError(SniProviders.SSL_PROV, SNICommon.HandshakeFailureError, e); + return SniCommon.ReportSNIError(SniProviders.SSL_PROV, SniCommon.HandshakeFailureError, e); } } diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Windows.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Windows.cs index 3ea38d03e9..5813720ae1 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Windows.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Windows.cs @@ -54,7 +54,7 @@ private string GetConnectionString(string localDbInstance) int result = localDBStartInstanceFunc(localDbInstance, 0, localDBConnectionString, ref sizeOfbuffer); if (result != TdsEnums.SNI_SUCCESS) { - SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.INVALID_PROV, 0, SNICommon.LocalDBErrorCode, Strings.SNI_ERROR_50); + SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.INVALID_PROV, 0, SniCommon.LocalDBErrorCode, Strings.SNI_ERROR_50); SqlClientEventSource.Log.TrySNITraceEvent(nameof(LocalDB), EventType.ERR, "Unsuccessful 'LocalDBStartInstance' method call with {0} result to start '{1}' localDb instance", args0: result, args1: localDbInstance); localDBConnectionString = null; } @@ -71,17 +71,17 @@ internal static uint MapLocalDBErrorStateToCode(LocalDBErrorState errorState) switch (errorState) { case LocalDBErrorState.NO_INSTALLATION: - return SNICommon.LocalDBNoInstallation; + return SniCommon.LocalDBNoInstallation; case LocalDBErrorState.INVALID_CONFIG: - return SNICommon.LocalDBInvalidConfig; + return SniCommon.LocalDBInvalidConfig; case LocalDBErrorState.NO_SQLUSERINSTANCEDLL_PATH: - return SNICommon.LocalDBNoSqlUserInstanceDllPath; + return SniCommon.LocalDBNoSqlUserInstanceDllPath; case LocalDBErrorState.INVALID_SQLUSERINSTANCEDLL_PATH: - return SNICommon.LocalDBInvalidSqlUserInstanceDllPath; + return SniCommon.LocalDBInvalidSqlUserInstanceDllPath; case LocalDBErrorState.NONE: return 0; default: - return SNICommon.LocalDBInvalidConfig; + return SniCommon.LocalDBInvalidConfig; } } @@ -140,7 +140,7 @@ private bool LoadUserInstanceDll() // In case the registry had an empty path for dll if (string.IsNullOrWhiteSpace(dllPath)) { - SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.INVALID_PROV, 0, SNICommon.LocalDBInvalidSqlUserInstanceDllPath, Strings.SNI_ERROR_55); + SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.INVALID_PROV, 0, SniCommon.LocalDBInvalidSqlUserInstanceDllPath, Strings.SNI_ERROR_55); SqlClientEventSource.Log.TrySNITraceEvent(nameof(LocalDB), EventType.ERR, "User instance DLL path is invalid. DLL path = {0}", dllPath); return false; } @@ -150,7 +150,7 @@ private bool LoadUserInstanceDll() if (libraryHandle.IsInvalid) { - SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.INVALID_PROV, 0, SNICommon.LocalDBFailedToLoadDll, Strings.SNI_ERROR_56); + SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.INVALID_PROV, 0, SniCommon.LocalDBFailedToLoadDll, Strings.SNI_ERROR_56); SqlClientEventSource.Log.TrySNITraceEvent(nameof(LocalDB), EventType.ERR, "Library Handle is invalid. Could not load the dll."); libraryHandle.Dispose(); return false; @@ -161,7 +161,7 @@ private bool LoadUserInstanceDll() if (_startInstanceHandle == IntPtr.Zero) { - SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.INVALID_PROV, 0, SNICommon.LocalDBBadRuntime, Strings.SNI_ERROR_57); + SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.INVALID_PROV, 0, SniCommon.LocalDBBadRuntime, Strings.SNI_ERROR_57); SqlClientEventSource.Log.TrySNITraceEvent(nameof(LocalDB), EventType.ERR, "Was not able to load the PROC from DLL. Bad Runtime."); libraryHandle.Dispose(); return false; @@ -172,7 +172,7 @@ private bool LoadUserInstanceDll() if (localDBStartInstanceFunc == null) { - SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.INVALID_PROV, 0, SNICommon.LocalDBBadRuntime, Strings.SNI_ERROR_57); + SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.INVALID_PROV, 0, SniCommon.LocalDBBadRuntime, Strings.SNI_ERROR_57); libraryHandle.Dispose(); _startInstanceHandle = IntPtr.Zero; return false; diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SSRP.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SSRP.netcore.cs index b16df0d3cf..5af6389b0d 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SSRP.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SSRP.netcore.cs @@ -188,8 +188,8 @@ private static byte[] SendUDPRequest(string browserHostname, int port, byte[] re } IPAddress[] ipAddresses = timeout.IsInfinite - ? SNICommon.GetDnsIpAddresses(browserHostname) - : SNICommon.GetDnsIpAddresses(browserHostname, timeout); + ? SniCommon.GetDnsIpAddresses(browserHostname) + : SniCommon.GetDnsIpAddresses(browserHostname, timeout); Debug.Assert(ipAddresses.Length > 0, "DNS should throw if zero addresses resolve"); IPAddress[] ipv4Addresses = null; diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniCommon.netcore.cs similarity index 93% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniCommon.netcore.cs index 8bc48cd353..1e7758c4f3 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNICommon.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniCommon.netcore.cs @@ -13,7 +13,7 @@ namespace Microsoft.Data.SqlClient.ManagedSni { - internal class SNICommon + internal class SniCommon { // Each error number maps to SNI_ERROR_* in String.resx internal const int ConnTerminatedError = 2; @@ -54,11 +54,11 @@ internal class SNICommon /// True if certificate is valid internal static bool ValidateSslServerCertificate(Guid connectionId, string targetServerName, string hostNameInCertificate, X509Certificate serverCert, string validationCertFileName, SslPolicyErrors policyErrors) { - using (TrySNIEventScope.Create(nameof(SNICommon))) + using (TrySNIEventScope.Create(nameof(SniCommon))) { if (policyErrors == SslPolicyErrors.None) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNICommon), EventType.INFO, "Connection Id {0}, targetServerName {1}, SSL Server certificate not validated as PolicyErrors set to None.", args0: connectionId, args1: targetServerName); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniCommon), EventType.INFO, "Connection Id {0}, targetServerName {1}, SSL Server certificate not validated as PolicyErrors set to None.", args0: connectionId, args1: targetServerName); return true; } @@ -94,12 +94,12 @@ internal static bool ValidateSslServerCertificate(Guid connectionId, string targ { if (serverCert.GetRawCertData().AsSpan().SequenceEqual(validationCertificate.GetRawCertData().AsSpan())) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNICommon), EventType.INFO, "Connection Id {0}, ServerCertificate matches the certificate provided by the server. Certificate validation passed.", args0: connectionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniCommon), EventType.INFO, "Connection Id {0}, ServerCertificate matches the certificate provided by the server. Certificate validation passed.", args0: connectionId); return true; } else { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNICommon), EventType.INFO, "Connection Id {0}, ServerCertificate doesn't match the certificate provided by the server. Certificate validation failed.", args0: connectionId); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniCommon), EventType.INFO, "Connection Id {0}, ServerCertificate doesn't match the certificate provided by the server. Certificate validation failed.", args0: connectionId); throw ADP.SSLCertificateAuthenticationException(Strings.SQL_RemoteCertificateDoesNotMatchServerCertificate); } } @@ -109,13 +109,13 @@ internal static bool ValidateSslServerCertificate(Guid connectionId, string targ StringBuilder messageBuilder = new(); if (policyErrors.HasFlag(SslPolicyErrors.RemoteCertificateNotAvailable)) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNICommon), EventType.ERR, "Connection Id {0}, targetServerName {1}, SSL Server certificate not validated as PolicyErrors set to RemoteCertificateNotAvailable.", args0: connectionId, args1: targetServerName); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniCommon), EventType.ERR, "Connection Id {0}, targetServerName {1}, SSL Server certificate not validated as PolicyErrors set to RemoteCertificateNotAvailable.", args0: connectionId, args1: targetServerName); messageBuilder.AppendLine(Strings.SQL_RemoteCertificateNotAvailable); } if (policyErrors.HasFlag(SslPolicyErrors.RemoteCertificateChainErrors)) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNICommon), EventType.ERR, "Connection Id {0}, targetServerName {0}, SslPolicyError {1}, SSL Policy certificate chain has errors.", args0: connectionId, args1: targetServerName, args2: policyErrors); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniCommon), EventType.ERR, "Connection Id {0}, targetServerName {0}, SslPolicyError {1}, SSL Policy certificate chain has errors.", args0: connectionId, args1: targetServerName, args2: policyErrors); // get the chain status from the certificate X509Certificate2 cert2 = serverCert as X509Certificate2; @@ -132,7 +132,7 @@ internal static bool ValidateSslServerCertificate(Guid connectionId, string targ chainStatusInformation.AppendLine(); } } - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNICommon), EventType.ERR, "Connection Id {0}, targetServerName {1}, SslPolicyError {2}, SSL Policy certificate chain has errors. ChainStatus {3}", args0: connectionId, args1: targetServerName, args2: policyErrors, args3: chainStatusInformation); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniCommon), EventType.ERR, "Connection Id {0}, targetServerName {1}, SslPolicyError {2}, SSL Policy certificate chain has errors. ChainStatus {3}", args0: connectionId, args1: targetServerName, args2: policyErrors, args3: chainStatusInformation); messageBuilder.AppendFormat(Strings.SQL_RemoteCertificateChainErrors, chainStatusInformation); messageBuilder.AppendLine(); } @@ -142,7 +142,7 @@ internal static bool ValidateSslServerCertificate(Guid connectionId, string targ X509Certificate2 cert2 = serverCert as X509Certificate2; if (!cert2.MatchesHostname(serverNameToValidate)) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNICommon), EventType.ERR, "Connection Id {0}, serverNameToValidate {1}, Target Server name or HNIC does not match the Subject/SAN in Certificate.", args0: connectionId, args1: serverNameToValidate); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniCommon), EventType.ERR, "Connection Id {0}, serverNameToValidate {1}, Target Server name or HNIC does not match the Subject/SAN in Certificate.", args0: connectionId, args1: serverNameToValidate); messageBuilder.AppendLine(Strings.SQL_RemoteCertificateNameMismatch); } } @@ -153,7 +153,7 @@ internal static bool ValidateSslServerCertificate(Guid connectionId, string targ } } - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNICommon), EventType.INFO, "Connection Id {0}, certificate with subject: {1}, validated successfully.", args0: connectionId, args1: serverCert.Subject); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniCommon), EventType.INFO, "Connection Id {0}, certificate with subject: {1}, validated successfully.", args0: connectionId, args1: serverCert.Subject); return true; } } @@ -172,9 +172,9 @@ internal static IPAddress[] GetDnsIpAddresses(string serverName, TimeoutTimer ti internal static IPAddress[] GetDnsIpAddresses(string serverName) { - using (TrySNIEventScope.Create(nameof(SNICommon))) + using (TrySNIEventScope.Create(nameof(SniCommon))) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNICommon), EventType.INFO, "Getting DNS host entries for serverName {0}.", args0: serverName); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniCommon), EventType.INFO, "Getting DNS host entries for serverName {0}.", args0: serverName); return Dns.GetHostAddresses(serverName); } } @@ -189,7 +189,7 @@ internal static IPAddress[] GetDnsIpAddresses(string serverName) /// internal static uint ReportSNIError(SniProviders provider, uint nativeError, uint sniError, string errorMessage) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNICommon), EventType.ERR, "Provider = {0}, native Error = {1}, SNI Error = {2}, Error Message = {3}", args0: provider, args1: nativeError, args2: sniError, args3: errorMessage); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniCommon), EventType.ERR, "Provider = {0}, native Error = {1}, SNI Error = {2}, Error Message = {3}", args0: provider, args1: nativeError, args2: sniError, args3: errorMessage); return ReportSNIError(new SniError(provider, nativeError, sniError, errorMessage)); } @@ -203,7 +203,7 @@ internal static uint ReportSNIError(SniProviders provider, uint nativeError, uin /// internal static uint ReportSNIError(SniProviders provider, uint sniError, Exception sniException, uint nativeErrorCode = 0) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNICommon), EventType.ERR, "Provider = {0}, SNI Error = {1}, Exception = {2}", args0: provider, args1: sniError, args2: sniException?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniCommon), EventType.ERR, "Provider = {0}, SNI Error = {1}, Exception = {2}", args0: provider, args1: sniError, args2: sniException?.Message); return ReportSNIError(new SniError(provider, sniError, sniException, nativeErrorCode)); } diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsConnection.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsConnection.netcore.cs index 44ed0b5a30..63265dc07f 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsConnection.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsConnection.netcore.cs @@ -81,7 +81,7 @@ public uint StartReceive() return TdsEnums.SNI_SUCCESS_IO_PENDING; } SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsConnection), EventType.ERR, "MARS Session Id {0}, Connection not usable.", args0: ConnectionId); - return SNICommon.ReportSNIError(SniProviders.SMUX_PROV, 0, SNICommon.ConnNotUsableError, Strings.SNI_ERROR_19); + return SniCommon.ReportSNIError(SniProviders.SMUX_PROV, 0, SniCommon.ConnNotUsableError, Strings.SNI_ERROR_19); } } @@ -288,7 +288,7 @@ public void HandleReceiveComplete(SniPacket packet, uint sniErrorCode) if (!_sessions.ContainsKey(_currentHeader.sessionId)) { - SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.SMUX_PROV, 0, SNICommon.InvalidParameterError, Strings.SNI_ERROR_5); + SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.SMUX_PROV, 0, SniCommon.InvalidParameterError, Strings.SNI_ERROR_5); HandleReceiveError(packet); SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsConnection), EventType.ERR, "Current Header Session Id {0} not found, MARS Session Id {1} will be destroyed, New SNI error created: {2}", args0: _currentHeader?.sessionId, args1: _lowerHandle?.ConnectionId, args2: sniErrorCode); _lowerHandle.Dispose(); @@ -324,7 +324,7 @@ public void HandleReceiveComplete(SniPacket packet, uint sniErrorCode) catch (Exception e) { SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsConnection), EventType.ERR, "SMUX_ACK | MARS Session Id {0}, Exception occurred: {2}", args0: _currentHeader?.sessionId, args1: e?.Message); - SNICommon.ReportSNIError(SniProviders.SMUX_PROV, SNICommon.InternalExceptionError, e); + SniCommon.ReportSNIError(SniProviders.SMUX_PROV, SniCommon.InternalExceptionError, e); } #if DEBUG Debug.Assert(_currentPacket == currentPacket, "current and _current are not the same"); diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsHandle.netcore.cs index 697899b9a8..31778f3c39 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsHandle.netcore.cs @@ -64,7 +64,7 @@ public override void Dispose() catch (Exception e) { SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.ERR, "MARS Session Id {0}, Internal exception error = {1}, Member Name={2}", args0: ConnectionId, args1: e?.Message, args2: e?.GetType()?.Name); - SNICommon.ReportSNIError(SniProviders.SMUX_PROV, SNICommon.InternalExceptionError, e); + SniCommon.ReportSNIError(SniProviders.SMUX_PROV, SniCommon.InternalExceptionError, e); } } } @@ -297,7 +297,7 @@ public override uint ReceiveAsync(ref SniPacket packet) if (_connectionError != null) { SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.ERR, "MARS Session Id {0}, _asyncReceives {1}, _receiveHighwater {2}, _sendHighwater {3}, _receiveHighwaterLastAck {4}, _connectionError {5}", args0: ConnectionId, args1: _asyncReceives, args2: _receiveHighwater, args3: _sendHighwater, args4: _receiveHighwaterLastAck, args5: _connectionError); - return SNICommon.ReportSNIError(_connectionError); + return SniCommon.ReportSNIError(_connectionError); } if (queueCount == 0) @@ -482,7 +482,7 @@ public override uint Receive(out SniPacket packet, int timeoutInMilliseconds) if (_connectionError != null) { SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.ERR, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, _connectionError found: {3}.", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater, args3: _connectionError); - return SNICommon.ReportSNIError(_connectionError); + return SniCommon.ReportSNIError(_connectionError); } queueCount = _receivedPacketQueue.Count; @@ -517,7 +517,7 @@ public override uint Receive(out SniPacket packet, int timeoutInMilliseconds) SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, Waiting for packet event.", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater); if (!_packetEvent.Wait(timeoutInMilliseconds)) { - SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.SMUX_PROV, 0, SNICommon.ConnTimeoutError, Strings.SNI_ERROR_11); + SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.SMUX_PROV, 0, SniCommon.ConnTimeoutError, Strings.SNI_ERROR_11); SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, _sequenceNumber {1}, _sendHighwater {2}, _packetEvent wait timed out.", args0: ConnectionId, args1: _sequenceNumber, args2: _sendHighwater); return TdsEnums.SNI_WAIT_TIMEOUT; } diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs index 10c338ec0f..ac8a7f3ea7 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs @@ -82,14 +82,14 @@ public SniNpHandle(string serverName, string pipeName, TimeoutTimer timeout, boo } catch (TimeoutException te) { - SNICommon.ReportSNIError(SniProviders.NP_PROV, SNICommon.ConnOpenFailedError, te); + SniCommon.ReportSNIError(SniProviders.NP_PROV, SniCommon.ConnOpenFailedError, te); _status = TdsEnums.SNI_ERROR; SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.ERR, "Connection Id {0}, Connection Timed out. Error Code 1 Exception = {1}", args0: _connectionId, args1: te?.Message); return; } catch (IOException ioe) { - SNICommon.ReportSNIError(SniProviders.NP_PROV, SNICommon.ConnOpenFailedError, ioe); + SniCommon.ReportSNIError(SniProviders.NP_PROV, SniCommon.ConnOpenFailedError, ioe); _status = TdsEnums.SNI_ERROR; SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.ERR, "Connection Id {0}, IO Exception occurred. Error Code 1 Exception = {1}", args0: _connectionId, args1: ioe?.Message); return; @@ -97,7 +97,7 @@ public SniNpHandle(string serverName, string pipeName, TimeoutTimer timeout, boo if (!_pipeStream.IsConnected || !_pipeStream.CanWrite || !_pipeStream.CanRead) { - SNICommon.ReportSNIError(SniProviders.NP_PROV, 0, SNICommon.ConnOpenFailedError, Strings.SNI_ERROR_40); + SniCommon.ReportSNIError(SniProviders.NP_PROV, 0, SniCommon.ConnOpenFailedError, Strings.SNI_ERROR_40); _status = TdsEnums.SNI_ERROR; SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.ERR, "Connection Id {0}, Pipe Stream not operational. Error Code 1 Exception = {1}", args0: _connectionId, args1: Strings.SNI_ERROR_1); return; @@ -347,12 +347,12 @@ public override uint EnableSsl(uint options) catch (AuthenticationException aue) { SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.ERR, "Connection Id {0}, AuthenticationException message = {1}.", args0: ConnectionId, args1: aue?.Message); - return SNICommon.ReportSNIError(SniProviders.NP_PROV, SNICommon.InternalExceptionError, aue); + return SniCommon.ReportSNIError(SniProviders.NP_PROV, SniCommon.InternalExceptionError, aue); } catch (InvalidOperationException ioe) { SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.ERR, "Connection Id {0}, InvalidOperationException message = {1}.", args0: ConnectionId, args1: ioe?.Message); - return SNICommon.ReportSNIError(SniProviders.NP_PROV, SNICommon.InternalExceptionError, ioe); + return SniCommon.ReportSNIError(SniProviders.NP_PROV, SniCommon.InternalExceptionError, ioe); } _stream = _sslStream; return TdsEnums.SNI_SUCCESS; @@ -388,7 +388,7 @@ private bool ValidateServerCertificate(object sender, X509Certificate serverCert } SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.INFO, "Connection Id {0}, Proceeding to SSL certificate validation.", args0: ConnectionId); - return SNICommon.ValidateSslServerCertificate(_connectionId, _targetServer, _hostNameInCertificate, serverCertificate, _serverCertificateFilename, policyErrors); + return SniCommon.ValidateSslServerCertificate(_connectionId, _targetServer, _hostNameInCertificate, serverCertificate, _serverCertificateFilename, policyErrors); } } @@ -408,7 +408,7 @@ private uint ReportErrorAndReleasePacket(SniPacket packet, Exception sniExceptio ReturnPacket(packet); } SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.INFO, "Connection Id {0}, Packet returned, error occurred: {1}", args0: ConnectionId, args1: sniException?.Message); - return SNICommon.ReportSNIError(SniProviders.NP_PROV, SNICommon.InternalExceptionError, sniException); + return SniCommon.ReportSNIError(SniProviders.NP_PROV, SniCommon.InternalExceptionError, sniException); } private uint ReportErrorAndReleasePacket(SniPacket packet, uint nativeError, uint sniError, string errorMessage) @@ -418,7 +418,7 @@ private uint ReportErrorAndReleasePacket(SniPacket packet, uint nativeError, uin ReturnPacket(packet); } SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniNpHandle), EventType.INFO, "Connection Id {0}, Packet returned, error occurred: {1}", args0: ConnectionId, args1: errorMessage); - return SNICommon.ReportSNIError(SniProviders.NP_PROV, nativeError, sniError, errorMessage); + return SniCommon.ReportSNIError(SniProviders.NP_PROV, nativeError, sniError, errorMessage); } #if DEBUG diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniPacket.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniPacket.netcore.cs index 98fd8438f9..aa9ae28817 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniPacket.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniPacket.netcore.cs @@ -284,7 +284,7 @@ private static void ReadFromStreamAsyncContinuation(Task task, object state Exception e = task.Exception?.InnerException; if (e != null) { - SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.TCP_PROV, SNICommon.InternalExceptionError, e); + SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.TCP_PROV, SniCommon.InternalExceptionError, e); #if DEBUG SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniPacket), EventType.ERR, "Connection Id {0}, Internal Exception occurred while reading data: {1}", args0: packet._owner?.ConnectionId, args1: e?.Message); #endif @@ -298,7 +298,7 @@ private static void ReadFromStreamAsyncContinuation(Task task, object state #endif if (packet._dataLength == 0) { - SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.TCP_PROV, 0, SNICommon.ConnTerminatedError, Strings.SNI_ERROR_2); + SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.TCP_PROV, 0, SniCommon.ConnTerminatedError, Strings.SNI_ERROR_2); #if DEBUG SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniPacket), EventType.ERR, "Connection Id {0}, No data read from stream, connection was terminated.", args0: packet._owner?.ConnectionId); #endif @@ -339,7 +339,7 @@ public async void WriteToStreamAsync(Stream stream, SniAsyncCallback callback, S } catch (Exception e) { - SniLoadHandle.SingletonInstance.LastError = new SniError(provider, SNICommon.InternalExceptionError, e); + SniLoadHandle.SingletonInstance.LastError = new SniError(provider, SniCommon.InternalExceptionError, e); #if DEBUG SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniPacket), EventType.ERR, "Connection Id {0}, Internal Exception occurred while writing data: {1}", args0: _owner?.ConnectionId, args1: e?.Message); #endif diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniProxy.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniProxy.netcore.cs index 84cd209e36..512fad3f61 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniProxy.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniProxy.netcore.cs @@ -104,7 +104,7 @@ internal static SniHandle CreateConnectionHandle( } catch (Exception e) { - SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.INVALID_PROV, SNICommon.ErrorSpnLookup, e); + SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.INVALID_PROV, SniCommon.ErrorSpnLookup, e); } } @@ -205,7 +205,7 @@ private static SniTcpHandle CreateTcpHandle( string hostName = details.ServerName; if (string.IsNullOrWhiteSpace(hostName)) { - SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.TCP_PROV, 0, SNICommon.InvalidConnStringError, Strings.SNI_ERROR_25); + SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.TCP_PROV, 0, SniCommon.InvalidConnStringError, Strings.SNI_ERROR_25); return null; } @@ -221,7 +221,7 @@ private static SniTcpHandle CreateTcpHandle( } catch (SocketException se) { - SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.TCP_PROV, SNICommon.ErrorLocatingServerInstance, se); + SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.TCP_PROV, SniCommon.ErrorLocatingServerInstance, se); return null; } } @@ -253,7 +253,7 @@ private static SniNpHandle CreateNpHandle(DataSource details, TimeoutTimer timeo if (parallel) { // Connecting to a SQL Server instance using the MultiSubnetFailover connection option is only supported when using the TCP protocol - SNICommon.ReportSNIError(SniProviders.NP_PROV, 0, SNICommon.MultiSubnetFailoverWithNonTcpProtocol, Strings.SNI_ERROR_49); + SniCommon.ReportSNIError(SniProviders.NP_PROV, 0, SniCommon.MultiSubnetFailoverWithNonTcpProtocol, Strings.SNI_ERROR_49); return null; } return new SniNpHandle(details.PipeHostName, details.PipeName, timeout, tlsFirst, hostNameInCertificate, serverCertificateFilename); @@ -439,7 +439,7 @@ internal static string GetLocalDBInstance(string dataSource, out bool error) } else if (index > 0) { - SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.INVALID_PROV, 0, SNICommon.ErrorLocatingServerInstance, Strings.SNI_ERROR_26); + SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.INVALID_PROV, 0, SniCommon.ErrorLocatingServerInstance, Strings.SNI_ERROR_26); SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniProxy), EventType.ERR, "Incompatible use of prefix with LocalDb: '{0}'", dataSource); error = true; } @@ -458,7 +458,7 @@ internal static string GetLocalDBInstance(string dataSource, out bool error) } else { - SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.INVALID_PROV, 0, SNICommon.LocalDBNoInstanceName, Strings.SNI_ERROR_51); + SniLoadHandle.SingletonInstance.LastError = new SniError(SniProviders.INVALID_PROV, 0, SniCommon.LocalDBNoInstanceName, Strings.SNI_ERROR_51); error = true; } } @@ -585,7 +585,7 @@ private bool InferConnectionDetails() private void ReportSNIError(SniProviders provider) { - SniLoadHandle.SingletonInstance.LastError = new SniError(provider, 0, SNICommon.InvalidConnStringError, Strings.SNI_ERROR_25); + SniLoadHandle.SingletonInstance.LastError = new SniError(provider, 0, SniCommon.InvalidConnStringError, Strings.SNI_ERROR_25); IsBadDataSource = true; } diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniTcpHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniTcpHandle.netcore.cs index 582661e2ca..38171cb034 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniTcpHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniTcpHandle.netcore.cs @@ -256,7 +256,7 @@ public SniTcpHandle( if (reportError) { SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.ERR, "Connection Id {0} could not be opened, exception occurred: {1}", args0: _connectionId, args1: Strings.SNI_ERROR_40); - ReportTcpSNIError(0, SNICommon.ConnOpenFailedError, Strings.SNI_ERROR_40); + ReportTcpSNIError(0, SniCommon.ConnOpenFailedError, Strings.SNI_ERROR_40); } SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.ERR, "Connection Id {0} Socket could not be opened.", args0: _connectionId); return; @@ -303,15 +303,15 @@ private Socket TryConnectParallel(string hostName, int port, TimeoutTimer timeou bool isInfiniteTimeOut = timeout.IsInfinite; IPAddress[] serverAddresses = isInfiniteTimeOut - ? SNICommon.GetDnsIpAddresses(hostName) - : SNICommon.GetDnsIpAddresses(hostName, timeout); + ? SniCommon.GetDnsIpAddresses(hostName) + : SniCommon.GetDnsIpAddresses(hostName, timeout); if (serverAddresses.Length > MaxParallelIpAddresses) { // Fail if above 64 to match legacy behavior callerReportError = false; SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.ERR, "Connection Id {0} serverAddresses.Length {1} Exception: {2}", args0: _connectionId, args1: serverAddresses.Length, args2: Strings.SNI_ERROR_47); - ReportTcpSNIError(0, SNICommon.MultiSubnetFailoverWithMoreThan64IPs, Strings.SNI_ERROR_47); + ReportTcpSNIError(0, SniCommon.MultiSubnetFailoverWithMoreThan64IPs, Strings.SNI_ERROR_47); return availableSocket; } @@ -735,7 +735,7 @@ private bool ValidateServerCertificate(object sender, X509Certificate serverCert } SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.INFO, "Connection Id {0}, Certificate will be validated for Target Server name", args0: _connectionId); - return SNICommon.ValidateSslServerCertificate(_connectionId, _targetServer, _hostNameInCertificate, serverCertificate, _serverCertificateFilename, policyErrors); + return SniCommon.ValidateSslServerCertificate(_connectionId, _targetServer, _hostNameInCertificate, serverCertificate, _serverCertificateFilename, policyErrors); } /// @@ -829,7 +829,7 @@ public override uint Receive(out SniPacket packet, int timeoutInMilliseconds) if (_socket == null) { SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.ERR, "Connection Id {0}, Socket is null.", args0: _connectionId); - return ReportTcpSNIError(0, SNICommon.ConnOpenFailedError, Strings.SNI_ERROR_10); + return ReportTcpSNIError(0, SniCommon.ConnOpenFailedError, Strings.SNI_ERROR_10); } try @@ -846,7 +846,7 @@ public override uint Receive(out SniPacket packet, int timeoutInMilliseconds) { // otherwise it is timeout for 0 or less than -1 SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.ERR, "Connection Id {0}, Error 258, Timeout error occurred.", args0: _connectionId); - ReportTcpSNIError(0, SNICommon.ConnTimeoutError, Strings.SNI_ERROR_11); + ReportTcpSNIError(0, SniCommon.ConnTimeoutError, Strings.SNI_ERROR_11); return TdsEnums.SNI_WAIT_TIMEOUT; } @@ -993,13 +993,13 @@ public override uint CheckConnection() private uint ReportTcpSNIError(Exception sniException, uint nativeErrorCode = 0) { _status = TdsEnums.SNI_ERROR; - return SNICommon.ReportSNIError(SniProviders.TCP_PROV, SNICommon.InternalExceptionError, sniException, nativeErrorCode); + return SniCommon.ReportSNIError(SniProviders.TCP_PROV, SniCommon.InternalExceptionError, sniException, nativeErrorCode); } private uint ReportTcpSNIError(uint nativeError, uint sniError, string errorMessage) { _status = TdsEnums.SNI_ERROR; - return SNICommon.ReportSNIError(SniProviders.TCP_PROV, nativeError, sniError, errorMessage); + return SniCommon.ReportSNIError(SniProviders.TCP_PROV, nativeError, sniError, errorMessage); } private uint ReportErrorAndReleasePacket(SniPacket packet, Exception sniException) From d7e2be401f7687a5fc7f8dc0809f8ac4219a6a38 Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Tue, 13 May 2025 13:29:21 -0500 Subject: [PATCH 18/26] Extract SniSslStream to its own file --- .../src/Microsoft.Data.SqlClient.csproj | 3 ++ .../SNIStreams.ValueTask.netcore.cs | 10 +++---- .../ManagedSni/SNIStreams.netcore.cs | 16 ----------- .../ManagedSni/SniNpHandle.netcore.cs | 2 +- .../ManagedSni/SniSslStream.netcore.cs | 28 +++++++++++++++++++ .../ManagedSni/SniTcpHandle.netcore.cs | 2 +- 6 files changed, 38 insertions(+), 23 deletions(-) create mode 100644 src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniSslStream.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index 9aedee9e72..1439cf64aa 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -317,6 +317,9 @@ Microsoft\Data\SqlClient\ManagedSni\SniSmuxHeader.netcore.cs + + Microsoft\Data\SqlClient\ManagedSni\SniSslStream.netcore.cs + Microsoft\Data\SqlClient\ManagedSni\SNIStream.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.ValueTask.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.ValueTask.netcore.cs index 34d6c034cf..d2b68136cb 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.ValueTask.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.ValueTask.netcore.cs @@ -8,7 +8,7 @@ namespace Microsoft.Data.SqlClient.ManagedSni { - internal sealed partial class SNISslStream + internal sealed partial class SniSslStream { public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { @@ -24,7 +24,7 @@ public override async ValueTask ReadAsync(Memory buffer, Cancellation } catch (Exception e) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNISslStream), EventType.ERR, "Internal Exception occurred while reading data: {0}", args0: e?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniSslStream), EventType.ERR, "Internal Exception occurred while reading data: {0}", args0: e?.Message); throw; } finally @@ -47,7 +47,7 @@ public override async ValueTask WriteAsync(ReadOnlyMemory buffer, Cancella } catch (Exception e) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNISslStream), EventType.ERR, "Internal Exception occurred while reading data: {0}", args0: e?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniSslStream), EventType.ERR, "Internal Exception occurred while reading data: {0}", args0: e?.Message); throw; } finally @@ -73,7 +73,7 @@ public override async ValueTask ReadAsync(Memory buffer, Cancellation } catch (Exception e) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNISslStream), EventType.ERR, "Internal Exception occurred while reading data: {0}", args0: e?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniSslStream), EventType.ERR, "Internal Exception occurred while reading data: {0}", args0: e?.Message); throw; } finally @@ -97,7 +97,7 @@ public override async ValueTask WriteAsync(ReadOnlyMemory buffer, Cancella } catch (Exception e) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNISslStream), EventType.ERR, "Internal Exception occurred while reading data: {0}", args0: e?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniSslStream), EventType.ERR, "Internal Exception occurred while reading data: {0}", args0: e?.Message); throw; } finally diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.netcore.cs index 1e7509682d..f8ab0f9ce9 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.netcore.cs @@ -8,22 +8,6 @@ namespace Microsoft.Data.SqlClient.ManagedSni { - /// - /// This class extends SslStream to customize stream behavior for Managed SNI implementation. - /// - internal sealed partial class SNISslStream : SslStream - { - private readonly ConcurrentQueueSemaphore _writeAsyncSemaphore; - private readonly ConcurrentQueueSemaphore _readAsyncSemaphore; - - public SNISslStream(Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback) - : base(innerStream, leaveInnerStreamOpen, userCertificateValidationCallback) - { - _writeAsyncSemaphore = new ConcurrentQueueSemaphore(1); - _readAsyncSemaphore = new ConcurrentQueueSemaphore(1); - } - } - /// /// This class extends NetworkStream to customize stream behavior for Managed SNI implementation. /// diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs index ac8a7f3ea7..cd46918f23 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs @@ -110,7 +110,7 @@ public SniNpHandle(string serverName, string pipeName, TimeoutTimer timeout, boo _sslOverTdsStream = new SslOverTdsStream(_pipeStream, _connectionId); stream = _sslOverTdsStream; } - _sslStream = new SNISslStream(stream, true, new RemoteCertificateValidationCallback(ValidateServerCertificate)); + _sslStream = new SniSslStream(stream, true, new RemoteCertificateValidationCallback(ValidateServerCertificate)); _stream = _pipeStream; _status = TdsEnums.SNI_SUCCESS; diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniSslStream.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniSslStream.netcore.cs new file mode 100644 index 0000000000..86572aa4e3 --- /dev/null +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniSslStream.netcore.cs @@ -0,0 +1,28 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.IO; +using System.Net.Security; + +namespace Microsoft.Data.SqlClient.ManagedSni +{ + /// + /// This class extends SslStream to customize stream behavior for Managed SNI implementation. + /// + internal sealed partial class SniSslStream : SslStream + { + private readonly ConcurrentQueueSemaphore _writeAsyncSemaphore; + private readonly ConcurrentQueueSemaphore _readAsyncSemaphore; + + public SniSslStream( + Stream innerStream, + bool leaveInnerStreamOpen, + RemoteCertificateValidationCallback userCertificateValidationCallback) + : base(innerStream, leaveInnerStreamOpen, userCertificateValidationCallback) + { + _writeAsyncSemaphore = new ConcurrentQueueSemaphore(1); + _readAsyncSemaphore = new ConcurrentQueueSemaphore(1); + } + } +} diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniTcpHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniTcpHandle.netcore.cs index 38171cb034..5a2b429c8f 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniTcpHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniTcpHandle.netcore.cs @@ -271,7 +271,7 @@ public SniTcpHandle( _sslOverTdsStream = new SslOverTdsStream(_tcpStream, _connectionId); stream = _sslOverTdsStream; } - _sslStream = new SNISslStream(stream, true, new RemoteCertificateValidationCallback(ValidateServerCertificate)); + _sslStream = new SniSslStream(stream, true, new RemoteCertificateValidationCallback(ValidateServerCertificate)); } catch (SocketException se) { From 2ae42d18a818692042925d987317be723121f4e5 Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Tue, 13 May 2025 13:32:59 -0500 Subject: [PATCH 19/26] Extract SniNetworkStream to its own file, delete SniStreams file --- .../netcore/src/Microsoft.Data.SqlClient.csproj | 6 +++--- .../SqlClient/ManagedSni/SNIStreams.ValueTask.netcore.cs | 2 +- ...{SNIStreams.netcore.cs => SniNetworkStream.netcore.cs} | 8 +++----- .../Data/SqlClient/ManagedSni/SniTcpHandle.netcore.cs | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/{SNIStreams.netcore.cs => SniNetworkStream.netcore.cs} (74%) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index 1439cf64aa..044f79d10f 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -296,6 +296,9 @@ Microsoft\Data\SqlClient\ManagedSni\SniMarsHandle.netcore.cs + + Microsoft\Data\SqlClient\ManagedSni\SniNetworkStream.netcore.cs + Microsoft\Data\SqlClient\ManagedSni\SniNpHandle.netcore.cs @@ -320,9 +323,6 @@ Microsoft\Data\SqlClient\ManagedSni\SniSslStream.netcore.cs - - Microsoft\Data\SqlClient\ManagedSni\SNIStream.netcore.cs - Microsoft\Data\SqlClient\ManagedSni\SNIStreams.ValueTask.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.ValueTask.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.ValueTask.netcore.cs index d2b68136cb..ca69d61170 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.ValueTask.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.ValueTask.netcore.cs @@ -57,7 +57,7 @@ public override async ValueTask WriteAsync(ReadOnlyMemory buffer, Cancella } } - internal sealed partial class SNINetworkStream + internal sealed partial class SniNetworkStream { public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNetworkStream.netcore.cs similarity index 74% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.netcore.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNetworkStream.netcore.cs index f8ab0f9ce9..24e4b78e16 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNetworkStream.netcore.cs @@ -1,9 +1,7 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Net.Security; -using System.IO; using System.Net.Sockets; namespace Microsoft.Data.SqlClient.ManagedSni @@ -11,12 +9,12 @@ namespace Microsoft.Data.SqlClient.ManagedSni /// /// This class extends NetworkStream to customize stream behavior for Managed SNI implementation. /// - internal sealed partial class SNINetworkStream : NetworkStream + internal sealed partial class SniNetworkStream : NetworkStream { private readonly ConcurrentQueueSemaphore _writeAsyncSemaphore; private readonly ConcurrentQueueSemaphore _readAsyncSemaphore; - public SNINetworkStream(Socket socket, bool ownsSocket) : base(socket, ownsSocket) + public SniNetworkStream(Socket socket, bool ownsSocket) : base(socket, ownsSocket) { _writeAsyncSemaphore = new ConcurrentQueueSemaphore(1); _readAsyncSemaphore = new ConcurrentQueueSemaphore(1); diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniTcpHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniTcpHandle.netcore.cs index 5a2b429c8f..3e5b88e332 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniTcpHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniTcpHandle.netcore.cs @@ -263,7 +263,7 @@ public SniTcpHandle( } _socket.NoDelay = true; - _tcpStream = new SNINetworkStream(_socket, true); + _tcpStream = new SniNetworkStream(_socket, true); Stream stream = _tcpStream; if (!_tlsFirst) From a06eff14ea60a702bde302affcc7907f96c426f9 Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Tue, 13 May 2025 13:37:28 -0500 Subject: [PATCH 20/26] Merge value task partial into the appropriate stream classes --- .../src/Microsoft.Data.SqlClient.csproj | 3 - .../SNIStreams.ValueTask.netcore.cs | 109 ------------------ .../ManagedSni/SniNetworkStream.netcore.cs | 50 ++++++++ .../ManagedSni/SniSslStream.netcore.cs | 49 ++++++++ 4 files changed, 99 insertions(+), 112 deletions(-) delete mode 100644 src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.ValueTask.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index 044f79d10f..59fe66a2bb 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -323,9 +323,6 @@ Microsoft\Data\SqlClient\ManagedSni\SniSslStream.netcore.cs - - Microsoft\Data\SqlClient\ManagedSni\SNIStreams.ValueTask.netcore.cs - Microsoft\Data\SqlClient\ManagedSni\SniTcpHandle.netcore.cs diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.ValueTask.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.ValueTask.netcore.cs deleted file mode 100644 index ca69d61170..0000000000 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SNIStreams.ValueTask.netcore.cs +++ /dev/null @@ -1,109 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System.Threading; -using System.Threading.Tasks; -using System; - -namespace Microsoft.Data.SqlClient.ManagedSni -{ - internal sealed partial class SniSslStream - { - public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) - { - return ReadAsync(new Memory(buffer, offset, count), cancellationToken).AsTask(); - } - - public override async ValueTask ReadAsync(Memory buffer, CancellationToken cancellationToken = default) - { - await _readAsyncSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false); - try - { - return await base.ReadAsync(buffer, cancellationToken).ConfigureAwait(false); - } - catch (Exception e) - { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniSslStream), EventType.ERR, "Internal Exception occurred while reading data: {0}", args0: e?.Message); - throw; - } - finally - { - _readAsyncSemaphore.Release(); - } - } - - public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) - { - return WriteAsync(new Memory(buffer, offset, count), cancellationToken).AsTask(); - } - - public override async ValueTask WriteAsync(ReadOnlyMemory buffer, CancellationToken cancellationToken = default) - { - await _writeAsyncSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false); - try - { - await base.WriteAsync(buffer, cancellationToken).ConfigureAwait(false); - } - catch (Exception e) - { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniSslStream), EventType.ERR, "Internal Exception occurred while reading data: {0}", args0: e?.Message); - throw; - } - finally - { - _writeAsyncSemaphore.Release(); - } - } - } - - internal sealed partial class SniNetworkStream - { - public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) - { - return ReadAsync(new Memory(buffer, offset, count), cancellationToken).AsTask(); - } - - public override async ValueTask ReadAsync(Memory buffer, CancellationToken cancellationToken = default) - { - await _readAsyncSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false); - try - { - return await base.ReadAsync(buffer, cancellationToken).ConfigureAwait(false); - } - catch (Exception e) - { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniSslStream), EventType.ERR, "Internal Exception occurred while reading data: {0}", args0: e?.Message); - throw; - } - finally - { - _readAsyncSemaphore.Release(); - } - } - - // Prevent the WriteAsync collisions by running the task in a Semaphore Slim - public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) - { - return WriteAsync(new Memory(buffer, offset, count), cancellationToken).AsTask(); - } - - public override async ValueTask WriteAsync(ReadOnlyMemory buffer, CancellationToken cancellationToken = default) - { - await _writeAsyncSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false); - try - { - await base.WriteAsync(buffer, cancellationToken).ConfigureAwait(false); - } - catch (Exception e) - { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniSslStream), EventType.ERR, "Internal Exception occurred while reading data: {0}", args0: e?.Message); - throw; - } - finally - { - _writeAsyncSemaphore.Release(); - } - } - } -} diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNetworkStream.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNetworkStream.netcore.cs index 24e4b78e16..20e9552d6e 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNetworkStream.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNetworkStream.netcore.cs @@ -2,7 +2,10 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; using System.Net.Sockets; +using System.Threading; +using System.Threading.Tasks; namespace Microsoft.Data.SqlClient.ManagedSni { @@ -19,5 +22,52 @@ public SniNetworkStream(Socket socket, bool ownsSocket) : base(socket, ownsSocke _writeAsyncSemaphore = new ConcurrentQueueSemaphore(1); _readAsyncSemaphore = new ConcurrentQueueSemaphore(1); } + + public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + { + return ReadAsync(new Memory(buffer, offset, count), cancellationToken).AsTask(); + } + + public override async ValueTask ReadAsync(Memory buffer, CancellationToken cancellationToken = default) + { + await _readAsyncSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false); + try + { + return await base.ReadAsync(buffer, cancellationToken).ConfigureAwait(false); + } + catch (Exception e) + { + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniSslStream), EventType.ERR, "Internal Exception occurred while reading data: {0}", args0: e?.Message); + throw; + } + finally + { + _readAsyncSemaphore.Release(); + } + } + + // Prevent the WriteAsync collisions by running the task in a Semaphore Slim + public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + { + return WriteAsync(new Memory(buffer, offset, count), cancellationToken).AsTask(); + } + + public override async ValueTask WriteAsync(ReadOnlyMemory buffer, CancellationToken cancellationToken = default) + { + await _writeAsyncSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false); + try + { + await base.WriteAsync(buffer, cancellationToken).ConfigureAwait(false); + } + catch (Exception e) + { + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniSslStream), EventType.ERR, "Internal Exception occurred while reading data: {0}", args0: e?.Message); + throw; + } + finally + { + _writeAsyncSemaphore.Release(); + } + } } } diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniSslStream.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniSslStream.netcore.cs index 86572aa4e3..1387c534a1 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniSslStream.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniSslStream.netcore.cs @@ -2,8 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System; using System.IO; using System.Net.Security; +using System.Threading; +using System.Threading.Tasks; namespace Microsoft.Data.SqlClient.ManagedSni { @@ -24,5 +27,51 @@ public SniSslStream( _writeAsyncSemaphore = new ConcurrentQueueSemaphore(1); _readAsyncSemaphore = new ConcurrentQueueSemaphore(1); } + + public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + { + return ReadAsync(new Memory(buffer, offset, count), cancellationToken).AsTask(); + } + + public override async ValueTask ReadAsync(Memory buffer, CancellationToken cancellationToken = default) + { + await _readAsyncSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false); + try + { + return await base.ReadAsync(buffer, cancellationToken).ConfigureAwait(false); + } + catch (Exception e) + { + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniSslStream), EventType.ERR, "Internal Exception occurred while reading data: {0}", args0: e?.Message); + throw; + } + finally + { + _readAsyncSemaphore.Release(); + } + } + + public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) + { + return WriteAsync(new Memory(buffer, offset, count), cancellationToken).AsTask(); + } + + public override async ValueTask WriteAsync(ReadOnlyMemory buffer, CancellationToken cancellationToken = default) + { + await _writeAsyncSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false); + try + { + await base.WriteAsync(buffer, cancellationToken).ConfigureAwait(false); + } + catch (Exception e) + { + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniSslStream), EventType.ERR, "Internal Exception occurred while reading data: {0}", args0: e?.Message); + throw; + } + finally + { + _writeAsyncSemaphore.Release(); + } + } } } From b7928ab1bdb4a220d295331988e104d1df52dbee Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Tue, 13 May 2025 13:49:30 -0500 Subject: [PATCH 21/26] Wrap all files in #if NET --- .../ConcurrentQueueSemaphore.netcore.cs | 5 ++++- .../ManagedSni/LocalDB.netcore.Unix.cs | 4 ++++ .../ManagedSni/LocalDB.netcore.Windows.cs | 4 ++++ .../Data/SqlClient/ManagedSni/SSRP.netcore.cs | 4 ++++ .../ManagedSni/SniAsyncCallback.netcore.cs | 4 ++++ .../SqlClient/ManagedSni/SniCommon.netcore.cs | 4 ++++ .../SqlClient/ManagedSni/SniError.netcore.cs | 4 ++++ .../SqlClient/ManagedSni/SniHandle.netcore.cs | 9 +++++++-- .../ManagedSni/SniLoadHandle.netcore.cs | 4 ++++ .../ManagedSni/SniMarsConnection.netcore.cs | 8 ++++++-- .../ManagedSni/SniMarsHandle.netcore.cs | 8 ++++++-- .../ManagedSni/SniNetworkStream.netcore.cs | 6 +++++- .../ManagedSni/SniNpHandle.netcore.cs | 8 ++++++-- .../SqlClient/ManagedSni/SniPacket.netcore.cs | 3 +++ .../ManagedSni/SniPhysicalHandle.netcore.cs | 4 ++++ .../ManagedSni/SniProviders.netcore.cs | 4 ++++ .../SqlClient/ManagedSni/SniProxy.netcore.cs | 8 ++++++-- .../ManagedSni/SniSmuxFlags.netcore.cs | 4 ++++ .../ManagedSni/SniSmuxHeader.netcore.cs | 4 ++++ .../ManagedSni/SniSslStream.netcore.cs | 6 +++++- .../ManagedSni/SniTcpHandle.netcore.cs | 8 ++++++-- .../ManagedSni/SslOverTdsStream.NetCoreApp.cs | 20 +++++++++++-------- .../ManagedSni/SslOverTdsStream.netcore.cs | 4 ++++ 23 files changed, 114 insertions(+), 23 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/ConcurrentQueueSemaphore.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/ConcurrentQueueSemaphore.netcore.cs index 83f4dbeaa3..fff46abea6 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/ConcurrentQueueSemaphore.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/ConcurrentQueueSemaphore.netcore.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET + using System.Collections.Concurrent; using System.Threading; using System.Threading.Tasks; @@ -55,5 +57,6 @@ public void Release() _semaphore.Release(); } } - } + +#endif diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Unix.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Unix.cs index e151e0b57f..8ab05865a2 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Unix.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Unix.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET + using System; namespace Microsoft.Data.SqlClient.ManagedSni @@ -14,3 +16,5 @@ internal static string GetLocalDBConnectionString(string localDbInstance) } } } + +#endif diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Windows.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Windows.cs index 5813720ae1..bcea4a8404 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Windows.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/LocalDB.netcore.Windows.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET + using System; using System.Runtime.InteropServices; using System.Text; @@ -265,3 +267,5 @@ private string GetUserInstanceDllPath(out LocalDBErrorState errorState) } } } + +#endif diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SSRP.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SSRP.netcore.cs index 5af6389b0d..37130c1230 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SSRP.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SSRP.netcore.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET + using System; using System.Collections.Generic; using System.Diagnostics; @@ -462,3 +464,5 @@ private static void SplitIPv4AndIPv6(IPAddress[] input, out IPAddress[] ipv4Addr } } } + +#endif diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniAsyncCallback.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniAsyncCallback.netcore.cs index 47e80450c0..832d8bc1ce 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniAsyncCallback.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniAsyncCallback.netcore.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET + namespace Microsoft.Data.SqlClient.ManagedSni { /// @@ -11,3 +13,5 @@ namespace Microsoft.Data.SqlClient.ManagedSni /// SNI error code internal delegate void SniAsyncCallback(SniPacket packet, uint sniErrorCode); } + +#endif diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniCommon.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniCommon.netcore.cs index 1e7758c4f3..6aaf23f877 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniCommon.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniCommon.netcore.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET + using System; using System.Diagnostics; using System.Net; @@ -219,3 +221,5 @@ internal static uint ReportSNIError(SniError error) } } } + +#endif diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniError.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniError.netcore.cs index 1b7f9138c5..1a33de1d96 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniError.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniError.netcore.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET + using System; namespace Microsoft.Data.SqlClient.ManagedSni @@ -45,3 +47,5 @@ public SniError(SniProviders provider, uint sniErrorCode, Exception sniException } } } + +#endif diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniHandle.netcore.cs index 145cc0aef7..1f3ee01ab8 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniHandle.netcore.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET + using System; using System.Collections.Generic; using System.Net.Security; @@ -120,11 +122,14 @@ protected static void AuthenticateAsClient(SslStream sslStream, string serverNam /// Gets a value that indicates the security protocol used to authenticate this connection. /// public virtual int ProtocolVersion { get; } = 0; -#if DEBUG + + #if DEBUG /// /// Test handle for killing underlying connection /// public abstract void KillConnection(); -#endif + #endif } } + +#endif diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniLoadHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniLoadHandle.netcore.cs index c34d8462a9..5c0d85ba67 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniLoadHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniLoadHandle.netcore.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET + using System.Threading; namespace Microsoft.Data.SqlClient.ManagedSni @@ -63,3 +65,5 @@ public EncryptionOptions Options public bool ClientOSEncryptionSupport => true; } } + +#endif diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsConnection.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsConnection.netcore.cs index 63265dc07f..abc4bef0e9 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsConnection.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsConnection.netcore.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET + using System; using System.Collections.Generic; using System.Diagnostics; @@ -387,7 +389,7 @@ public void ReturnPacket(SniPacket packet) _lowerHandle.ReturnPacket(packet); } -#if DEBUG + #if DEBUG /// /// Test handle for killing underlying connection /// @@ -398,6 +400,8 @@ public void KillConnection() _lowerHandle.KillConnection(); } } -#endif + #endif } } + +#endif diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsHandle.netcore.cs index 31778f3c39..56e8d94ea6 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsHandle.netcore.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET + using System; using System.Collections.Generic; using System.Diagnostics; @@ -560,7 +562,7 @@ public override void SetBufferSize(int bufferSize) public override void ReturnPacket(SniPacket packet) => _connection.ReturnPacket(packet); -#if DEBUG + #if DEBUG /// /// Test handle for killing underlying connection /// @@ -568,6 +570,8 @@ public override void KillConnection() { _connection.KillConnection(); } -#endif + #endif } } + +#endif diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNetworkStream.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNetworkStream.netcore.cs index 20e9552d6e..f939ba4b7e 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNetworkStream.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNetworkStream.netcore.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET + using System; using System.Net.Sockets; using System.Threading; @@ -12,7 +14,7 @@ namespace Microsoft.Data.SqlClient.ManagedSni /// /// This class extends NetworkStream to customize stream behavior for Managed SNI implementation. /// - internal sealed partial class SniNetworkStream : NetworkStream + internal sealed class SniNetworkStream : NetworkStream { private readonly ConcurrentQueueSemaphore _writeAsyncSemaphore; private readonly ConcurrentQueueSemaphore _readAsyncSemaphore; @@ -71,3 +73,5 @@ public override async ValueTask WriteAsync(ReadOnlyMemory buffer, Cancella } } } + +#endif diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs index cd46918f23..e244209f23 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniNpHandle.netcore.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET + using System; using System.ComponentModel; using System.IO; @@ -421,7 +423,7 @@ private uint ReportErrorAndReleasePacket(SniPacket packet, uint nativeError, uin return SniCommon.ReportSNIError(SniProviders.NP_PROV, nativeError, sniError, errorMessage); } -#if DEBUG + #if DEBUG /// /// Test handle for killing underlying connection /// @@ -430,6 +432,8 @@ public override void KillConnection() _pipeStream.Dispose(); _pipeStream = null; } -#endif + #endif } } + +#endif diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniPacket.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniPacket.netcore.cs index aa9ae28817..5270513c05 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniPacket.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniPacket.netcore.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET // #define TRACE_HISTORY // this is used for advanced debugging when you need to trace the entire lifetime of a single packet, be very careful with it using System; @@ -349,3 +350,5 @@ public async void WriteToStreamAsync(Stream stream, SniAsyncCallback callback, S } } } + +#endif diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniPhysicalHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniPhysicalHandle.netcore.cs index 1334b07292..c45e7cce26 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniPhysicalHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniPhysicalHandle.netcore.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET + using System; using System.Collections.Generic; using System.Diagnostics; @@ -98,3 +100,5 @@ private string GetStackParts() #endif } } + +#endif diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniProviders.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniProviders.netcore.cs index 623e76c80b..2c040a11cf 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniProviders.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniProviders.netcore.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET + namespace Microsoft.Data.SqlClient.ManagedSni { /// @@ -24,3 +26,5 @@ internal enum SniProviders INVALID_PROV = 11 // SQL Network Interfaces } } + +#endif diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniProxy.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniProxy.netcore.cs index 512fad3f61..4659a4cf0a 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniProxy.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniProxy.netcore.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET + using System; using System.Diagnostics; using System.IO; @@ -702,7 +704,9 @@ private bool InferNamedPipesInformation() return false; } - private static bool IsLocalHost(string serverName) - => ".".Equals(serverName) || "(local)".Equals(serverName) || "localhost".Equals(serverName); + private static bool IsLocalHost(string serverName) => + ".".Equals(serverName) || "(local)".Equals(serverName) || "localhost".Equals(serverName); } } + +#endif diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniSmuxFlags.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniSmuxFlags.netcore.cs index 5611bcb7cb..feffee9113 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniSmuxFlags.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniSmuxFlags.netcore.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET + using System; namespace Microsoft.Data.SqlClient.ManagedSni @@ -34,3 +36,5 @@ internal enum SniSmuxFlags SMUX_DATA = 8 } } + +#endif diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniSmuxHeader.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniSmuxHeader.netcore.cs index 601a09741d..503d3905ae 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniSmuxHeader.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniSmuxHeader.netcore.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET + using System; using System.Buffers.Binary; @@ -63,3 +65,5 @@ public void Write(Span bytes) } } } + +#endif diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniSslStream.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniSslStream.netcore.cs index 1387c534a1..a7fc289d7f 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniSslStream.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniSslStream.netcore.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET + using System; using System.IO; using System.Net.Security; @@ -13,7 +15,7 @@ namespace Microsoft.Data.SqlClient.ManagedSni /// /// This class extends SslStream to customize stream behavior for Managed SNI implementation. /// - internal sealed partial class SniSslStream : SslStream + internal sealed class SniSslStream : SslStream { private readonly ConcurrentQueueSemaphore _writeAsyncSemaphore; private readonly ConcurrentQueueSemaphore _readAsyncSemaphore; @@ -75,3 +77,5 @@ public override async ValueTask WriteAsync(ReadOnlyMemory buffer, Cancella } } } + +#endif diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniTcpHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniTcpHandle.netcore.cs index 3e5b88e332..656060beeb 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniTcpHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniTcpHandle.netcore.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET + using System; using System.Collections.Generic; using System.ComponentModel; @@ -1020,7 +1022,7 @@ private uint ReportErrorAndReleasePacket(SniPacket packet, uint nativeError, uin return ReportTcpSNIError(nativeError, sniError, errorMessage); } -#if DEBUG + #if DEBUG /// /// Test handle for killing underlying connection /// @@ -1028,7 +1030,7 @@ public override void KillConnection() { _socket.Shutdown(SocketShutdown.Both); } -#endif + #endif internal static void SetKeepAliveValues(ref Socket socket) { @@ -1038,3 +1040,5 @@ internal static void SetKeepAliveValues(ref Socket socket) } } } + +#endif diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SslOverTdsStream.NetCoreApp.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SslOverTdsStream.NetCoreApp.cs index 078dc47f0a..ff3358c50a 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SslOverTdsStream.NetCoreApp.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SslOverTdsStream.NetCoreApp.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET + using System; using System.Buffers; using System.Threading; @@ -11,17 +13,17 @@ namespace Microsoft.Data.SqlClient.ManagedSni { internal sealed partial class SslOverTdsStream { - public override int Read(byte[] buffer, int offset, int count) - => Read(buffer.AsSpan(offset, count)); + public override int Read(byte[] buffer, int offset, int count) => + Read(buffer.AsSpan(offset, count)); - public override void Write(byte[] buffer, int offset, int count) - => Write(buffer.AsSpan(offset, count)); + public override void Write(byte[] buffer, int offset, int count) => + Write(buffer.AsSpan(offset, count)); - public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) - => ReadAsync(new Memory(buffer, offset, count), cancellationToken).AsTask(); + public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) => + ReadAsync(new Memory(buffer, offset, count), cancellationToken).AsTask(); - public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) - => WriteAsync(new ReadOnlyMemory(buffer, offset, count), cancellationToken).AsTask(); + public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) => + WriteAsync(new ReadOnlyMemory(buffer, offset, count), cancellationToken).AsTask(); public override int Read(Span buffer) { @@ -293,3 +295,5 @@ public override async ValueTask WriteAsync(ReadOnlyMemory buffer, Cancella } } } + +#endif diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SslOverTdsStream.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SslOverTdsStream.netcore.cs index 52393fa8ab..ae3dae0c06 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SslOverTdsStream.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SslOverTdsStream.netcore.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#if NET + using System; using System.IO; using System.IO.Pipes; @@ -123,3 +125,5 @@ private static void SetupPreLoginPacketHeader(byte[] buffer, int dataLength, int } } } + +#endif From 8fcf84092d89fc0e1360101d037abfbf2301defb Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Tue, 13 May 2025 13:50:33 -0500 Subject: [PATCH 22/26] SNISMUXHeader => SniSmuxHeader ... whoops --- .../ManagedSni/SniMarsConnection.netcore.cs | 14 ++++++------- .../ManagedSni/SniMarsHandle.netcore.cs | 20 +++++++++---------- .../ManagedSni/SniSmuxHeader.netcore.cs | 4 ++-- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsConnection.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsConnection.netcore.cs index abc4bef0e9..030dfb7452 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsConnection.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsConnection.netcore.cs @@ -19,7 +19,7 @@ internal class SniMarsConnection private readonly Guid _connectionId; private readonly Dictionary _sessions; private readonly byte[] _headerBytes; - private readonly SNISMUXHeader _currentHeader; + private readonly SniSmuxHeader _currentHeader; private readonly object _sync; private SniHandle _lowerHandle; private ushort _nextSessionId; @@ -45,8 +45,8 @@ public SniMarsConnection(SniHandle lowerHandle) _sync = new object(); _connectionId = Guid.NewGuid(); _sessions = new Dictionary(); - _headerBytes = new byte[SNISMUXHeader.HEADER_LENGTH]; - _currentHeader = new SNISMUXHeader(); + _headerBytes = new byte[SniSmuxHeader.HEADER_LENGTH]; + _currentHeader = new SniSmuxHeader(); _nextSessionId = 0; _currentHeaderByteCount = 0; _dataBytesLeft = 0; @@ -206,7 +206,7 @@ public void HandleReceiveComplete(SniPacket packet, uint sniErrorCode) { using (TrySNIEventScope.Create(nameof(SniMarsConnection))) { - SNISMUXHeader currentHeader = null; + SniSmuxHeader currentHeader = null; SniPacket currentPacket = null; SniMarsHandle currentSession = null; @@ -224,15 +224,15 @@ public void HandleReceiveComplete(SniPacket packet, uint sniErrorCode) { lock (DemuxerSync) { - if (_currentHeaderByteCount != SNISMUXHeader.HEADER_LENGTH) + if (_currentHeaderByteCount != SniSmuxHeader.HEADER_LENGTH) { currentHeader = null; currentPacket = null; currentSession = null; - while (_currentHeaderByteCount != SNISMUXHeader.HEADER_LENGTH) + while (_currentHeaderByteCount != SniSmuxHeader.HEADER_LENGTH) { - int bytesTaken = packet.TakeData(_headerBytes, _currentHeaderByteCount, SNISMUXHeader.HEADER_LENGTH - _currentHeaderByteCount); + int bytesTaken = packet.TakeData(_headerBytes, _currentHeaderByteCount, SniSmuxHeader.HEADER_LENGTH - _currentHeaderByteCount); _currentHeaderByteCount += bytesTaken; if (bytesTaken == 0) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsHandle.netcore.cs index 56e8d94ea6..ed69c242bf 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniMarsHandle.netcore.cs @@ -27,7 +27,7 @@ internal sealed class SniMarsHandle : SniHandle private readonly ushort _sessionId; private readonly ManualResetEventSlim _packetEvent = new ManualResetEventSlim(false); private readonly ManualResetEventSlim _ackEvent = new ManualResetEventSlim(false); - private readonly SNISMUXHeader _currentHeader = new SNISMUXHeader(); + private readonly SniSmuxHeader _currentHeader = new SniSmuxHeader(); private readonly SniAsyncCallback _handleSendCompleteCallback; private uint _sendHighwater = 4; @@ -47,7 +47,7 @@ internal sealed class SniMarsHandle : SniHandle /// public override uint Status => _status; - public override int ReserveHeaderSize => SNISMUXHeader.HEADER_LENGTH; + public override int ReserveHeaderSize => SniSmuxHeader.HEADER_LENGTH; public override int ProtocolVersion => _connection.ProtocolVersion; @@ -98,14 +98,14 @@ private void SendControlPacket(SniSmuxFlags flags) { using (TrySNIEventScope.Create(nameof(SniMarsHandle))) { - SniPacket packet = RentPacket(headerSize: SNISMUXHeader.HEADER_LENGTH, dataSize: 0); + SniPacket packet = RentPacket(headerSize: SniSmuxHeader.HEADER_LENGTH, dataSize: 0); #if DEBUG SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, Packet rented {1}, packet dataLeft {2}", args0: ConnectionId, args1: packet?._id, args2: packet?.DataLeft); #endif lock (this) { SetupSMUXHeader(0, flags); - _currentHeader.Write(packet.GetHeaderBuffer(SNISMUXHeader.HEADER_LENGTH)); + _currentHeader.Write(packet.GetHeaderBuffer(SniSmuxHeader.HEADER_LENGTH)); packet.SetHeaderActive(); } @@ -125,7 +125,7 @@ private void SetupSMUXHeader(int length, SniSmuxFlags flags) _currentHeader.SMID = 83; _currentHeader.flags = (byte)flags; _currentHeader.sessionId = _sessionId; - _currentHeader.length = (uint)SNISMUXHeader.HEADER_LENGTH + (uint)length; + _currentHeader.length = (uint)SniSmuxHeader.HEADER_LENGTH + (uint)length; _currentHeader.sequenceNumber = ((flags == SniSmuxFlags.SMUX_FIN) || (flags == SniSmuxFlags.SMUX_ACK)) ? _sequenceNumber - 1 : _sequenceNumber++; _currentHeader.highwater = _receiveHighwater; _receiveHighwaterLastAck = _currentHeader.highwater; @@ -138,10 +138,10 @@ private void SetupSMUXHeader(int length, SniSmuxFlags flags) /// The packet with the SMUx header set. private SniPacket SetPacketSMUXHeader(SniPacket packet) { - Debug.Assert(packet.ReservedHeaderSize == SNISMUXHeader.HEADER_LENGTH, "mars handle attempting to smux packet without smux reservation"); + Debug.Assert(packet.ReservedHeaderSize == SniSmuxHeader.HEADER_LENGTH, "mars handle attempting to smux packet without smux reservation"); SetupSMUXHeader(packet.Length, SniSmuxFlags.SMUX_DATA); - _currentHeader.Write(packet.GetHeaderBuffer(SNISMUXHeader.HEADER_LENGTH)); + _currentHeader.Write(packet.GetHeaderBuffer(SniSmuxHeader.HEADER_LENGTH)); packet.SetHeaderActive(); #if DEBUG SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniMarsHandle), EventType.INFO, "MARS Session Id {0}, Setting SMUX_DATA header in current header for packet {1}", args0: ConnectionId, args1: packet?._id); @@ -156,7 +156,7 @@ private SniPacket SetPacketSMUXHeader(SniPacket packet) /// SNI error code public override uint Send(SniPacket packet) { - Debug.Assert(packet.ReservedHeaderSize == SNISMUXHeader.HEADER_LENGTH, "mars handle attempting to send muxed packet without smux reservation in Send"); + Debug.Assert(packet.ReservedHeaderSize == SniSmuxHeader.HEADER_LENGTH, "mars handle attempting to send muxed packet without smux reservation in Send"); using (TrySNIEventScope.Create(nameof(SniMarsHandle))) { while (true) @@ -196,7 +196,7 @@ public override uint Send(SniPacket packet) /// SNI error code private uint InternalSendAsync(SniPacket packet) { - Debug.Assert(packet.ReservedHeaderSize == SNISMUXHeader.HEADER_LENGTH, "mars handle attempting to send muxed packet without smux reservation in InternalSendAsync"); + Debug.Assert(packet.ReservedHeaderSize == SniSmuxHeader.HEADER_LENGTH, "mars handle attempting to send muxed packet without smux reservation in InternalSendAsync"); using (TrySNIEventScope.Create(nameof(SniMarsHandle))) { lock (this) @@ -401,7 +401,7 @@ public void HandleAck(uint highwater) /// /// SNI packet /// SMUX header - public void HandleReceiveComplete(SniPacket packet, SNISMUXHeader header) + public void HandleReceiveComplete(SniPacket packet, SniSmuxHeader header) { using (TrySNIEventScope.Create(nameof(SniMarsHandle))) { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniSmuxHeader.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniSmuxHeader.netcore.cs index 503d3905ae..10bde29f7f 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniSmuxHeader.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniSmuxHeader.netcore.cs @@ -12,7 +12,7 @@ namespace Microsoft.Data.SqlClient.ManagedSni /// /// SMUX packet header /// - internal sealed class SNISMUXHeader + internal sealed class SniSmuxHeader { public const int HEADER_LENGTH = 16; @@ -29,7 +29,7 @@ public void Read(byte[] bytes) flags = bytes[1]; Span span = bytes.AsSpan(); sessionId = BinaryPrimitives.ReadUInt16LittleEndian(span.Slice(2)); - length = BinaryPrimitives.ReadUInt32LittleEndian(span.Slice(4)) - SNISMUXHeader.HEADER_LENGTH; + length = BinaryPrimitives.ReadUInt32LittleEndian(span.Slice(4)) - SniSmuxHeader.HEADER_LENGTH; sequenceNumber = BinaryPrimitives.ReadUInt32LittleEndian(span.Slice(8)); highwater = BinaryPrimitives.ReadUInt32LittleEndian(span.Slice(12)); } From 4d333f6612292367f833b6d00445954b3c222045 Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Mon, 19 May 2025 16:50:55 -0500 Subject: [PATCH 23/26] Rename SSRP to SsrpClient --- .../src/Microsoft.Data.SqlClient.csproj | 4 +-- .../SqlClient/ManagedSni/SniProxy.netcore.cs | 4 +-- ...{SSRP.netcore.cs => SsrpClient.netcore.cs} | 26 +++++++++---------- 3 files changed, 17 insertions(+), 17 deletions(-) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/{SSRP.netcore.cs => SsrpClient.netcore.cs} (96%) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index a2d30c8194..6ce4f4a60d 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -332,8 +332,8 @@ Microsoft\Data\SqlClient\ManagedSni\SslOverTdsStream.NetCoreApp.cs - - Microsoft\Data\SqlClient\ManagedSni\SSRP.netcore.cs + + Microsoft\Data\SqlClient\ManagedSni\SsrpClient.netcore.cs Microsoft\Data\SqlClient\NoneAttestationEnclaveProvider.cs diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniProxy.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniProxy.netcore.cs index 4659a4cf0a..c09e5a7b27 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniProxy.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniProxy.netcore.cs @@ -218,8 +218,8 @@ private static SniTcpHandle CreateTcpHandle( try { details.ResolvedPort = port = isAdminConnection ? - SSRP.GetDacPortByInstanceName(hostName, details.InstanceName, timeout, parallel, ipPreference) : - SSRP.GetPortByInstanceName(hostName, details.InstanceName, timeout, parallel, ipPreference); + SsrpClient.GetDacPortByInstanceName(hostName, details.InstanceName, timeout, parallel, ipPreference) : + SsrpClient.GetPortByInstanceName(hostName, details.InstanceName, timeout, parallel, ipPreference); } catch (SocketException se) { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SSRP.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SsrpClient.netcore.cs similarity index 96% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SSRP.netcore.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SsrpClient.netcore.cs index 37130c1230..1aebffefbe 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SSRP.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SsrpClient.netcore.cs @@ -16,7 +16,7 @@ namespace Microsoft.Data.SqlClient.ManagedSni { - internal sealed class SSRP + internal sealed class SsrpClient { private const char SemicolonSeparator = ';'; private const int SqlServerBrowserPort = 1434; //port SQL Server Browser @@ -40,7 +40,7 @@ internal static int GetPortByInstanceName(string browserHostName, string instanc { Debug.Assert(!string.IsNullOrWhiteSpace(browserHostName), "browserHostName should not be null, empty, or whitespace"); Debug.Assert(!string.IsNullOrWhiteSpace(instanceName), "instanceName should not be null, empty, or whitespace"); - using (TrySNIEventScope.Create(nameof(SSRP))) + using (TrySNIEventScope.Create(nameof(SsrpClient))) { byte[] instanceInfoRequest = CreateInstanceInfoRequest(instanceName); byte[] responsePacket = null; @@ -56,7 +56,7 @@ internal static int GetPortByInstanceName(string browserHostName, string instanc // the same error as if the response was empty. The higher error suits all scenarios. // But log it, just in case there is a different, underlying issue that support needs // to troubleshoot. - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SSRP), EventType.ERR, "SocketException Message = {0}", args0: se?.Message); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SsrpClient), EventType.ERR, "SocketException Message = {0}", args0: se?.Message); throw; } @@ -88,7 +88,7 @@ internal static int GetPortByInstanceName(string browserHostName, string instanc private static byte[] CreateInstanceInfoRequest(string instanceName) { Debug.Assert(!string.IsNullOrWhiteSpace(instanceName), "instanceName should not be null, empty, or whitespace"); - using (TrySNIEventScope.Create(nameof(SSRP))) + using (TrySNIEventScope.Create(nameof(SsrpClient))) { const byte ClntUcastInst = 0x04; instanceName += char.MinValue; @@ -172,7 +172,7 @@ private class SsrpResult /// response packet from UDP server private static byte[] SendUDPRequest(string browserHostname, int port, byte[] requestPacket, TimeoutTimer timeout, bool allIPsInParallel, SqlConnectionIPAddressPreference ipPreference) { - using (TrySNIEventScope.Create(nameof(SSRP))) + using (TrySNIEventScope.Create(nameof(SsrpClient))) { Debug.Assert(!string.IsNullOrWhiteSpace(browserHostname), "browserhostname should not be null, empty, or whitespace"); Debug.Assert(port >= 0 && port <= 65535, "Invalid port"); @@ -340,10 +340,10 @@ private static SsrpResult SendUDPRequest(IPEndPoint endPoint, byte[] requestPack Task sendTask = client.SendAsync(requestPacket, requestPacket.Length, endPoint); Task receiveTask = null; - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SSRP), EventType.INFO, "Waiting for UDP Client to fetch Port info."); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SsrpClient), EventType.INFO, "Waiting for UDP Client to fetch Port info."); if (sendTask.Wait(sendTimeOutMs) && (receiveTask = client.ReceiveAsync()).Wait(receiveTimeOutMs)) { - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SSRP), EventType.INFO, "Received Port info from UDP Client."); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SsrpClient), EventType.INFO, "Received Port info from UDP Client."); result.ResponsePacket = receiveTask.Result.Buffer; } } @@ -360,7 +360,7 @@ private static SsrpResult SendUDPRequest(IPEndPoint endPoint, byte[] requestPack { result.Error = e; } - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SSRP), EventType.INFO, + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SsrpClient), EventType.INFO, "SendUDPRequest ({0}) resulted in exception: {1}", args0: endPoint.ToString(), args1: e.Message); } @@ -370,14 +370,14 @@ private static SsrpResult SendUDPRequest(IPEndPoint endPoint, byte[] requestPack else { result.Error = ae; - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SSRP), EventType.INFO, + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SsrpClient), EventType.INFO, "SendUDPRequest ({0}) resulted in exception: {1}", args0: endPoint.ToString(), args1: ae.Message); } } catch (Exception e) { result.Error = e; - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SSRP), EventType.INFO, + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SsrpClient), EventType.INFO, "SendUDPRequest ({0}) resulted in exception: {1}", args0: endPoint.ToString(), args1: e.Message); } @@ -398,13 +398,13 @@ internal static string SendBroadcastUDPRequest() // https://docs.microsoft.com/en-us/openspecs/windows_protocols/mc-sqlr/f2640a2d-3beb-464b-a443-f635842ebc3e#Appendix_A_3 int currentTimeOut = FirstTimeoutForCLNT_BCAST_EX; - using (TrySNIEventScope.Create(nameof(SSRP))) + using (TrySNIEventScope.Create(nameof(SsrpClient))) { using (UdpClient clientListener = new UdpClient()) { Task sendTask = clientListener.SendAsync(CLNT_BCAST_EX_Request, CLNT_BCAST_EX_Request.Length, new IPEndPoint(IPAddress.Broadcast, SqlServerBrowserPort)); Task receiveTask = null; - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SSRP), EventType.INFO, "Waiting for UDP Client to fetch list of instances."); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SsrpClient), EventType.INFO, "Waiting for UDP Client to fetch list of instances."); Stopwatch sw = new Stopwatch(); //for waiting until 15 sec elapsed sw.Start(); try @@ -412,7 +412,7 @@ internal static string SendBroadcastUDPRequest() while ((receiveTask = clientListener.ReceiveAsync()).Wait(currentTimeOut) && sw.ElapsedMilliseconds <= ReceiveMAXTimeoutsForCLNT_BCAST_EX && receiveTask != null) { currentTimeOut = ReceiveTimeoutsForCLNT_BCAST_EX; - SqlClientEventSource.Log.TrySNITraceEvent(nameof(SSRP), EventType.INFO, "Received instnace info from UDP Client."); + SqlClientEventSource.Log.TrySNITraceEvent(nameof(SsrpClient), EventType.INFO, "Received instnace info from UDP Client."); if (receiveTask.Result.Buffer.Length < ValidResponseSizeForCLNT_BCAST_EX) //discard invalid response { response.Append(Encoding.ASCII.GetString(receiveTask.Result.Buffer, ServerResponseHeaderSizeForCLNT_BCAST_EX, receiveTask.Result.Buffer.Length - ServerResponseHeaderSizeForCLNT_BCAST_EX)); //RESP_DATA(VARIABLE) - 3 (RESP_SIZE + SVR_RESP) From 54c77ca2a7e4585afd1aded544232e84b74acee3 Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Mon, 19 May 2025 17:28:16 -0500 Subject: [PATCH 24/26] Change reflection references to SNI --- .../SQL/Common/InternalConnectionWrapper.cs | 2 +- .../TdsParserStateObjectHelper.cs | 31 ++++++++----------- .../SQL/InstanceNameTest/InstanceNameTest.cs | 6 ++-- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/Common/InternalConnectionWrapper.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/Common/InternalConnectionWrapper.cs index c9f054a882..4086c73265 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/Common/InternalConnectionWrapper.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/Common/InternalConnectionWrapper.cs @@ -128,7 +128,7 @@ public void KillConnection() object stateObject = TdsParserHelper.GetStateObject(tdsParser); Assembly assembly = Assembly.Load(new AssemblyName(typeof(SqlConnection).GetTypeInfo().Assembly.FullName)); - Type sniHandleType = assembly.GetType("Microsoft.Data.SqlClient.SNI.SNIHandle"); + Type sniHandleType = assembly.GetType("Microsoft.Data.SqlClient.ManagedSni.SniHandle"); MethodInfo killConn = null; if (sniHandleType is not null) diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/Common/SystemDataInternals/TdsParserStateObjectHelper.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/Common/SystemDataInternals/TdsParserStateObjectHelper.cs index 625f0e9d9b..9095046299 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/Common/SystemDataInternals/TdsParserStateObjectHelper.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/Common/SystemDataInternals/TdsParserStateObjectHelper.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using System.Diagnostics; using System.Reflection; using Xunit; @@ -16,8 +15,11 @@ internal static class TdsParserStateObjectHelper private static readonly FieldInfo s_forceSyncOverAsyncAfterFirstPend; private static readonly FieldInfo s_failAsyncPends; private static readonly FieldInfo s_forcePendingReadsToWaitForUser; + + #if NET private static readonly Type s_tdsParserStateObjectManaged; private static readonly FieldInfo s_tdsParserStateObjectManagedSessionHandle; + #endif static TdsParserStateObjectHelper() { @@ -42,23 +44,16 @@ static TdsParserStateObjectHelper() s_forcePendingReadsToWaitForUser = tdsParserStateObject.GetField("s_forcePendingReadsToWaitForUser", BindingFlags.Static | BindingFlags.NonPublic); Assert.True(s_forcePendingReadsToWaitForUser is not null, nameof(s_forcePendingReadsToWaitForUser)); - // These managed SNI handles are allowed to be null, since they - // won't exist in .NET Framework builds. - s_tdsParserStateObjectManaged = - assembly.GetType("Microsoft.Data.SqlClient.SNI.TdsParserStateObjectManaged"); - s_tdsParserStateObjectManagedSessionHandle = null; - if (s_tdsParserStateObjectManaged is not null) - { - s_tdsParserStateObjectManagedSessionHandle = - s_tdsParserStateObjectManaged.GetField( - "_sessionHandle", - BindingFlags.Instance | BindingFlags.NonPublic); - // If we have the managed SNI type, we must have the session - // handle field. - Assert.True( - s_tdsParserStateObjectManagedSessionHandle is not null, - nameof(s_tdsParserStateObjectManagedSessionHandle)); - } + #if NET + s_tdsParserStateObjectManaged = assembly.GetType( + "Microsoft.Data.SqlClient.ManagedSni.TdsParserStateObjectManaged"); + Assert.NotNull(s_tdsParserStateObjectManaged); + + s_tdsParserStateObjectManagedSessionHandle = s_tdsParserStateObjectManaged.GetField( + "_sessionHandle", + BindingFlags.Static | BindingFlags.NonPublic); + Assert.NotNull(s_tdsParserStateObjectManagedSessionHandle); + #endif } internal static bool ForceAllPends diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/InstanceNameTest/InstanceNameTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/InstanceNameTest/InstanceNameTest.cs index 9f6673332c..24e5a277af 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/InstanceNameTest/InstanceNameTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/InstanceNameTest/InstanceNameTest.cs @@ -160,9 +160,9 @@ private static string GetSPNInfo(string dataSource, string inInstanceName) { Assembly sqlConnectionAssembly = Assembly.GetAssembly(typeof(SqlConnection)); - Type sniProxyType = sqlConnectionAssembly.GetType("Microsoft.Data.SqlClient.SNI.SNIProxy"); - Type ssrpType = sqlConnectionAssembly.GetType("Microsoft.Data.SqlClient.SNI.SSRP"); - Type dataSourceType = sqlConnectionAssembly.GetType("Microsoft.Data.SqlClient.SNI.DataSource"); + Type sniProxyType = sqlConnectionAssembly.GetType("Microsoft.Data.SqlClient.ManagedSni.SniProxy"); + Type ssrpType = sqlConnectionAssembly.GetType("Microsoft.Data.SqlClient.ManagedSni.SsrpClient"); + Type dataSourceType = sqlConnectionAssembly.GetType("Microsoft.Data.SqlClient.ManagedSni.DataSource"); Type timeoutTimerType = sqlConnectionAssembly.GetType("Microsoft.Data.ProviderBase.TimeoutTimer"); Type[] dataSourceConstructorTypesArray = new Type[] { typeof(string) }; From ad28fa0efba48d208fff77c766ac222f1abe5c5b Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Tue, 20 May 2025 12:29:07 -0500 Subject: [PATCH 25/26] Fix release-only reference --- .../Data/SqlClient/ManagedSni/SniPhysicalHandle.netcore.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniPhysicalHandle.netcore.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniPhysicalHandle.netcore.cs index c45e7cce26..3ee2111e78 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniPhysicalHandle.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniPhysicalHandle.netcore.cs @@ -35,7 +35,7 @@ public override SniPacket RentPacket(int headerSize, int dataSize) int id = Interlocked.Increment(ref s_packetId); packet = new SniPacket(this, id); #else - packet = new SNIPacket(); + packet = new SniPacket(); #endif } #if DEBUG From 8cb8837f3d9bb9e70e7d45ff7962c8a95c4420c0 Mon Sep 17 00:00:00 2001 From: Ben Russell Date: Tue, 20 May 2025 17:12:33 -0500 Subject: [PATCH 26/26] I can't trust any changes I make to the test projects, so I'm just gonna roll back this change. --- .../TdsParserStateObjectHelper.cs | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/Common/SystemDataInternals/TdsParserStateObjectHelper.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/Common/SystemDataInternals/TdsParserStateObjectHelper.cs index 9095046299..dadbb5c58c 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/Common/SystemDataInternals/TdsParserStateObjectHelper.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/Common/SystemDataInternals/TdsParserStateObjectHelper.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using System.Diagnostics; using System.Reflection; using Xunit; @@ -15,11 +16,8 @@ internal static class TdsParserStateObjectHelper private static readonly FieldInfo s_forceSyncOverAsyncAfterFirstPend; private static readonly FieldInfo s_failAsyncPends; private static readonly FieldInfo s_forcePendingReadsToWaitForUser; - - #if NET private static readonly Type s_tdsParserStateObjectManaged; private static readonly FieldInfo s_tdsParserStateObjectManagedSessionHandle; - #endif static TdsParserStateObjectHelper() { @@ -44,16 +42,23 @@ static TdsParserStateObjectHelper() s_forcePendingReadsToWaitForUser = tdsParserStateObject.GetField("s_forcePendingReadsToWaitForUser", BindingFlags.Static | BindingFlags.NonPublic); Assert.True(s_forcePendingReadsToWaitForUser is not null, nameof(s_forcePendingReadsToWaitForUser)); - #if NET - s_tdsParserStateObjectManaged = assembly.GetType( - "Microsoft.Data.SqlClient.ManagedSni.TdsParserStateObjectManaged"); - Assert.NotNull(s_tdsParserStateObjectManaged); - - s_tdsParserStateObjectManagedSessionHandle = s_tdsParserStateObjectManaged.GetField( - "_sessionHandle", - BindingFlags.Static | BindingFlags.NonPublic); - Assert.NotNull(s_tdsParserStateObjectManagedSessionHandle); - #endif + // These managed SNI handles are allowed to be null, since they + // won't exist in .NET Framework builds. + s_tdsParserStateObjectManaged = + assembly.GetType("Microsoft.Data.SqlClient.ManagedSni.TdsParserStateObjectManaged"); + s_tdsParserStateObjectManagedSessionHandle = null; + if (s_tdsParserStateObjectManaged is not null) + { + s_tdsParserStateObjectManagedSessionHandle = + s_tdsParserStateObjectManaged.GetField( + "_sessionHandle", + BindingFlags.Instance | BindingFlags.NonPublic); + // If we have the managed SNI type, we must have the session + // handle field. + Assert.True( + s_tdsParserStateObjectManagedSessionHandle is not null, + nameof(s_tdsParserStateObjectManagedSessionHandle)); + } } internal static bool ForceAllPends @@ -96,7 +101,7 @@ internal static object GetSessionHandle(object stateObject) { throw new ArgumentException("Library being tested does not implement TdsParserStateObjectManaged", nameof(stateObject)); } - if (! s_tdsParserStateObjectManaged.IsInstanceOfType(stateObject)) + if (!s_tdsParserStateObjectManaged.IsInstanceOfType(stateObject)) { throw new ArgumentException("Object provided was not a TdsParserStateObjectManaged", nameof(stateObject)); }