@@ -170,7 +170,16 @@ private static byte[] SendUDPRequest(string browserHostname, int port, byte[] re
170170 Debug . Assert ( port >= 0 && port <= 65535 , "Invalid port" ) ;
171171 Debug . Assert ( requestPacket != null && requestPacket . Length > 0 , "requestPacket should not be null or 0-length array" ) ;
172172
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+ }
174183
175184 TimeSpan ts = default ;
176185 // In case the Timeout is Infinite, we will receive the max value of Int64 as the tick count
@@ -181,26 +190,7 @@ private static byte[] SendUDPRequest(string browserHostname, int port, byte[] re
181190 ts = ts . Ticks < 0 ? TimeSpan . FromTicks ( 0 ) : ts ;
182191 }
183192
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- }
193+ IPAddress [ ] ipAddresses = SNICommon . GetDnsIpAddresses ( browserHostname ) ;
204194
205195 Debug . Assert ( ipAddresses . Length > 0 , "DNS should throw if zero addresses resolve" ) ;
206196
@@ -278,7 +268,7 @@ private static SsrpResult SendUDPRequest(IPAddress[] ipAddresses, int port, byte
278268 for ( int i = 0 ; i < ipAddresses . Length ; i ++ )
279269 {
280270 IPEndPoint endPoint = new IPEndPoint ( ipAddresses [ i ] , port ) ;
281- tasks . Add ( Task . Factory . StartNew < SsrpResult > ( ( ) => SendUDPRequest ( endPoint , requestPacket ) ) ) ;
271+ tasks . Add ( Task . Factory . StartNew < SsrpResult > ( ( ) => SendUDPRequest ( endPoint , requestPacket ) , cts . Token ) ) ;
282272 }
283273
284274 List < Task < SsrpResult > > completedTasks = new ( ) ;
0 commit comments