diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2017-10-07 05:15:39 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2017-10-07 05:15:39 +0000 |
commit | 2166e71091d68ce3f1462c78a7f1ede5548c265b (patch) | |
tree | 1118f24d361e71f1e15adf298c550cf4cc35f54e /src/sys | |
parent | d3303c219ea74b41301afa2c6dc9f43bcb4a91ed (diff) | |
parent | 6bb37041ba0c5be864eec71418fb65b91994ed7f (diff) | |
download | nix-2166e71091d68ce3f1462c78a7f1ede5548c265b.zip |
Merge #773
773: Add more accessors for AioCb r=asomers a=asomers
Diffstat (limited to 'src/sys')
-rw-r--r-- | src/sys/aio.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/sys/aio.rs b/src/sys/aio.rs index 22bd3959..4be0da7b 100644 --- a/src/sys/aio.rs +++ b/src/sys/aio.rs @@ -84,6 +84,11 @@ pub struct AioCb<'a> { } impl<'a> AioCb<'a> { + /// Returns the underlying file descriptor associated with the `AioCb` + pub fn fd(&self) -> RawFd { + self.aiocb.aio_fildes + } + /// Constructs a new `AioCb` with no associated buffer. /// /// The resulting `AioCb` structure is suitable for use with `AioCb::fsync`. @@ -239,6 +244,38 @@ impl<'a> AioCb<'a> { }) } + /// Returns the `aiocb`'s `LioOpcode` field + /// + /// If the value cannot be represented as an `LioOpcode`, returns `None` + /// instead. + pub fn lio_opcode(&self) -> Option<LioOpcode> { + match self.aiocb.aio_lio_opcode { + libc::LIO_READ => Some(LioOpcode::LIO_READ), + libc::LIO_WRITE => Some(LioOpcode::LIO_WRITE), + libc::LIO_NOP => Some(LioOpcode::LIO_NOP), + _ => None + } + } + + /// Returns the requested length of the aio operation in bytes + /// + /// This method returns the *requested* length of the operation. To get the + /// number of bytes actually read or written by a completed operation, use + /// `aio_return` instead. + pub fn nbytes(&self) -> usize { + self.aiocb.aio_nbytes + } + + /// Returns the file offset stored in the `AioCb` + pub fn offset(&self) -> off_t { + self.aiocb.aio_offset + } + + /// Returns the priority of the `AioCb` + pub fn priority(&self) -> libc::c_int { + self.aiocb.aio_reqprio + } + /// Asynchronously reads from a file descriptor into a buffer pub fn read(&mut self) -> Result<()> { assert!(self.mutable, "Can't read into an immutable buffer"); @@ -250,6 +287,11 @@ impl<'a> AioCb<'a> { }) } + /// Returns the `SigEvent` stored in the `AioCb` + pub fn sigevent(&self) -> SigEvent { + SigEvent::from(&self.aiocb.aio_sigevent) + } + /// Retrieve return status of an asynchronous operation. Should only be /// called once for each `AioCb`, after `AioCb::error` indicates that it has /// completed. The result is the same as for `read`, `write`, of `fsync`. |