public void ReadStop() { if (!_GCHandle.IsAllocated) { return; } LibUv.ReadStop(this); LibUv.BufferStruct bufferStruct = LibUv.CreateBufferStruct(IntPtr.Zero, 0); UbReadCb(handle, 0, ref bufferStruct); }
public unsafe void Free(UvStreamHandle uvPipeHandle, UvStreamHandle sendHandle, Action <int, Exception, object> callBack, object state) { _callback = callBack; _state = state; try { _pins.Add(GCHandle.Alloc(this, GCHandleType.Normal)); LibUv.BufferStruct *ptr = (LibUv.BufferStruct *)((void *)_bufs); *ptr = LibUv.CreateBufferStruct(_bufferPoint, 4); LibUv.Write2(this, uvPipeHandle, ptr, 1, sendHandle, _Write_Callback); } catch { HandleFree(this); sendHandle.Dispose(); _callback = null; _state = null; throw; } }
private unsafe void Write(UvStreamHandle uvStreamHandle, byte[] buffer1, int buffer1StartIndex, int buffer1Offset, byte[] buffer2, int buffer2StartIndex, int buffer2Offset, Action <int, Exception, object> callBack, object state) { if (buffer1 == null || buffer1Offset < 1 || buffer1.Length < buffer1Offset + buffer1StartIndex) { throw new ArgumentNullException("buffer1"); } _callback = callBack; _state = state; try { _pins.Add(GCHandle.Alloc(this, GCHandleType.Normal)); LibUv.BufferStruct *ptr = (LibUv.BufferStruct *)((void *)_bufs); int nbufs = 0; GCHandle item = GCHandle.Alloc(buffer1, GCHandleType.Pinned); _pins.Add(item); //返回的是对象的“数据区”的起始地址 *ptr = LibUv.CreateBufferStruct(item.AddrOfPinnedObject() + buffer1StartIndex, buffer1Offset); nbufs++; if (buffer2 != null && buffer2Offset > 0) { if (buffer2.Length < buffer2Offset + buffer2StartIndex) { throw new ArgumentException("buffer2"); } item = GCHandle.Alloc(buffer2, GCHandleType.Pinned); _pins.Add(item); ptr[1] = LibUv.CreateBufferStruct(item.AddrOfPinnedObject() + buffer2StartIndex, buffer2Offset); nbufs++; } //int uv_write(uv_write_t* req, uv_stream_t* handle,uv_buf_t bufs[], int bufcnt, uv_write_cb cb); LibUv.Write(this, uvStreamHandle, ptr, nbufs, _Write_Callback); } catch { HandleFree(this); _callback = null; _state = null; throw; } }