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) { 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); }
private void Alloc(IntPtr data, int size, out uv_buf_t buf) { IntPtr ptr; size = Alloc(size, out ptr); buf = new uv_buf_t(ptr, size); }
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; var buf = new uv_buf_t[] { new uv_buf_t(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); } }
unsafe public int TryWrite(ArraySegment <byte> data) { CheckDisposed(); Ensure.ArgumentNotNull(data.Array !, "data"); fixed(byte *bytePtr = data.Array) { IntPtr ptr = (IntPtr)(bytePtr + data.Offset); var buf = new uv_buf_t[] { new uv_buf_t(ptr, data.Count) }; int r = uv_try_write(NativeHandle, buf, 1); Ensure.Success(r); return(r); } }
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(); }; var ptr = new IntPtr(datagchandle.AddrOfPinnedObject().ToInt64() + segment.Offset); var buf = new uv_buf_t[] { new uv_buf_t(ptr, segment.Count) }; int r = uv_fs_write(loop.NativeHandle, fsr.Handle, FileDescriptor, buf, segment.Count, offset, FileSystemRequest.CallbackDelegate); Ensure.Success(r); }
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, callback); }
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) { 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 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; uv_buf_t[] buf = new uv_buf_t[] { new uv_buf_t(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); }
private static void rcallback(IntPtr streamPointer, IntPtr size, ref uv_buf_t buf) { var stream = FromIntPtr <UVStream>(streamPointer); stream.rcallback(streamPointer, size); }
private static void recv_callback(IntPtr handlePointer, IntPtr nread, ref uv_buf_t buf, IntPtr sockaddr, ushort flags) { var handle = FromIntPtr <Udp>(handlePointer); handle.recv_callback(handlePointer, nread, sockaddr, flags); }