static void static_read(IntPtr stream, IntPtr nread, uv_buf_t buf) { int size = (int)nread; if (size < 0) { if ((int)buf.data != 0) { Marshal.FreeHGlobal(buf.data); } IntPtr shutdown = Marshal.AllocHGlobal(Sizes.ShutdownT); Util.CheckError(uv_shutdown(shutdown, stream, after_shutdown)); return; } if (size == 0) { Marshal.FreeHGlobal(buf.data); return; } byte[] data = new byte[size]; Marshal.Copy(buf.data, data, 0, size); var handle = (uv_handle_t)Marshal.PtrToStructure(stream, typeof(uv_handle_t)); var instance_gchandle = GCHandle.FromIntPtr(handle.data); var stream_instance = (UVStream)instance_gchandle.Target; stream_instance.HandleRead(data); Marshal.FreeHGlobal(buf.data); }
internal byte[] CopyAndDeleteBuffer(uv_buf_t buf, int size) { byte[] data = new byte[size > 0 ? size : 0]; if (size > 0) Marshal.Copy(buf.data, data, 0, size); this.DeleteBuffer(buf); return data; }
public void Write(byte[] data, int length) { IntPtr write_request = Marshal.AllocHGlobal(Sizes.WriteT); var dataptrhandle = GCHandle.Alloc(data, GCHandleType.Pinned); // This is not being freed, which needs to be fixed IntPtr dat = dataptrhandle.AddrOfPinnedObject(); uv_buf_t[] buf = new uv_buf_t[1]; buf[0].data = dat; #if __MonoCS__ buf[0].len = (IntPtr)length; #else buf[0].len = (ulong)length; #endif var req = (uv_req_t)Marshal.PtrToStructure(write_request, typeof(uv_req_t)); req.data = dat; Marshal.StructureToPtr(req, write_request, true); Util.CheckError(uv_write(write_request, this.handle, buf, 1, after_write)); }
internal void DeleteBuffer(uv_buf_t buffer) { if (buffer.data != IntPtr.Zero) buffer.data = _loop.BufferManager.Free(buffer.data); }
internal static extern int uv_write(IntPtr req, IntPtr handle, uv_buf_t[] bufs, int bufcnt, uv_write_cb cb);
internal static extern int uv_fs_write(IntPtr loop, IntPtr req, uv_file file, uv_buf_t[] bufs, int nbufs, long offset, uv_fs_cb cb);
private IntPtr Create(uv_req_type reqType, uv_buf_t buffer) { var requestHandle = _loop.Allocs.AllocRequest(reqType); uv_req_t request = new uv_req_t() { type = reqType, data = buffer.data }; Marshal.StructureToPtr(request, requestHandle, false); _writes.Add(requestHandle, buffer); return requestHandle; }
static void static_read(IntPtr stream, IntPtr nread, uv_buf_t buf) { int size = (int)nread; if (size < 0) { if ((int)buf.data != 0) Marshal.FreeHGlobal(buf.data); IntPtr shutdown = Marshal.AllocHGlobal(Sizes.ShutdownT); Util.CheckError(uv_shutdown(shutdown, stream, after_shutdown)); return; } if (size == 0) { Marshal.FreeHGlobal(buf.data); return; } byte[] data = new byte[size]; Marshal.Copy(buf.data, data, 0, size); var handle = (uv_handle_t)Marshal.PtrToStructure(stream, typeof(uv_handle_t)); var instance_gchandle = GCHandle.FromIntPtr(handle.data); var stream_instance = (UVStream)instance_gchandle.Target; stream_instance.HandleRead(data); Marshal.FreeHGlobal(buf.data); }
private void OnRead(IntPtr stream, IntPtr nread, uv_buf_t buf) { int size = (int) nread; if (size > 0) { var data = new byte[size]; Marshal.Copy(buf.data, data, 0, size); this.OnRead(data); } this.DeleteBuffer(buf); if(size < 0) this.Close(); }
internal void DeleteBuffer(uv_buf_t buffer) { if (buffer.data != IntPtr.Zero) buffer.data = this.Free(buffer.data); }