public void Main() { source = new Source(this); loop = CFRunLoop.Current; loop.AddSource(source, CFRunLoop.ModeDefault); context = new Context(this); SynchronizationContext.SetSynchronizationContext(context); readyEvent.Set(); loop.Run(); cts.Dispose(); source.Dispose(); }
void eventTapThread() { tapThread = CFRunLoop.Current; tapThread.AddSource(eventPortSource, CFRunLoop.ModeCommon); tapThread.Run(); }
CFSocket (int family, int type, int proto, CFRunLoop loop) { var cbTypes = CFSocketCallBackType.DataCallBack | CFSocketCallBackType.ConnectCallBack; gch = GCHandle.Alloc (this); var ctx = new CFStreamClientContext (); ctx.Info = GCHandle.ToIntPtr (gch); var ptr = Marshal.AllocHGlobal (Marshal.SizeOf (typeof(CFStreamClientContext))); try { Marshal.StructureToPtr (ctx, ptr, false); handle = CFSocketCreate ( IntPtr.Zero, family, type, proto, cbTypes, OnCallback, ptr); } finally { Marshal.FreeHGlobal (ptr); } if (handle == IntPtr.Zero) throw new CFSocketException (CFSocketError.Error); gch = GCHandle.Alloc (this); var source = new CFRunLoopSource (CFSocketCreateRunLoopSource (IntPtr.Zero, handle, 0)); loop.AddSource (source, CFRunLoop.CFDefaultRunLoopMode); }