summaryrefslogtreecommitdiff
path: root/src/sys
diff options
context:
space:
mode:
authorAlan Somers <asomers@gmail.com>2017-09-17 22:06:03 -0600
committerAlan Somers <asomers@gmail.com>2017-10-02 21:39:18 -0600
commit6bb37041ba0c5be864eec71418fb65b91994ed7f (patch)
tree0c09a635296cee3cfb0cb12fdb361daa4a422b40 /src/sys
parent9f4db8a494398226d4feda72ea2c4ed25fa03364 (diff)
downloadnix-6bb37041ba0c5be864eec71418fb65b91994ed7f.zip
Add more accessors for AioCb
Diffstat (limited to 'src/sys')
-rw-r--r--src/sys/aio.rs42
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`.