Exemple #1
0
        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;
        }
        public void Write(byte[] data, int offset, int length)
        {
            var requestHandle = this.Alloc(uv_req_type.UV_WRITE);
            uv_buf_t buffer = CreateBuffer(data, offset, length);
            uv_req_t request = new uv_req_t()
            {
                type = uv_req_type.UV_WRITE,
                data = buffer.data
            };

            Marshal.StructureToPtr(request, requestHandle, false);

            try
            {
                CheckError((Uvi.uv_write(requestHandle, this.Handle, new[] { buffer }, 1, this.OnWrite)));
                _writes.Add(requestHandle, buffer);
            }
            catch (Exception)
            {
                this.Free(requestHandle);
                this.DeleteBuffer(buffer);
                throw;
            }
        }