@@ -170,7 +170,16 @@ private static byte[] SendUDPRequest(string browserHostname, int port, byte[] re
170
170
Debug . Assert ( port >= 0 && port <= 65535 , "Invalid port" ) ;
171
171
Debug . Assert ( requestPacket != null && requestPacket . Length > 0 , "requestPacket should not be null or 0-length array" ) ;
172
172
173
- bool isIpAddress = IPAddress . TryParse ( browserHostname , out IPAddress address ) ;
173
+ if ( IPAddress . TryParse ( browserHostname , out IPAddress address ) )
174
+ {
175
+ SsrpResult response = SendUDPRequest ( new IPAddress [ ] { address } , port , requestPacket , allIPsInParallel ) ;
176
+ if ( response != null && response . ResponsePacket != null )
177
+ return response . ResponsePacket ;
178
+ else if ( response != null && response . Error != null )
179
+ throw response . Error ;
180
+ else
181
+ return null ;
182
+ }
174
183
175
184
TimeSpan ts = default ;
176
185
// In case the Timeout is Infinite, we will receive the max value of Int64 as the tick count
@@ -181,27 +190,7 @@ private static byte[] SendUDPRequest(string browserHostname, int port, byte[] re
181
190
ts = ts . Ticks < 0 ? TimeSpan . FromTicks ( 0 ) : ts ;
182
191
}
183
192
184
- IPAddress [ ] ipAddresses = null ;
185
- if ( ! isIpAddress )
186
- {
187
- Task < IPAddress [ ] > serverAddrTask = Dns . GetHostAddressesAsync ( browserHostname ) ;
188
- bool taskComplete ;
189
- try
190
- {
191
- taskComplete = serverAddrTask . Wait ( ts ) ;
192
- }
193
- catch ( AggregateException ae )
194
- {
195
- throw ae . InnerException ;
196
- }
197
-
198
- // If DNS took too long, need to return instead of blocking
199
- if ( ! taskComplete )
200
- return null ;
201
-
202
- ipAddresses = serverAddrTask . Result ;
203
- }
204
-
193
+ IPAddress [ ] ipAddresses = SNICommon . GetDnsIpAddresses ( browserHostname ) ;
205
194
Debug . Assert ( ipAddresses . Length > 0 , "DNS should throw if zero addresses resolve" ) ;
206
195
207
196
switch ( ipPreference )
@@ -278,7 +267,7 @@ private static SsrpResult SendUDPRequest(IPAddress[] ipAddresses, int port, byte
278
267
for ( int i = 0 ; i < ipAddresses . Length ; i ++ )
279
268
{
280
269
IPEndPoint endPoint = new IPEndPoint ( ipAddresses [ i ] , port ) ;
281
- tasks . Add ( Task . Factory . StartNew < SsrpResult > ( ( ) => SendUDPRequest ( endPoint , requestPacket ) ) ) ;
270
+ tasks . Add ( Task . Factory . StartNew < SsrpResult > ( ( ) => SendUDPRequest ( endPoint , requestPacket ) , cts . Token ) ) ;
282
271
}
283
272
284
273
List < Task < SsrpResult > > completedTasks = new ( ) ;
0 commit comments