[ofw] [PATCH] winmad: Add proper check for IO pending

Hefty, Sean sean.hefty at intel.com
Wed Sep 21 14:09:20 PDT 2011


ReadFile and WriteFile may complete asynchronously.  Add a check for ERROR_IO_PENDING if the read or write calls return non-zero.  If the last error is IO pending, then we need to wait for the operation to complete by calling GetOverlappedResult.

Signed-off-by: Sean Hefty <sean.hefty at intel.com>
---
This has been committed to svn, which is far less painful going to the ofa server.

Index: winmad/user/wm_provider.cpp
===================================================================
--- winmad/user/wm_provider.cpp	(revision 3269)
+++ winmad/user/wm_provider.cpp	(working copy)
@@ -190,7 +190,8 @@
 	bytes = (DWORD) sizeof(WM_MAD) + pMad->Length;
 	if (pOverlapped == NULL) {
 		EnterCriticalSection(&m_CritSecWrite);
-		if (WriteFile(m_hFile, pMad, bytes, &bytes, &m_OverlapWrite)) {
+		if (WriteFile(m_hFile, pMad, bytes, NULL, &m_OverlapWrite) ||
+			(GetLastError() == ERROR_IO_PENDING)) {
 			hr = GetOverlappedResult(&m_OverlapWrite, &bytes, TRUE);
 		} else {
 			hr = HRESULT_FROM_WIN32(GetLastError());
@@ -215,7 +216,8 @@
 
 	if (pOverlapped == NULL) {
 		EnterCriticalSection(&m_CritSecRead);
-		if (ReadFile(m_hFile, pMad, (DWORD) BufferSize, &bytes, &m_OverlapRead)) {
+		if (ReadFile(m_hFile, pMad, (DWORD) BufferSize, NULL, &m_OverlapRead) ||
+			(GetLastError() == ERROR_IO_PENDING)) {
 			hr = GetOverlappedResult(&m_OverlapRead, &bytes, TRUE);
 		} else {
 			hr = HRESULT_FROM_WIN32(GetLastError());



More information about the ofw mailing list