5
5
using System ;
6
6
using System . Collections . Generic ;
7
7
using System . Diagnostics ;
8
+ using System . Runtime . CompilerServices ;
8
9
using System . Runtime . InteropServices ;
9
10
using System . Threading ;
11
+ #if NETFRAMEWORK
12
+ using Microsoft . Data . Common ;
13
+ #endif
10
14
11
15
namespace Microsoft . Data . SqlClient
12
16
{
@@ -23,7 +27,7 @@ internal sealed partial class SNILoadHandle : SafeHandle
23
27
24
28
private SNILoadHandle ( ) : base ( IntPtr . Zero , true )
25
29
{
26
- // From security review - SafeHandle guarantees this is only called once.
30
+ // SQL BU DT 346588 - from security review - SafeHandle guarantees this is only called once.
27
31
// The reason for the safehandle is guaranteed initialization and termination of SNI to
28
32
// ensure SNI terminates and cleans up properly.
29
33
try
@@ -49,7 +53,7 @@ public bool ClientOSEncryptionSupport
49
53
{
50
54
try
51
55
{
52
- UInt32 value = 0 ;
56
+ uint value = 0 ;
53
57
// Query OS to find out whether encryption is supported.
54
58
SNINativeMethodWrapper . SNIQueryInfo ( SNINativeMethodWrapper . QTypes . SNI_QUERY_CLIENT_ENCRYPT_POSSIBLE , ref value ) ;
55
59
_clientOSEncryptionSupport = value != 0 ;
@@ -101,7 +105,11 @@ private static void ReadDispatcher(IntPtr key, IntPtr packet, uint error)
101
105
102
106
if ( null != stateObj )
103
107
{
108
+ #if NETFRAMEWORK
109
+ stateObj . ReadAsyncCallback ( IntPtr . Zero , packet , error ) ;
110
+ #else
104
111
stateObj . ReadAsyncCallback ( IntPtr . Zero , PacketHandle . FromNativePointer ( packet ) , error ) ;
112
+ #endif // NETFRAMEWORK
105
113
}
106
114
}
107
115
}
@@ -122,7 +130,11 @@ private static void WriteDispatcher(IntPtr key, IntPtr packet, uint error)
122
130
123
131
if ( null != stateObj )
124
132
{
133
+ #if NETFRAMEWORK
134
+ stateObj . WriteAsyncCallback ( IntPtr . Zero , packet , error ) ;
135
+ #else
125
136
stateObj . WriteAsyncCallback ( IntPtr . Zero , PacketHandle . FromNativePointer ( packet ) , error ) ;
137
+ #endif // NETFRAMEWORK
126
138
}
127
139
}
128
140
}
@@ -144,12 +156,17 @@ internal SNIHandle(
144
156
bool flushCache ,
145
157
bool fSync ,
146
158
bool fParallel ,
159
+ #if NETFRAMEWORK
160
+ TransparentNetworkResolutionState transparentNetworkResolutionState ,
161
+ int totalTimeout ,
162
+ #endif
147
163
SqlConnectionIPAddressPreference ipPreference ,
148
164
SQLDNSInfo cachedDNSInfo ,
149
165
bool tlsFirst ,
150
166
string hostNameInCertificate )
151
167
: base ( IntPtr . Zero , true )
152
168
{
169
+ RuntimeHelpers . PrepareConstrainedRegions ( ) ;
153
170
try
154
171
{ }
155
172
finally
@@ -158,11 +175,21 @@ internal SNIHandle(
158
175
instanceName = new byte [ 256 ] ; // Size as specified by netlibs.
159
176
if ( ignoreSniOpenTimeout )
160
177
{
178
+ // UNDONE: ITEM12001110 (DB Mirroring Reconnect) Old behavior of not truly honoring timeout presevered
179
+ // for non-failover scenarios to avoid breaking changes as part of a QFE. Consider fixing timeout
180
+ // handling in next full release and removing ignoreSniOpenTimeout parameter.
161
181
timeout = Timeout . Infinite ; // -1 == native SNIOPEN_TIMEOUT_VALUE / INFINITE
162
182
}
163
183
164
- _status = SNINativeMethodWrapper . SNIOpenSyncEx ( myInfo , serverName , ref base . handle , spnBuffer , instanceName , flushCache ,
165
- fSync , timeout , fParallel , ipPreference , cachedDNSInfo , hostNameInCertificate ) ;
184
+ #if NETFRAMEWORK
185
+ int transparentNetworkResolutionStateNo = ( int ) transparentNetworkResolutionState ;
186
+ _status = SNINativeMethodWrapper . SNIOpenSyncEx ( myInfo , serverName , ref base . handle ,
187
+ spnBuffer , instanceName , flushCache , fSync , timeout , fParallel , transparentNetworkResolutionStateNo , totalTimeout ,
188
+ ADP . IsAzureSqlServerEndpoint ( serverName ) , ipPreference , cachedDNSInfo , hostNameInCertificate ) ;
189
+ #else
190
+ _status = SNINativeMethodWrapper . SNIOpenSyncEx ( myInfo , serverName , ref base . handle ,
191
+ spnBuffer , instanceName , flushCache , fSync , timeout , fParallel , ipPreference , cachedDNSInfo , hostNameInCertificate ) ;
192
+ #endif // NETFRAMEWORK
166
193
}
167
194
}
168
195
0 commit comments