Skip to content

Commit

Permalink
Work around a limitation in the SCNetworkReachability api when using …
Browse files Browse the repository at this point in the history
…hostnames
  • Loading branch information
Miguel de Icaza authored and Miguel de Icaza committed Dec 4, 2009
1 parent fc11e2a commit b33fd54
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions reachability/reachability.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit b33fd54

Please sign in to comment.