Re: ReadFile problem (overlapped I/O)

Tech-Archive recommends: Fix windows errors by optimizing your registry



Well, several issues.

First, why is 63488 a meaningful number? Why is it not a #define somehwere?

Second, it is expected that after an asynchronous ReadFile it will return an error code,
the error specifically being ERROR_IO_PENDING, whose string value is the message you
describe. All this means is that the I/O is in transit and will complete at some future
time. If you "re-issue" the ReadFile, you will lose an entire 63488 bytes of data.

Also, if you do a WaitForSingleObject, you tend to defeat the advantage of overlapped I/O,
which is that you can be doing something else while it is running. If you don't need to
do anything else, you don't need overlapped I/O. And you should not be doing a
WaitForSingleObject in the main GUI thread. For anything with realtime, I try to avoid
blocking any thread unless it truly has nothing to do (instead of blocking it to wait for
something to finish).

My own preference is to use an I/O Completion Port and handle the I/O completion in a
separate thread, which means I treat ReadFile as a "fire-and-forget" operation that I
don't need to worry about once it has been issued.
joe


On Fri, 3 Aug 2007 07:42:02 -0700, Alan Williams-Key
<AlanWilliamsKey@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

My program is working OK on my PC (XP Home SP2+) where I need to read sound
files into memory before calling PlaySound. I use ReadFile.

I create the file handle using
CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED, NULL);

I read the file (asynchonously) using
ReadFile(hsoundfile, soundbuf[bufno], 63488, &nbytesread[bufno], &over);

(bufno is to identify one of two buffers that I use alternately)

I occasionally got a read failure and the error message was something like
"an overlapped I/O operation is being performed", which I didn't understand
because I thought I had set up the system to do overlapped I/O. But I cured
this by detecting the failure and making a second attempt if the first failed.

I am now trying this on another PC running Vista Home Basic and every
ReadFile fails with this error. What does it mean? How do I stop it from
failing?

Thanks

Alan

Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: problem with ReadFile using Overlapped I/O in VC++
    ... I suppose you call SetCommTimeouts, though you ommitted it in your code. ... Zero bytes read doesn't mean error. ... It's successful ReadFile call with zero ... I'm opening the com port using overlapped I/O, ...
    (microsoft.public.vc.mfc)
  • Re: ReadFile problem (overlapped I/O)
    ... I occasionally got a read failure and the error message was something like ... because I thought I had set up the system to do overlapped I/O. ... ReadFile fails with this error. ... completion ports or alertable IO or any other method of recieving ...
    (microsoft.public.vc.mfc)
  • Re: Asynchronous I/O development in CE
    ... The desktop model does not allow multiple threads to be in a call to ... ReadFile and WriteFile at the same time. ... Thus Overlapped I/O is not needed. ...
    (microsoft.public.windowsce.embedded)
  • Re: problem with ReadFile using Overlapped I/O in VC++
    ... No, the event should get signaled when the ReadFile completes the overlapped operation, no matter what the reason for the completion. ... So it could complete due to a timeout, or due to a comm error. ... You need timeouts to handle the case when data stops coming in for a while. ... That's needed with or without overlapped I/O. ...
    (microsoft.public.vc.mfc)