public void Write(ArraySegment <byte> data, Action <Exception> callback) { CheckDisposed(); 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); var buf = new uv_buf_t[] { new uv_buf_t(ptr, count) }; int r = uv_write(cpr.Handle, NativeHandle, buf, 1, CallbackPermaRequest.CallbackDelegate); Ensure.Success(r); }
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); }
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); }
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); }
public void Shutdown(Action callback) { var cbr = new CallbackPermaRequest(UvRequestType.UV_SHUTDOWN); cbr.Callback = (status, _) => { Close(callback); }; uv_shutdown(cbr.Handle, handle, CallbackPermaRequest.StaticEnd); }
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); }
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); }
public void Shutdown(Action <Exception> callback) { var cbr = new CallbackPermaRequest(RequestType.UV_SHUTDOWN); cbr.Callback = (status, _) => { Ensure.Success(status, (ex) => Close(() => { if (callback != null) { callback(ex); } })); }; uv_shutdown(cbr.Handle, NativeHandle, CallbackPermaRequest.CallbackDelegate); }
public void Write(IList <ArraySegment <byte> > buffers, Action <Exception> callback) { CheckDisposed(); PendingWrites++; int i; int n = buffers.Count; GCHandle[] datagchandles = new GCHandle[n]; CallbackPermaRequest cpr = new CallbackPermaRequest(RequestType.UV_WRITE); cpr.Callback = (status, cpr2) => { for (i = 0; i < n; ++i) { datagchandles[i].Free(); } PendingWrites--; Ensure.Success(status, callback); if (PendingWrites == 0) { OnDrain(); } }; var bufs = new uv_buf_t[n]; for (i = 0; i < n; ++i) { ArraySegment <byte> data = buffers[i]; int index = data.Offset; int count = data.Count; GCHandle datagchandle = GCHandle.Alloc(data.Array, GCHandleType.Pinned); var ptr = (IntPtr)(datagchandle.AddrOfPinnedObject().ToInt64() + index); bufs[i] = new uv_buf_t(ptr, count); datagchandles[i] = datagchandle; } int r = uv_write(cpr.Handle, NativeHandle, bufs, n, CallbackPermaRequest.CallbackDelegate); Ensure.Success(r); }
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); }
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); var buf = new uv_buf_t[] { new uv_buf_t(ptr, segment.Count) }; int r = uv_write2(cpr.Handle, NativeHandle, buf, 1, handle.NativeHandle, CallbackPermaRequest.CallbackDelegate); Ensure.Success(r); }
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); }
public void Shutdown(Action callback) { var cbr = new CallbackPermaRequest(RequestType.UV_SHUTDOWN); cbr.Callback = (status, _) => { Close(callback); }; uv_shutdown(cbr.Handle, NativeHandle, CallbackPermaRequest.StaticEnd); }
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); }
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); }