Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return how many bytes read/write from io_getevents #19

Open
Sasasu opened this issue Mar 19, 2019 · 1 comment
Open

Return how many bytes read/write from io_getevents #19

Sasasu opened this issue Mar 19, 2019 · 1 comment

Comments

@Sasasu
Copy link

Sasasu commented Mar 19, 2019

Linux's libaio put how many bytes read/write in io_event.res using a positive integer.
I did not find the document, but the kernel code proves that ╮( ̄▽ ̄)╭

https://github.com/torvalds/linux/blob/3717f613f48df0222311f974cf8a06c8a6c97bae/fs/aio.c#L1535-L1541

usually, it is the device block size, but actually, it is equal with the blocking system call read(2).

The simplest way is change fn retrieve_result(&mut self) -> Result<futures::Async<()>, io::Error> to fn retrieve_result(&mut self) -> Result<futures::Async<u64>, io::Error>

It will be a lot of broken change.

diff --git a/src/lib.rs b/src/lib.rs
index 537f6d8..0751418 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -207,7 +207,7 @@ impl AioBaseFuture {
 
     // Attempt to retrieve the result of a previously submitted I/O request; this may need to
     // wait until the I/O operation has been completed
-    fn retrieve_result(&mut self) -> Result<futures::Async<()>, io::Error> {
+    fn retrieve_result(&mut self) -> Result<futures::Async<u64>, io::Error> {
         // Check if we have received a notification indicating completion of the I/O request
         let result_code = match self.state.as_mut().unwrap().completed_receiver.poll() {
             Err(err) => return Err(io::Error::new(io::ErrorKind::Other, err)),
@@ -229,17 +229,17 @@ impl AioBaseFuture {
         if result_code < 0 {
             Err(io::Error::from_raw_os_error(result_code as i32))
         } else {
-            Ok(futures::Async::Ready(()))
+            Ok(futures::Async::Ready(result_code as u64))
         }
     }
 }
 
 // Common future base type for all asynchronous operations supperted by this API
 impl futures::Future for AioBaseFuture {
-    type Item = ();
+    type Item = u64;
     type Error = io::Error;
 
-    fn poll(&mut self) -> Result<futures::Async<()>, io::Error> {
+    fn poll(&mut self) -> Result<futures::Async<u64>, io::Error> {
         let result = self.submit_request();
 
         match result {
@@ -298,13 +298,13 @@ impl<ReadWriteHandle> futures::Future for AioReadResultFuture<ReadWriteHandle>
 where
     ReadWriteHandle: convert::AsMut<[u8]>,
 {
-    type Item = ReadWriteHandle;
+    type Item = (ReadWriteHandle, u64);
     type Error = AioError<ReadWriteHandle>;
 
     fn poll(&mut self) -> Result<futures::Async<Self::Item>, Self::Error> {
         self.base
             .poll()
-            .map(|val| val.map(|_| self.buffer.take().unwrap()))
+            .map(|val| val.map(|nbytes| (self.buffer.take().unwrap(), nbytes)))
             .map_err(|err| AioError {
                 buffer: self.buffer.take().unwrap(),
                 error: err,
@@ -329,13 +329,13 @@ impl<ReadOnlyHandle> futures::Future for AioWriteResultFuture<ReadOnlyHandle>
 where
     ReadOnlyHandle: convert::AsRef<[u8]>,
 {
-    type Item = ReadOnlyHandle;
+    type Item = (ReadOnlyHandle, u64);
     type Error = AioError<ReadOnlyHandle>;
 
     fn poll(&mut self) -> Result<futures::Async<Self::Item>, Self::Error> {
         self.base
             .poll()
-            .map(|val| val.map(|_| self.buffer.take().unwrap()))
+            .map(|val| val.map(|nbytes| (self.buffer.take().unwrap(), nbytes)))
             .map_err(|err| AioError {
                 buffer: self.buffer.take().unwrap(),
                 error: err,
@@ -353,7 +353,7 @@ pub struct AioSyncResultFuture
 
 impl futures::Future for AioSyncResultFuture
 {
-    type Item = ();
+    type Item = u64;
     type Error = io::Error;
 
     fn poll(&mut self) -> Result<futures::Async<Self::Item>, Self::Error> {
@ctsakthi
Copy link

Hello,
Can you please help me on this,

in Linux's libaio put how many bytes read/write in io_event.res using a positive integer.
If the io_event.res value is negative, it indicates some error.

In my case, it returns Zero, what does it mean? In the Application program how to handle that case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants