关于异步I/O请求被同步处理的问题。。
2009-12-09 22:40
513 查看
有些异步I/O请求会被同步处理。。比方说,你要读的内容正好在系统缓存中,那么就可以直接copy到你的缓存中,异步I/O请求就可以同步的处理。。于是,在我们coding的时候,就要把情况考虑周全。。
if (!ReadFile(hFile,
pDataBuf,
dwSizeOfBuffer,
&NumberOfBytesRead,
&osReadOperation )
{
if (GetLastError() != ERROR_IO_PENDING)
{
// Some other error occurred while reading the file.
ErrorReadingFile();
ExitProcess(0);
}
else
// Operation has been queued and
// will complete in the future.
fOverlapped = TRUE;
}
else
// Operation has completed immediately.
fOverlapped = FALSE;
if (fOverlapped)
{
// Wait for the operation to complete before continuing.
// You could do some background work if you wanted to.
if (GetOverlappedResult( hFile,
&osReadOperation,
&NumberOfBytesTransferred,
TRUE))
ReadHasCompleted(NumberOfBytesTransferred);
else
// Operation has completed, but it failed.
ErrorReadingFile();
}
else
ReadHasCompleted(NumberOfBytesRead);
以上函数,当ReadFile 和 WriteFile返回非零值表示这个异步I/O请求被同步的处理了。。
如果被异步处理了,或者出现error.返回false。。此时,我们必须调用GetLastError来确定是那种情况。若GetLastError返回ERROR_IO_PENDING,说明I/O请求被排入等待队列,将会被处理。。其他的返回值,说明出现了error..
if (!ReadFile(hFile,
pDataBuf,
dwSizeOfBuffer,
&NumberOfBytesRead,
&osReadOperation )
{
if (GetLastError() != ERROR_IO_PENDING)
{
// Some other error occurred while reading the file.
ErrorReadingFile();
ExitProcess(0);
}
else
// Operation has been queued and
// will complete in the future.
fOverlapped = TRUE;
}
else
// Operation has completed immediately.
fOverlapped = FALSE;
if (fOverlapped)
{
// Wait for the operation to complete before continuing.
// You could do some background work if you wanted to.
if (GetOverlappedResult( hFile,
&osReadOperation,
&NumberOfBytesTransferred,
TRUE))
ReadHasCompleted(NumberOfBytesTransferred);
else
// Operation has completed, but it failed.
ErrorReadingFile();
}
else
ReadHasCompleted(NumberOfBytesRead);
以上函数,当ReadFile 和 WriteFile返回非零值表示这个异步I/O请求被同步的处理了。。
如果被异步处理了,或者出现error.返回false。。此时,我们必须调用GetLastError来确定是那种情况。若GetLastError返回ERROR_IO_PENDING,说明I/O请求被排入等待队列,将会被处理。。其他的返回值,说明出现了error..
相关文章推荐
- 关于IOS9中NSURLConection的同步或异步发送请求过时问题。
- 关于jquery同步和异步请求问题总结
- 前端踩坑小结:多个异步请求在同一个函数里面执行时的同步问题之promise的用法。
- 关于rmanI/O同步异步问题
- 关于python的bottle框架跨域请求报错问题的处理
- 记阿里面试的一道nodejs中http同步处理请求问题
- 关于HTTP请求、Ajax请求,请求的同步和异步
- Struts2 拦截器处理同步(普通Http)请求和异步(post,ajax)请求时拦截配置
- 关于rmanI/O同步异步问题 推荐
- 关于Extjs异步session超时问题处理
- jquery ajax请求同步与异步问题
- 多个ajax请求的同步异步问题
- 网络处理(2)-异步POST请求和同步请求
- javascript Ajax 同步请求与异步请求的问题
- 关于springmvc处理跨域请求的问题
- 网络处理2-异步POST请求和同步请求
- 浅谈js的ajax的异步和同步请求的问题
- 关于Oracle DataGuard 同步 还是 异步 的问题
- 关于jfinal处理请求的流程问题
- Ajax异步请求,中文乱码问题处理