@@ -46,8 +46,7 @@ public PooledSocket(DnsEndPoint endpoint, TimeSpan connectionTimeout, TimeSpan r
4646 : ( int ) receiveTimeout . TotalMilliseconds ;
4747
4848 socket . ReceiveTimeout = rcv ;
49- socket . SendTimeout = rcv ;
50- socket . SetSocketOption ( SocketOptionLevel . Socket , SocketOptionName . KeepAlive , true ) ;
49+ socket . SendTimeout = rcv ;
5150
5251 ConnectWithTimeout ( socket , endpoint , timeout ) ;
5352
@@ -59,8 +58,21 @@ public PooledSocket(DnsEndPoint endpoint, TimeSpan connectionTimeout, TimeSpan r
5958
6059 private void ConnectWithTimeout ( Socket socket , DnsEndPoint endpoint , int timeout )
6160 {
61+ socket . SetSocketOption ( SocketOptionLevel . Socket , SocketOptionName . KeepAlive , true ) ;
6262 var args = new SocketAsyncEventArgs ( ) ;
63- args . RemoteEndPoint = endpoint ;
63+
64+ //Workaround for https://github.com/dotnet/corefx/issues/26840
65+ if ( ! IPAddress . TryParse ( endpoint . Host , out var address ) )
66+ {
67+ address = Dns . GetHostAddresses ( endpoint . Host ) . FirstOrDefault ( ip => ip . AddressFamily == AddressFamily . InterNetwork ) ;
68+ if ( address == null )
69+ throw new ArgumentException ( String . Format ( "Could not resolve host '{0}'." , endpoint . Host ) ) ;
70+ args . RemoteEndPoint = new IPEndPoint ( address , endpoint . Port ) ;
71+ }
72+ else
73+ {
74+ args . RemoteEndPoint = endpoint ;
75+ }
6476
6577 using ( var mres = new ManualResetEventSlim ( ) )
6678 {
0 commit comments