public void SendFile(int out_fd, int in_fd, long offset, long length, Action <long, int> callback) { Libeio.sendfile(out_fd, in_fd, offset, length, (arg1, arg2) => { outstanding.Enqueue(() => callback(arg1, arg2)); pulse.Send(); }); }
public void Write(int fd, byte[] buffer, long offset, long length, Action <int, int> callback) { Libeio.write(fd, buffer, offset, length, (arg1, arg2) => { outstanding.Enqueue(() => callback(arg1, arg2)); pulse.Send(); }); }
public void Read(int fd, byte[] buffer, long offset, long length, Action <int, byte[], int> callback) { Libeio.read(fd, buffer, offset, length, (arg1, arg2, arg3) => { outstanding.Enqueue(() => callback(arg1, arg2, arg3)); pulse.Send(); }); }
void OpenFile() { Libeio.open(file, OpenFlags.O_RDONLY, FilePermissions.ALLPERMS, (fd, err) => { this.sourceFd = fd; if (fd == -1) { completed = true; Console.Error.WriteLine("Error sending file '{0}' errno: '{1}'", file, err); } else { Libeio.fstat(fd, (r, stat, error) => { if (r == -1) { completed = true; } else { length = stat.st_size; target.ResumeWriting(); } }); } }); }
public override void Close() { if (Handle != IntPtr.Zero) { Libeio.close(Handle.ToInt32(), OnCloseDone); Handle = IntPtr.Zero; } base.Close(); }
void ReadNextBuffer() { if (!readEnabled) { return; } var length = (int)Math.Min(readBuffer.Length, readLimit); Libeio.read(Handle.ToInt32(), readBuffer, position, length, OnReadDone); }
protected override int WriteSingleBuffer(ByteBuffer buffer) { var bytes = buffer.Bytes; if (buffer.Position > 0) { bytes = new byte[buffer.Length]; Array.Copy(buffer.Bytes, buffer.Position, bytes, 0, buffer.Length); } Libeio.write(Handle.ToInt32(), bytes, position, buffer.Length, OnWriteDone); return(buffer.Length); }
void SendNextBlock() { Libeio.sendfile(target.Handle.ToInt32(), sourceFd, position, length - position, (len, err) => { if (len >= 0) { position += len; } else { completed = true; } if (position == length) { completed = true; } target.ResumeWriting(); }); }
void CloseFile() { Libeio.close(sourceFd, err => { }); sourceFd = 0; }