Ejemplo n.º 1
0
 internal void read_callback_w(IntPtr stream, IntPtr size, WindowsBufferStruct buf)
 {
     read_callback(stream, size);
 }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
 internal static extern int uv_write_win(IntPtr req, IntPtr handle, WindowsBufferStruct[] bufs, int bufcnt, callback callback);
Ejemplo n.º 4
0
 internal void recv_start_callback_w(IntPtr handle, IntPtr nread, WindowsBufferStruct buf, IntPtr sockaddr, ushort flags)
 {
     recv_start_callback(handle, nread, sockaddr, flags);
 }
Ejemplo n.º 5
0
 internal static extern int uv_udp_send_win(IntPtr req, IntPtr handle, WindowsBufferStruct[] bufs, int bufcnt, sockaddr_in addr, callback callback);
Ejemplo n.º 6
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);
        }
		void AllocWin(IntPtr data, int size, out WindowsBufferStruct buf)
		{
			IntPtr ptr;
			size = Alloc(size, out ptr);
			buf = new WindowsBufferStruct(ptr, size);
		}
Ejemplo n.º 8
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);
        }