开发者

How does overlapped/asynchronous I/O work

开发者 https://www.devze.com 2023-02-23 23:21 出处:网络
Supposed I have something like this readFile(.....&ol) //with overlapped while(1){ ////////..... waitforsingleobject(//ol.hevent);

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..


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号