OVERLAPPED
OVERLAPPED
un}; };
OVERLAPPED結構類型聲明如下:
typedef struct _OVERLAPPED {
ULONG_PTR Internal; //操作系統保留,指出一個和系統相關的狀態
ULONG_PTR InternalHigh; //指出發送或接收的數據長度
union {
struct {
DWORD Offset; //文件傳送的開始位置
DWORD OffsetHigh; //文件傳送的位元組偏移量的高位字
};
PVOID Pointer; //指針,指向文件傳送位置
};
HANDLE hEvent; //指定一個I/O操作完成後觸發的事件
} OVERLAPPED, *LPOVERLAPPED;
I/O設備處理必然讓主程序停下來乾等I/O的完成,解決這個問題,可以使用OVERLAPPED。
OVERLAPPED I/O是WIN32的一項技術,你可以要求操作系統為你傳送數據,並且在傳送完畢時通知你。這項技術使你的程序在I/O進行過程中仍然能夠繼續處理事務。事實上,操作系統內部正是以線程來I/O完成OVERLAPPED I/O。你可以獲得線程的所有利益,而不需付出什麼痛苦的代價。也就是說,OVERLAPPED主要是設置非同步I/O操作,非同步I/O操作是指應用程序可以在後台讀或者寫數據,而在前台做其他事情。
Allen denver在他的《Serial Communication in Win32》中是這樣解釋OVERLAPPED I/O的:我個人認為還是比較準確的
Overlapped I/O is not as straightforward as nonoverlapped I/O, but allows more flexibility and efficiency. A port open for overlapped operations allows multiple threads to do I/O operations at the same time and perform other work while the operations are pending. Furthermore, the behavior of overlapped operations allows a single thread to issue many different requests and do work in the background while the operations are pending.