42 COverlapReader(
void) : m_hFile(INVALID_HANDLE_VALUE), m_hEvent(NULL), m_isOverLapping(false)
51 if ( m_hEvent != NULL )
53 ::CloseHandle(m_hEvent);
63 void Attach(HANDLE hFile,
size_t size)
78 m_hFile = INVALID_HANDLE_VALUE;
91 size_t Read(LPVOID _P, DWORD wait = 0)
95 if ( m_hFile != INVALID_HANDLE_VALUE && m_work.
GetSize() > 0 )
97 if ( m_isOverLapping )
100 r = m_GetResult(wait);
108 r = m_GetResult(wait);
111 if ( r != INVALID_SIZE && r != 0 )
130 virtual bool OnRead(HANDLE hFile, LPVOID _P,
size_t size, OVERLAPPED& overLapped)
133 bool r = !! ::ReadFile(hFile, _P, size, &d, &overLapped);
134 return r && (size == d);
148 size_t m_Read(
size_t size, LPVOID _P)
152 if ( m_hEvent == NULL )
154 m_hEvent = ::CreateEvent(NULL, FALSE, TRUE, NULL);
155 ::ResetEvent(m_hEvent);
157 m_overLapped.hEvent = m_hEvent;
158 DWORD work = ULONG_MAX;
159 if (
OnRead(m_hFile, _P, size, m_overLapped) )
164 else if ( ::GetLastError() == ERROR_IO_PENDING )
168 if( ::GetOverlappedResult(m_hFile, &m_overLapped, &work, FALSE) )
172 else if ( ::GetLastError() == ERROR_IO_INCOMPLETE )
174 m_isOverLapping =
true;
187 size_t m_GetResult(DWORD wait = 0)
189 if ( ! m_isOverLapping )
193 size_t result = INVALID_SIZE;
195 switch ( ::WaitForSingleObject(m_overLapped.hEvent, wait) )
198 if ( ::GetOverlappedResult(m_hFile, &m_overLapped, &r, FALSE) )
221 if ( m_isOverLapping )
224 m_isOverLapping =
false;
228 bool m_isOverLapping;
229 OVERLAPPED m_overLapped;
265 m_dwIoControlCode = code;
278 virtual bool OnRead(HANDLE hFile, LPVOID _P,
size_t size, OVERLAPPED& overLapped)
281 BOOL ret = ::DeviceIoControl(hFile, m_dwIoControlCode, _P, size, _P, size, &dwByteReturn, &overLapped);
285 DWORD m_dwIoControlCode;
virtual bool OnRead(HANDLE hFile, LPVOID _P, size_t size, OVERLAPPED &overLapped)
[通知] 読込み.
COverlapIoReader(void)
コンストラクタ
void SetIoControlCode(DWORD code)
[設定] コントロールコード設定.
virtual bool OnRead(HANDLE hFile, LPVOID _P, size_t size, OVERLAPPED &overLapped)
[通知] 読込み.
size_t Read(LPVOID _P, DWORD wait=0)
[読込] 読込み.
void Detach(void)
[設定] デタッチ.
COverlapReader(void)
コンストラクタ
~COverlapReader(void)
デストラクタ
void Attach(HANDLE hFile, size_t size)
[設定] アタッチ.
size_t GetSize(void) const
[取得] サイズ取得
void Resize(size_t l)
[設定] サイズ再設定
const TYP * Ref(void) const
[取得] ポインタ取得
#define EXCLUSIVE(CLS)
簡易排他制御マクロ.
void Zero(V &value)
[設定] ゼロクリア.