Example #1
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());
            }
        }
Example #2
0
 public CFDataBuffer(IntPtr ptr)
 {
     data = new CFData (ptr, false);
     buffer = data.GetBuffer ();
 }
 public CFDataBuffer(IntPtr ptr)
 {
     data   = new CFData(ptr, false);
     buffer = data.GetBuffer();
 }
Example #4
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 ());
            }
        }