Exemplo n.º 1
0
        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, (nuint)(ulong)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.ModeDefault);
        }
Exemplo n.º 2
0
        internal CFSocket(CFSocketNativeHandle sock)
        {
            var cbTypes = CFSocketCallBackType.DataCallBack | CFSocketCallBackType.WriteCallBack;

            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 = CFSocketCreateWithNative(
                    IntPtr.Zero, sock, (nuint)(ulong)cbTypes, OnCallback, ptr);
            } finally {
                Marshal.FreeHGlobal(ptr);
            }

            if (handle == IntPtr.Zero)
            {
                throw new CFSocketException(CFSocketError.Error);
            }

            var source = new CFRunLoopSource(CFSocketCreateRunLoopSource(IntPtr.Zero, handle, 0));
            var loop   = CFRunLoop.Current;

            loop.AddSource(source, CFRunLoop.ModeDefault);
        }
Exemplo n.º 3
0
        CFSocket(IntPtr handle)
        {
            this.handle = handle;
            gch         = GCHandle.Alloc(this);

            var source = new CFRunLoopSource(CFSocketCreateRunLoopSource(IntPtr.Zero, handle, 0));
            var loop   = CFRunLoop.Current;

            loop.AddSource(source, CFRunLoop.ModeDefault);
        }
Exemplo n.º 4
0
        public bool ContainsSource(CFRunLoopSource source, NSString mode)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (mode == null)
            {
                throw new ArgumentNullException("mode");
            }

            return(CFRunLoopContainsSource(handle, source.Handle, mode.Handle));
        }
Exemplo n.º 5
0
        public void AddSource(CFRunLoopSource source, NSString mode)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (mode == null)
            {
                throw new ArgumentNullException("mode");
            }

            CFRunLoopAddSource(handle, source.Handle, mode.Handle);
        }
Exemplo n.º 6
0
        public bool RemoveSource(CFRunLoopSource source, NSString mode)
#endif
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (mode == null)
            {
                throw new ArgumentNullException("mode");
            }

            CFRunLoopRemoveSource(handle, source.Handle, mode.Handle);
#if !XAMCORE_2_0
            return(true);
#endif
        }
Exemplo n.º 7
0
 public void RemoveSource(CFRunLoopSource source, NSString mode)
Exemplo n.º 8
0
        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, (nuint) (ulong) 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.ModeDefault);
        }
Exemplo n.º 9
0
        CFSocket(IntPtr handle)
        {
            this.handle = handle;
            gch = GCHandle.Alloc (this);

            var source = new CFRunLoopSource (CFSocketCreateRunLoopSource (IntPtr.Zero, handle, 0));
            var loop = CFRunLoop.Current;
            loop.AddSource (source, CFRunLoop.ModeDefault);
        }
Exemplo n.º 10
0
        internal CFSocket(CFSocketNativeHandle sock)
        {
            var cbTypes = CFSocketCallBackType.DataCallBack | CFSocketCallBackType.WriteCallBack;

            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 = CFSocketCreateWithNative (
                    IntPtr.Zero, sock, (nuint) (ulong) cbTypes, OnCallback, ptr);
            } finally {
                Marshal.FreeHGlobal (ptr);
            }

            if (handle == IntPtr.Zero)
                throw new CFSocketException (CFSocketError.Error);

            var source = new CFRunLoopSource (CFSocketCreateRunLoopSource (IntPtr.Zero, handle, 0));
            var loop = CFRunLoop.Current;
            loop.AddSource (source, CFRunLoop.ModeDefault);
        }
Exemplo n.º 11
0
		public bool RemoveSource (CFRunLoopSource source, NSString mode)
#endif
		{
			if (source == null)
				throw new ArgumentNullException ("source");
			if (mode == null)
				throw new ArgumentNullException ("mode");

			CFRunLoopRemoveSource (handle, source.Handle, mode.Handle);
#if !XAMCORE_2_0
			return true;
#endif
		}
Exemplo n.º 12
0
		public void RemoveSource (CFRunLoopSource source, NSString mode)
Exemplo n.º 13
0
		public bool ContainsSource (CFRunLoopSource source, NSString mode)
		{
			if (source == null)
				throw new ArgumentNullException ("source");
			if (mode == null)
				throw new ArgumentNullException ("mode");

			return CFRunLoopContainsSource (handle, source.Handle, mode.Handle);
		}
Exemplo n.º 14
0
		public void AddSource (CFRunLoopSource source, NSString mode)
		{
			if (source == null)
				throw new ArgumentNullException ("source");
			if (mode == null)
				throw new ArgumentNullException ("mode");

			CFRunLoopAddSource (handle, source.Handle, mode.Handle);
		}