From b33fd5409cda246aa7b4eda53ce5a5eb2286c9ca Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Fri, 4 Dec 2009 12:06:54 -0500 Subject: [PATCH] Work around a limitation in the SCNetworkReachability api when using hostnames --- reachability/reachability.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/reachability/reachability.cs b/reachability/reachability.cs index 7c0f802f5..d5f1c6961 100644 --- a/reachability/reachability.cs +++ b/reachability/reachability.cs @@ -96,15 +96,24 @@ static bool IsNetworkAvaialable (out NetworkReachabilityFlags flags) static NetworkReachability remoteHostReachability; public static NetworkStatus RemoteHostStatus () { + NetworkReachabilityFlags flags; + bool reachable; + if (remoteHostReachability == null){ remoteHostReachability = new NetworkReachability (HostName); + + // Need to probe before we queue, or we wont get any meaningful values + // this only happens when you create NetworkReachability from a hostname + reachable = remoteHostReachability.TryGetFlags (out flags); + remoteHostReachability.SetCallback (OnChange); remoteHostReachability.Schedule (CFRunLoop.Current, CFRunLoop.ModeDefault); - } - NetworkReachabilityFlags flags; - if (!remoteHostReachability.TryGetFlags (out flags)) - return NetworkStatus.NotReachable; + } else + reachable = remoteHostReachability.TryGetFlags (out flags); + if (!reachable) + return NetworkStatus.NotReachable; + if (!IsReachableWithoutRequiringConnection (flags)) return NetworkStatus.NotReachable;