Esempio n. 1
0
 protected virtual void Dispose(bool disposing)
 {
     if (data != null)
     {
         data.Dispose();
         data = null;
     }
 }
Esempio n. 2
0
        public unsafe CFDataBuffer(byte[] buffer)
        {
            this.buffer = buffer;

            /*
             * Copy the buffer to allow the native side to take ownership.
             */
            fixed(byte *ptr = buffer)
            data = CFData.FromData((IntPtr)ptr, buffer.Length);
        }
Esempio n. 3
0
        public CFDataBuffer(byte[] buffer)
        {
            this.buffer = buffer;

            /*
             * Copy the buffer to allow the native side to take ownership.
             */

            var gch = GCHandle.Alloc (buffer, GCHandleType.Pinned);
            data = CFData.FromData (gch.AddrOfPinnedObject (), buffer.Length);
            gch.Free ();
        }
Esempio n. 4
0
        public CFDataBuffer(byte[] buffer)
        {
            this.buffer = buffer;

            /*
             * Copy the buffer to allow the native side to take ownership.
             */

            var gch = GCHandle.Alloc(buffer, GCHandleType.Pinned);

            data = CFData.FromData(gch.AddrOfPinnedObject(), buffer.Length);
            gch.Free();
        }
Esempio n. 5
0
        static void OnCallback(IntPtr s, nuint type, IntPtr address, IntPtr data, IntPtr info)
        {
            var socket = GCHandle.FromIntPtr(info).Target as CFSocket;
            CFSocketCallBackType cbType = (CFSocketCallBackType)(ulong)type;

            if (cbType == CFSocketCallBackType.AcceptCallBack)
            {
                var ep     = CFSocketAddress.EndPointFromAddressPtr(address);
                var handle = new CFSocketNativeHandle(Marshal.ReadInt32(data));
                socket.OnAccepted(new CFSocketAcceptEventArgs(handle, ep));
            }
            else if (cbType == CFSocketCallBackType.ConnectCallBack)
            {
                CFSocketError result;
                if (data == IntPtr.Zero)
                {
                    result = CFSocketError.Success;
                }
                else
                {
                    // Note that we read a 32bit value even if CFSocketError is a nint:
                    // 'or a pointer to an SInt32 error code if the connect failed.'
                    result = (CFSocketError)Marshal.ReadInt32(data);
                }
                socket.OnConnect(new CFSocketConnectEventArgs(result));
            }
            else if (cbType == CFSocketCallBackType.DataCallBack)
            {
                var ep = CFSocketAddress.EndPointFromAddressPtr(address);
                using (var cfdata = new CFData(data, false))
                    socket.OnData(new CFSocketDataEventArgs(ep, cfdata.GetBuffer()));
            }
            else if (cbType == CFSocketCallBackType.NoCallBack)
            {
                // nothing to do
            }
            else if (cbType == CFSocketCallBackType.ReadCallBack)
            {
                socket.OnRead(new CFSocketReadEventArgs());
            }
            else if (cbType == CFSocketCallBackType.WriteCallBack)
            {
                socket.OnWrite(new CFSocketWriteEventArgs());
            }
        }
Esempio n. 6
0
 public CFDataBuffer(IntPtr ptr)
 {
     data = new CFData (ptr, false);
     buffer = data.GetBuffer ();
 }
Esempio n. 7
0
 protected virtual void Dispose(bool disposing)
 {
     if (data != null) {
         data.Dispose ();
         data = null;
     }
 }
Esempio n. 8
0
 public CFDataBuffer(IntPtr ptr)
 {
     data   = new CFData(ptr, false);
     buffer = data.GetBuffer();
 }
Esempio n. 9
0
        static void OnCallback(IntPtr s, nuint type, IntPtr address, IntPtr data, IntPtr info)
        {
            var socket = GCHandle.FromIntPtr (info).Target as CFSocket;
            CFSocketCallBackType cbType = (CFSocketCallBackType) (ulong) type;

            if (cbType == CFSocketCallBackType.AcceptCallBack) {
                var ep = CFSocketAddress.EndPointFromAddressPtr (address);
                var handle = new CFSocketNativeHandle (Marshal.ReadInt32 (data));
                socket.OnAccepted (new CFSocketAcceptEventArgs (handle, ep));
            } else if (cbType == CFSocketCallBackType.ConnectCallBack) {
                CFSocketError result;
                if (data == IntPtr.Zero)
                    result = CFSocketError.Success;
                else {
                    // Note that we read a 32bit value even if CFSocketError is a nint:
                    // 'or a pointer to an SInt32 error code if the connect failed.'
                    result = (CFSocketError)Marshal.ReadInt32 (data);
                }
                socket.OnConnect (new CFSocketConnectEventArgs (result));
            } else if (cbType == CFSocketCallBackType.DataCallBack) {
                var ep = CFSocketAddress.EndPointFromAddressPtr (address);
                using (var cfdata = new CFData (data, false))
                    socket.OnData (new CFSocketDataEventArgs (ep, cfdata.GetBuffer ()));
            } else if (cbType == CFSocketCallBackType.NoCallBack) {
                // nothing to do
            } else if (cbType == CFSocketCallBackType.ReadCallBack) {
                socket.OnRead (new CFSocketReadEventArgs ());
            } else if (cbType == CFSocketCallBackType.WriteCallBack) {
                socket.OnWrite (new CFSocketWriteEventArgs ());
            }
        }