public static MyNetworkStream CreateStream(string server, uint connectionTimeout, uint keepAlive, uint port, bool unix) { if (unix) { return(new MyNetworkStream(StreamCreator.GetUnixSocket(server, connectionTimeout, keepAlive), true)); } MyNetworkStream stream = null; IPHostEntry ipHE = GetHostEntry(server); foreach (IPAddress address in ipHE.AddressList) { try { stream = CreateSocketStream(port, keepAlive, connectionTimeout, address, unix); if (stream != null) { break; } } catch (Exception ex) { string exTimeOutMessage = connectionTimeout == 0 ? ResourcesX.TimeOutSingleHost0ms : String.Format(ResourcesX.TimeOutSingleHost, connectionTimeout); if (ex is TimeoutException) { throw new TimeoutException(exTimeOutMessage); } SocketException socketException = ex as SocketException; #if NETSTANDARD1_6 socketException = ex.InnerException as SocketException; #endif // if the exception is a ConnectionRefused then we eat it as we may have other address // to attempt if (socketException == null) { throw; } if (socketException.SocketErrorCode == SocketError.TimedOut) { throw new TimeoutException(exTimeOutMessage); } if (socketException.SocketErrorCode != SocketError.ConnectionRefused) { throw; } } } return(stream); }
public static MyNetworkStream CreateStream(MySqlConnectionStringBuilder settings, bool unix) { if (unix) { return(new MyNetworkStream(StreamCreator.GetUnixSocket(settings), true)); } MyNetworkStream stream = null; IPHostEntry ipHE = GetHostEntry(settings.Server); foreach (IPAddress address in ipHE.AddressList) { try { stream = CreateSocketStream(settings, address, unix); if (stream != null) { break; } } catch (Exception ex) { SocketException socketException = ex as SocketException; // if the exception is a ConnectionRefused then we eat it as we may have other address // to attempt if (socketException == null) { throw; } if (socketException.SocketErrorCode != SocketError.ConnectionRefused) { throw; } } } return(stream); }