LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Strange behavior with posix async I/O (https://www.linuxquestions.org/questions/programming-9/strange-behavior-with-posix-async-i-o-635504/)

gsp 04-15-2008 10:11 AM

Strange behavior with posix async I/O
 
Hi - Any help with this one sure would be appreciated.

OS: Centos 5 Kernel 2.6.22
Compiler: Gnu C++

I'm using the posix async I/O routines (io_prep_pread, io_prep_pwrite, io_submit) to read and write some data files asynchronously, harvesting the completion status using io_getevents and I'm experiencing some behavior that I can't explain. If this is normal behavior, the "documentation" certainly hides it well.

The first maddening thing is that when I run my application in gdb, io_getevents continually returns a status of -4. (I think this is -EAGAIN) I'm calling it with my I/O context variable, a minimum event count of 1, a maximum of 10 and the timer parameter is NULL. So what's up with this? Why am I getting a -4 while in gdb? It makes it slightly more challenging to debug any problems. I DO eventually get a '1' when an outstanding I/O completes, so I've coded around this anomaly.

Next, (and more importantly) I'm getting odd behavior if I inadvertently try to read past the end of file. No, I shouldn't be trying to read past the end of file, but darn it, if I do try, the OS should TELL me that I had an end of file error. The problem is, when this event completes, the res and res2 fields of the io_event struct are zero. Zero tells me nothing, other than "there were zero bytes transferred". Well, yeah. But WHY? I should have some I/O status SOMEwhere that indicates the reason for the error, but I get nothing. Can anyone shed some light on this?

Thanks in advance.
Greg

jim mcnamara 04-16-2008 09:31 AM

From POSIX
Quote:

The errors reported by aio_error() and aio_return() include all of the
errors normally reported by read() and write() plus errors unique to
asynchronous I/O processing. After an asynchronous I/O operation is
started but before an error is detected or the operation completes
successfully, aio_error() will return EINPROGRESS.

Are you calling aio_return and aio_error?

gsp 04-17-2008 09:06 AM

Jim: Thanks for the reply.

No, I'm not calling those routines. There seems to be two "flavors" of asynch I/O. I'm using the interface defined in libaio.h by Benjamin LaHaise (not aio.h) Has libaio.h been deprecated in favor of this aio.h interface?

The only I/O completion context that I have is an iocb (not an aiocb). Similar in structure, but definitively different.

Greg


All times are GMT -5. The time now is 12:59 PM.