Exemplo n.º 1
0
        public void Write(byte[] data, int offset, int count, Action <bool> callback)
        {
            GCHandle             datagchandle = GCHandle.Alloc(data, GCHandleType.Pinned);
            CallbackPermaRequest cpr          = new CallbackPermaRequest(UvRequestType.UV_WRITE);

            cpr.Callback += (status, cpr2) => {
                datagchandle.Free();
                if (callback != null)
                {
                    callback(status == 0);
                }
            };

            IntPtr ptr = (IntPtr)(((long)datagchandle.AddrOfPinnedObject()) + (long)offset);

            int r;

            if (UV.isUnix)
            {
                UnixBufferStruct[] buf = new UnixBufferStruct[1];
                buf[0] = new UnixBufferStruct(ptr, count);
                r      = uv_write_unix(cpr.Handle, handle, buf, 1, CallbackPermaRequest.StaticEnd);
            }
            else
            {
                WindowsBufferStruct[] buf = new WindowsBufferStruct[1];
                buf[0] = new WindowsBufferStruct(ptr, count);
                r      = uv_write_win(cpr.Handle, handle, buf, 1, CallbackPermaRequest.StaticEnd);
            }

            Ensure.Success(r, Loop);
        }
Exemplo n.º 2
0
        public void Write(Handle handle, ArraySegment <byte> segment, Action <Exception> callback)
        {
            CheckDisposed();

            GCHandle             datagchandle = GCHandle.Alloc(segment.Array, GCHandleType.Pinned);
            CallbackPermaRequest cpr          = new CallbackPermaRequest(RequestType.UV_WRITE);

            cpr.Callback = (status, cpr2) => {
                datagchandle.Free();
                Ensure.Success(status, callback);
            };

            var ptr = (IntPtr)(datagchandle.AddrOfPinnedObject().ToInt64() + segment.Offset);

            int r;

            if (UV.isUnix)
            {
                UnixBufferStruct[] buf = new UnixBufferStruct[1];
                buf[0] = new UnixBufferStruct(ptr, segment.Count);
                r      = uv_write2_unix(cpr.Handle, NativeHandle, buf, 1, handle.NativeHandle, CallbackPermaRequest.CallbackDelegate);
            }
            else
            {
                WindowsBufferStruct[] buf = new WindowsBufferStruct[1];
                buf[0] = new WindowsBufferStruct(ptr, segment.Count);
                r      = uv_write2_win(cpr.Handle, NativeHandle, buf, 1, handle.NativeHandle, CallbackPermaRequest.CallbackDelegate);
            }

            Ensure.Success(r);
        }
Exemplo n.º 3
0
        public void Write(UVStream stream, byte[] data, int index, int count, Action <bool> callback)
        {
            GCHandle             datagchandle = GCHandle.Alloc(data, GCHandleType.Pinned);
            CallbackPermaRequest cpr          = new CallbackPermaRequest(RequestType.UV_WRITE);

            cpr.Callback = (status, cpr2) => {
                datagchandle.Free();
                if (callback != null)
                {
                    callback(status == 0);
                }
            };

            var ptr = (IntPtr)(datagchandle.AddrOfPinnedObject().ToInt64() + index);

            int r;

            if (UV.isUnix)
            {
                UnixBufferStruct[] buf = new UnixBufferStruct[1];
                buf[0] = new UnixBufferStruct(ptr, count);
                r      = uv_write2_unix(cpr.Handle, NativeHandle, buf, 1, stream.NativeHandle, CallbackPermaRequest.StaticEnd);
            }
            else
            {
                WindowsBufferStruct[] buf = new WindowsBufferStruct[1];
                buf[0] = new WindowsBufferStruct(ptr, count);
                r      = uv_write2_win(cpr.Handle, NativeHandle, buf, 1, stream.NativeHandle, CallbackPermaRequest.StaticEnd);
            }

            Ensure.Success(r, Loop);
        }
Exemplo n.º 4
0
        unsafe internal static UnixBufferStruct DebugAlloc(IntPtr handle, int size)
        {
            UnixBufferStruct tmp = UV.Alloc(handle, size);

            Console.WriteLine(tmp.@base);
            return(tmp);
        }
Exemplo n.º 5
0
        unsafe public int TryWrite(ArraySegment <byte> data)
        {
            Ensure.ArgumentNotNull(data.Array, "data");

            fixed(byte *bytePtr = data.Array)
            {
                IntPtr ptr = (IntPtr)bytePtr + data.Offset;
                int    r;

                if (UV.isUnix)
                {
                    UnixBufferStruct[] buf = new UnixBufferStruct[1];
                    buf[0] = new UnixBufferStruct(ptr, data.Count);
                    r      = uv_try_write(NativeHandle, buf, 1);
                }
                else
                {
                    WindowsBufferStruct[] buf = new WindowsBufferStruct[1];
                    buf[0] = new WindowsBufferStruct(ptr, data.Count);
                    r      = uv_try_write(NativeHandle, buf, 1);
                }
                Ensure.Success(r);
                return(r);
            }
        }
Exemplo n.º 6
0
        void AllocUnix(IntPtr data, int size, out UnixBufferStruct buf)
        {
            IntPtr ptr;

            size = Alloc(size, out ptr);
            buf  = new UnixBufferStruct(ptr, size);
        }
Exemplo n.º 7
0
        public void Send(UdpMessage message, Action <Exception> callback)
        {
            CheckDisposed();

            Ensure.ArgumentNotNull(message.EndPoint, "message EndPoint");
            Ensure.AddressFamily(message.EndPoint.Address);

            var ipEndPoint = message.EndPoint;
            var data       = message.Payload;

            GCHandle             datagchandle = GCHandle.Alloc(data.Array, GCHandleType.Pinned);
            CallbackPermaRequest cpr          = new CallbackPermaRequest(RequestType.UV_UDP_SEND);

            cpr.Callback = (status, cpr2) => {
                datagchandle.Free();
                Ensure.Success(status, callback);
            };

            var ptr = (IntPtr)(datagchandle.AddrOfPinnedObject().ToInt64() + data.Offset);

            int r;

            if (UV.isUnix)
            {
                UnixBufferStruct[] buf = new UnixBufferStruct[1];
                buf[0] = new UnixBufferStruct(ptr, data.Count);

                if (ipEndPoint.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    sockaddr_in address = UV.ToStruct(ipEndPoint.Address.ToString(), ipEndPoint.Port);
                    r = uv_udp_send(cpr.Handle, NativeHandle, buf, 1, ref address, CallbackPermaRequest.CallbackDelegate);
                }
                else
                {
                    sockaddr_in6 address = UV.ToStruct6(ipEndPoint.Address.ToString(), ipEndPoint.Port);
                    r = uv_udp_send(cpr.Handle, NativeHandle, buf, 1, ref address, CallbackPermaRequest.CallbackDelegate);
                }
            }
            else
            {
                WindowsBufferStruct[] buf = new WindowsBufferStruct[1];
                buf[0] = new WindowsBufferStruct(ptr, data.Count);

                if (ipEndPoint.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    sockaddr_in address = UV.ToStruct(ipEndPoint.Address.ToString(), ipEndPoint.Port);
                    r = uv_udp_send(cpr.Handle, NativeHandle, buf, 1, ref address, CallbackPermaRequest.CallbackDelegate);
                }
                else
                {
                    sockaddr_in6 address = UV.ToStruct6(ipEndPoint.Address.ToString(), ipEndPoint.Port);
                    r = uv_udp_send(cpr.Handle, NativeHandle, buf, 1, ref address, CallbackPermaRequest.CallbackDelegate);
                }
            }
            Ensure.Success(r);
        }
Exemplo n.º 8
0
        public void Send(IPAddress ipAddress, int port, byte[] data, int index, int count, Action <bool> callback)
        {
            Ensure.ArgumentNotNull(ipAddress, "ipAddress");
            Ensure.AddressFamily(ipAddress);
            Ensure.ArgumentNotNull(data, "data");

            GCHandle             datagchandle = GCHandle.Alloc(data, GCHandleType.Pinned);
            CallbackPermaRequest cpr          = new CallbackPermaRequest(RequestType.UV_UDP_SEND);

            cpr.Callback += (status, cpr2) => {
                datagchandle.Free();
                if (callback != null)
                {
                    callback(status == 0);
                }
            };

            var ptr = (IntPtr)(datagchandle.AddrOfPinnedObject().ToInt64() + index);

            int r;

            if (UV.isUnix)
            {
                UnixBufferStruct[] buf = new UnixBufferStruct[1];
                buf[0] = new UnixBufferStruct(ptr, count);

                if (ipAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    r = uv_udp_send_unix(cpr.Handle, NativeHandle, buf, 1, UV.uv_ip4_addr(ipAddress.ToString(), port), CallbackPermaRequest.StaticEnd);
                }
                else
                {
                    r = uv_udp_send6_unix(cpr.Handle, NativeHandle, buf, 1, UV.uv_ip6_addr(ipAddress.ToString(), port), CallbackPermaRequest.StaticEnd);
                }
            }
            else
            {
                WindowsBufferStruct[] buf = new WindowsBufferStruct[1];
                buf[0] = new WindowsBufferStruct(ptr, count);

                if (ipAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    r = uv_udp_send_win(cpr.Handle, NativeHandle, buf, 1, UV.uv_ip4_addr(ipAddress.ToString(), port), CallbackPermaRequest.StaticEnd);
                }
                else
                {
                    r = uv_udp_send6_win(cpr.Handle, NativeHandle, buf, 1, UV.uv_ip6_addr(ipAddress.ToString(), port), CallbackPermaRequest.StaticEnd);
                }
            }
            Ensure.Success(r, Loop);
        }
Exemplo n.º 9
0
        public void Read(Loop loop, int offset, ArraySegment <byte> segment, Action <Exception, int> callback)
        {
            var datagchandle = GCHandle.Alloc(segment.Array, GCHandleType.Pinned);
            var fsr          = new FileSystemRequest();

            fsr.Callback = (ex) => {
                Ensure.Success(ex, callback, fsr.Result.ToInt32());
                datagchandle.Free();
            };
            UnixBufferStruct[] buf = new UnixBufferStruct[1];
            buf[0] = new UnixBufferStruct(datagchandle.AddrOfPinnedObject() + segment.Offset, segment.Count);
            int r = uv_fs_read(loop.NativeHandle, fsr.Handle, FileDescriptor, buf, 1, offset, FileSystemRequest.CallbackDelegate);

            Ensure.Success(r);
        }
Exemplo n.º 10
0
        unsafe public int TrySend(UdpMessage message)
        {
            Ensure.ArgumentNotNull(message, "message");

            var data       = message.Payload;
            var ipEndPoint = message.EndPoint;

            fixed(byte *bytePtr = data.Array)
            {
                var ptr = (IntPtr)bytePtr + message.Payload.Offset;
                int r;

                if (UV.isUnix)
                {
                    UnixBufferStruct[] buf = new UnixBufferStruct[1];
                    buf[0] = new UnixBufferStruct(ptr, data.Count);

                    if (ipEndPoint.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                    {
                        sockaddr_in address = UV.ToStruct(ipEndPoint.Address.ToString(), ipEndPoint.Port);
                        r = uv_udp_try_send(NativeHandle, buf, 1, ref address);
                    }
                    else
                    {
                        sockaddr_in6 address = UV.ToStruct6(ipEndPoint.Address.ToString(), ipEndPoint.Port);
                        r = uv_udp_try_send(NativeHandle, buf, 1, ref address);
                    }
                }
                else
                {
                    WindowsBufferStruct[] buf = new WindowsBufferStruct[1];
                    buf[0] = new WindowsBufferStruct(ptr, data.Count);

                    if (ipEndPoint.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                    {
                        sockaddr_in address = UV.ToStruct(ipEndPoint.Address.ToString(), ipEndPoint.Port);
                        r = uv_udp_try_send(NativeHandle, buf, 1, ref address);
                    }
                    else
                    {
                        sockaddr_in6 address = UV.ToStruct6(ipEndPoint.Address.ToString(), ipEndPoint.Port);
                        r = uv_udp_try_send(NativeHandle, buf, 1, ref address);
                    }
                }
                return(r);
            }
        }
Exemplo n.º 11
0
        public void Write(ArraySegment <byte> data, Action <Exception> callback)
        {
            Ensure.ArgumentNotNull(data, "data");

            int index = data.Offset;
            int count = data.Count;

            PendingWrites++;

            GCHandle             datagchandle = GCHandle.Alloc(data.Array, GCHandleType.Pinned);
            CallbackPermaRequest cpr          = new CallbackPermaRequest(RequestType.UV_WRITE);

            cpr.Callback = (status, cpr2) => {
                datagchandle.Free();
                PendingWrites--;

                Ensure.Success(status, callback);

                if (PendingWrites == 0)
                {
                    OnDrain();
                }
            };

            var ptr = (IntPtr)(datagchandle.AddrOfPinnedObject().ToInt64() + index);

            int r;

            if (UV.isUnix)
            {
                UnixBufferStruct[] buf = new UnixBufferStruct[1];
                buf[0] = new UnixBufferStruct(ptr, count);
                r      = uv_write_unix(cpr.Handle, NativeHandle, buf, 1, CallbackPermaRequest.CallbackDelegate);
            }
            else
            {
                WindowsBufferStruct[] buf = new WindowsBufferStruct[1];
                buf[0] = new WindowsBufferStruct(ptr, count);
                r      = uv_write_win(cpr.Handle, NativeHandle, buf, 1, CallbackPermaRequest.CallbackDelegate);
            }

            Ensure.Success(r);
        }
Exemplo n.º 12
0
 internal static extern int uv_write_unix(IntPtr req, IntPtr handle, UnixBufferStruct[] bufs, int bufcnt, callback callback);
Exemplo n.º 13
0
        public void Write(byte[] data, int index, int count, Action<bool> callback)
        {
            Ensure.ArgumentNotNull(data, "data");

            PendingWrites++;

            GCHandle datagchandle = GCHandle.Alloc(data, GCHandleType.Pinned);
            CallbackPermaRequest cpr = new CallbackPermaRequest(RequestType.UV_WRITE);
            cpr.Callback += (status, cpr2) => {
                datagchandle.Free();
                PendingWrites--;
                if (callback != null) {
                    callback(status == 0);
                }
                if (PendingWrites == 0) {
                    OnDrain();
                }
            };

            var ptr = (IntPtr)(datagchandle.AddrOfPinnedObject().ToInt64() + index);

            int r;
            if (UV.isUnix) {
                UnixBufferStruct[] buf = new UnixBufferStruct[1];
                buf[0] = new UnixBufferStruct(ptr, count);
                r = uv_write_unix(cpr.Handle, NativeHandle, buf, 1, CallbackPermaRequest.StaticEnd);
            } else {
                WindowsBufferStruct[] buf = new WindowsBufferStruct[1];
                buf[0] = new WindowsBufferStruct(ptr, count);
                r = uv_write_win(cpr.Handle, NativeHandle, buf, 1, CallbackPermaRequest.StaticEnd);
            }

            Ensure.Success(r, Loop);
        }
Exemplo n.º 14
0
 private static extern int uv_fs_write(IntPtr loop, IntPtr req, int fd, UnixBufferStruct[] bufs, int nbufs, long offset, NativeMethods.uv_fs_cb fs_cb);
Exemplo n.º 15
0
 internal void read_callback_u(IntPtr stream, IntPtr size, UnixBufferStruct buf)
 {
     read_callback(stream, size);
 }
Exemplo n.º 16
0
 internal static void Free(UnixBufferStruct buf)
 {
     Free(buf.@base);
 }
Exemplo n.º 17
0
 private static extern int uv_fs_read(IntPtr loop, IntPtr req, int fd, UnixBufferStruct[] buf, int nbufs, long offset, NativeMethods.uv_fs_cb callback);
Exemplo n.º 18
0
 internal void recv_start_callback_u(IntPtr handle, IntPtr nread, UnixBufferStruct buf, IntPtr sockaddr, ushort flags)
 {
     recv_start_callback(handle, nread, sockaddr, flags);
 }
Exemplo n.º 19
0
		internal static void Free(UnixBufferStruct buf)
		{
			Free(buf.@base);
		}
		void AllocUnix(IntPtr data, int size, out UnixBufferStruct buf)
		{
			IntPtr ptr;
			size = Alloc(size, out ptr);
			buf = new UnixBufferStruct(ptr, size);
		}
Exemplo n.º 21
0
 internal void read_callback_u(IntPtr stream, IntPtr size, UnixBufferStruct buf)
 {
     read_callback(stream, size);
 }
Exemplo n.º 22
0
 internal static extern int uv_udp_send_unix(IntPtr req, IntPtr handle, UnixBufferStruct[] bufs, int bufcnt, sockaddr_in addr, callback callback);
Exemplo n.º 23
0
        static void recv_start_callback_u(IntPtr handlePointer, IntPtr nread, ref UnixBufferStruct buf, IntPtr sockaddr, ushort flags)
        {
            var handle = FromIntPtr <Udp>(handlePointer);

            handle.recv_start_callback(handlePointer, nread, sockaddr, flags);
        }
Exemplo n.º 24
0
 internal void recv_start_callback_u(IntPtr handle, IntPtr nread, UnixBufferStruct buf, IntPtr sockaddr, ushort flags)
 {
     recv_start_callback(handle, nread, sockaddr, flags);
 }
Exemplo n.º 25
0
 public void Write(Loop loop, int offset, ArraySegment<byte> segment, Action<Exception, int> callback)
 {
     var datagchandle = GCHandle.Alloc(segment.Array, GCHandleType.Pinned);
     var fsr = new FileSystemRequest();
     fsr.Callback = (ex) => {
         Ensure.Success(ex, callback, fsr.Result.ToInt32());
         datagchandle.Free();
     };
     UnixBufferStruct[] buf = new UnixBufferStruct[1];
     buf[0] = new UnixBufferStruct(new IntPtr(datagchandle.AddrOfPinnedObject().ToInt64() + segment.Offset), segment.Count);
     int r = uv_fs_write(loop.NativeHandle, fsr.Handle, FileDescriptor, buf, segment.Count, offset, FileSystemRequest.CallbackDelegate);
     Ensure.Success(r);
 }
Exemplo n.º 26
0
        static void read_callback_u(IntPtr streamPointer, IntPtr size, UnixBufferStruct buf)
        {
            var stream = FromIntPtr <UVStream>(streamPointer);

            stream.read_callback(streamPointer, size);
        }
Exemplo n.º 27
0
        public void Send(IPAddress ipAddress, int port, byte[] data, int index, int count, Action<bool> callback)
        {
            Ensure.ArgumentNotNull(ipAddress, "ipAddress");
            Ensure.AddressFamily(ipAddress);
            Ensure.ArgumentNotNull(data, "data");

            GCHandle datagchandle = GCHandle.Alloc(data, GCHandleType.Pinned);
            CallbackPermaRequest cpr = new CallbackPermaRequest(RequestType.UV_UDP_SEND);
            cpr.Callback += (status, cpr2) => {
                datagchandle.Free();
                if (callback != null) {
                    callback(status == 0);
                }
            };

            var ptr = (IntPtr)(datagchandle.AddrOfPinnedObject().ToInt64() + index);

            int r;
            if (UV.isUnix) {
                UnixBufferStruct[] buf = new UnixBufferStruct[1];
                buf[0] = new UnixBufferStruct(ptr, count);

                if (ipAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) {
                    r = uv_udp_send_unix(cpr.Handle, NativeHandle, buf, 1, UV.uv_ip4_addr(ipAddress.ToString(), port), CallbackPermaRequest.StaticEnd);
                } else {
                    r = uv_udp_send6_unix(cpr.Handle, NativeHandle, buf, 1, UV.uv_ip6_addr(ipAddress.ToString(), port), CallbackPermaRequest.StaticEnd);
                }
            } else {
                WindowsBufferStruct[] buf = new WindowsBufferStruct[1];
                buf[0] = new WindowsBufferStruct(ptr, count);

                if (ipAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) {
                    r = uv_udp_send_win(cpr.Handle, NativeHandle, buf, 1, UV.uv_ip4_addr(ipAddress.ToString(), port), CallbackPermaRequest.StaticEnd);
                } else {
                    r = uv_udp_send6_win(cpr.Handle, NativeHandle, buf, 1, UV.uv_ip6_addr(ipAddress.ToString(), port), CallbackPermaRequest.StaticEnd);
                }
            }
            Ensure.Success(r, Loop);
        }
Exemplo n.º 28
0
        public void Write(byte[] data, int offset, int count, Action<bool> callback)
        {
            GCHandle datagchandle = GCHandle.Alloc(data, GCHandleType.Pinned);
            CallbackPermaRequest cpr = new CallbackPermaRequest(UvRequestType.UV_WRITE);
            cpr.Callback += (status, cpr2) => {
                datagchandle.Free();
                if (callback != null) {
                    callback(status == 0);
                }
            };

            IntPtr ptr = (IntPtr)(((long)datagchandle.AddrOfPinnedObject()) + (long)offset);

            int r;
            if (UV.isUnix) {
                UnixBufferStruct[] buf = new UnixBufferStruct[1];
                buf[0] = new UnixBufferStruct(ptr, count);
                r = uv_write_unix(cpr.Handle, handle, buf, 1, CallbackPermaRequest.StaticEnd);
            } else {
                WindowsBufferStruct[] buf = new WindowsBufferStruct[1];
                buf[0] = new WindowsBufferStruct(ptr, count);
                r = uv_write_win(cpr.Handle, handle, buf, 1, CallbackPermaRequest.StaticEnd);
            }

            Ensure.Success(r, Loop);
        }