public unsafe void Write(byte[] datas, Int32 offset, Int32 count) { fixed(byte *p = datas) { UVIntrop.uv_buf_t[] mbuf = new UVIntrop.uv_buf_t[] { UVIntrop.buf_init((IntPtr)(p + offset), count) }; UVIntrop.try_write(this, mbuf, 1); } }
private unsafe static void UVReadCb(IntPtr handle, int nread, ref UVIntrop.uv_buf_t buf) { UVException ex; UVIntrop.Check(nread, out ex); UVStreamHandle target = FromIntPtr <UVStreamHandle>(handle); if (target == null) { throw new UVException("流已释放"); } target.mReadCallback(target, nread, ex, ref buf, target.mReadCallbackState); }
private static void UVAllocCb(IntPtr handle, int suggestedSize, out UVIntrop.uv_buf_t buf) { UVStreamHandle target = FromIntPtr <UVStreamHandle>(handle); if (target == null) { throw new UVException("流已释放"); } try { buf = target.mAllocCallback(target, suggestedSize, target.mAllocCallbackState); } catch (Exception ex) { //todo:清理操作 throw new UVException("分配内存出错," + ex.Message); } }