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