Jake
Jake

Reputation: 2907

How does overlapped/asynchronous I/O work

Supposed I have something like this

readFile(.....&ol) //with overlapped

while(1){

////////.....
waitforsingleobject(//ol.hevent);

////

readfile(.....&ol)

}

I noticed that both readfiles read from the beginning of the file...why? In a normal readfile without overlapped/asynchronization the second readfile would start off where the first ended..

Upvotes: 0

Views: 1589

Answers (1)

Collin Dauphinee
Collin Dauphinee

Reputation: 13973

When using overlapped I/O on a file, you pass a pointer to an OVERLAPPED object, in this case ol.

The OVERLAPPED struct has two variables, Offset and OffsetHigh. These two variables are combined into a 64-bit integer, with Offset being the lower-order DWORD and OffsetHigh being the high-order DWORD, and used as the offset to perform the I/O operation at.

So, for example, if you wanted to start a ReadFile at the 8th byte of the file, you would set the Offset variable to 8 and the OffsetHigh variable to 0 before passing the OVERLAPPED to ReadFile.

Upvotes: 1

Related Questions