public void Dispose() { lock (this) { if (handle == IntPtr.Zero) { return; } if (scheduledWithRunLoop) { SCNetworkReachabilityUnscheduleFromRunLoop(handle, CFRunLoopGetMain(), runLoopMode); } CFRelease(handle); handle = IntPtr.Zero; callback = null; flags = NetworkReachabilityFlags.None; scheduledWithRunLoop = false; } }
public MacNetworkChange() { var sockaddr = sockaddr_in.Create(); handle = SCNetworkReachabilityCreateWithAddress(IntPtr.Zero, ref sockaddr); if (handle == IntPtr.Zero) { throw new Exception("SCNetworkReachabilityCreateWithAddress returned NULL"); } callback = new SCNetworkReachabilityCallback(HandleCallback); var info = new SCNetworkReachabilityContext { info = GCHandle.ToIntPtr(GCHandle.Alloc(this)) }; SCNetworkReachabilitySetCallback(handle, callback, ref info); scheduledWithRunLoop = LoadRunLoopMode() && SCNetworkReachabilityScheduleWithRunLoop(handle, CFRunLoopGetMain(), runLoopMode); SCNetworkReachabilityGetFlags(handle, out flags); }
static extern bool SCNetworkReachabilitySetCallback(IntPtr reachability, SCNetworkReachabilityCallback callback, ref SCNetworkReachabilityContext context);
public void Dispose () { lock (this) { if (handle == IntPtr.Zero) return; if (scheduledWithRunLoop) SCNetworkReachabilityUnscheduleFromRunLoop (handle, CFRunLoopGetMain (), runLoopMode); CFRelease (handle); handle = IntPtr.Zero; callback = null; flags = NetworkReachabilityFlags.None; scheduledWithRunLoop = false; } }
public MacNetworkChange () { var sockaddr = sockaddr_in.Create (); handle = SCNetworkReachabilityCreateWithAddress (IntPtr.Zero, ref sockaddr); if (handle == IntPtr.Zero) throw new Exception ("SCNetworkReachabilityCreateWithAddress returned NULL"); callback = new SCNetworkReachabilityCallback (HandleCallback); var info = new SCNetworkReachabilityContext { info = GCHandle.ToIntPtr (GCHandle.Alloc (this)) }; SCNetworkReachabilitySetCallback (handle, callback, ref info); scheduledWithRunLoop = LoadRunLoopMode () && SCNetworkReachabilityScheduleWithRunLoop (handle, CFRunLoopGetMain (), runLoopMode); SCNetworkReachabilityGetFlags (handle, out flags); }
static extern bool SCNetworkReachabilitySetCallback (IntPtr reachability, SCNetworkReachabilityCallback callback, ref SCNetworkReachabilityContext context);