Re: ReadFile problem (overlapped I/O)
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Fri, 03 Aug 2007 13:48:24 -0400
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 soundJoseph M. Newcomer [MVP]
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
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Prev by Date: Re: CreateProcess() it's extermely slow
- Next by Date: Re: backward compatibility in Vista
- Previous by thread: Re: ReadFile problem (overlapped I/O)
- Next by thread: CreateProcess() it's extermely slow
- Index(es):
Relevant Pages
|