Roger Luo

超越梦想一起飞
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

C++ Asynchronous IO on Windows

Posted on 2013-03-05 15:25  Roger Luo  阅读(307)  评论(0编辑  收藏  举报

 

 

IO notification has 6 models
1. synchronous completion for “fast” I/O
2. polling
3. signaling the device kernel object directly
4. signaling an event object provided when I/O started
5. posting a packet to an I/O completion port
6. posting an APC to the initiating thread

Overlapped structure, using it to access the results of asynchronous I/O operation.

typedef struct _OVERLAPPED {
ULONG_PTR Internal;
ULONG_PTR InternalHigh;
union {
struct {
DWORD Offset;
DWORD OffsetHigh;
} DUMMYSTRUCTNAME;
PVOID Pointer;
} DUMMYUNIONNAME;

HANDLE hEvent;
} OVERLAPPED, *LPOVERLAPPED;

All of the members of the OVERLAPPED structure must be initialized to zero unless an event will be used to signal completion of an I/O operation. If an event is used, the hEvent member of the OVERLAPPED structure specifies a handle to the allocated event object. The system sets the state of the event object to nonsignaled when a call to the I/O function returns before the operation has been completed. The system sets the state of the event object to signaled when the operation has been completed. An event is needed only if there will be more than one outstanding I/O operation at the same time. If an event is not used, each completed I/O operation will signal the file, named pipe, or communications device.

Most of these fields are for system use only.