winmad: return correct error code
authorshefty <shefty@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Wed, 2 Sep 2009 15:07:09 +0000 (15:07 +0000)
committershefty <shefty@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Wed, 2 Sep 2009 15:07:09 +0000 (15:07 +0000)
Winmad returns an incorrect error code when using send or receive in synchronous mode.  The OFED MAD code ends up working, since it checks for errors by comparing the return value < 0.  In this case, the return value us positive, when it should be zero.  Simplify the code and return the correct error code.

Signed-off-by: Sean Hefty <sean.hefty@intel.com>
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@2409 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

core/winmad/user/wm_provider.cpp
core/winmad/user/wm_provider.h

index fb5efea..96c20da 100644 (file)
@@ -148,46 +148,6 @@ WmDeviceIoControl(HANDLE hDevice, DWORD dwIoControlCode,
        return ret;\r
 }\r
 \r
-STDMETHODIMP_(BOOL) CWMProvider::\r
-WmReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,\r
-                  LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped)\r
-{\r
-       BOOL ret;\r
-\r
-       if (lpOverlapped == NULL) {\r
-               EnterCriticalSection(&m_CritSecRead);\r
-               ReadFile(hFile, lpBuffer, nNumberOfBytesToRead,\r
-                                lpNumberOfBytesRead, &m_OverlapRead);\r
-               ret = GetOverlappedResult(&m_OverlapRead, lpNumberOfBytesRead, TRUE);\r
-               LeaveCriticalSection(&m_CritSecRead);\r
-       } else {\r
-               ret = ReadFile(hFile, lpBuffer, nNumberOfBytesToRead,\r
-                                          lpNumberOfBytesRead, lpOverlapped);\r
-       }\r
-\r
-       return ret;\r
-}\r
-\r
-STDMETHODIMP_(BOOL) CWMProvider::\r
-WmWriteFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberIfBytesToWrite,\r
-                       LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped)\r
-{\r
-       BOOL ret;\r
-\r
-       if (lpOverlapped == NULL) {\r
-               EnterCriticalSection(&m_CritSecWrite);\r
-               WriteFile(hFile, lpBuffer, nNumberIfBytesToWrite,\r
-                                 lpNumberOfBytesWritten, &m_OverlapWrite);\r
-               ret = GetOverlappedResult(&m_OverlapWrite, lpNumberOfBytesWritten, TRUE);\r
-               LeaveCriticalSection(&m_CritSecWrite);\r
-       } else {\r
-               ret = WriteFile(hFile, lpBuffer, nNumberIfBytesToWrite,\r
-                                               lpNumberOfBytesWritten, lpOverlapped);\r
-       }\r
-\r
-       return ret;\r
-}\r
-\r
 STDMETHODIMP CWMProvider::\r
 Register(WM_REGISTER *pAttributes, UINT64 *pId)\r
 {\r
@@ -220,23 +180,43 @@ STDMETHODIMP CWMProvider::
 Send(WM_MAD *pMad, OVERLAPPED *pOverlapped)\r
 {\r
        DWORD bytes;\r
+       HRESULT hr;\r
 \r
-       if (WmWriteFile(m_hFile, pMad, (DWORD) sizeof(WM_MAD) + pMad->Length,\r
-                                       &bytes, pOverlapped)) {\r
-               return NOERROR;\r
+       bytes = (DWORD) sizeof(WM_MAD) + pMad->Length;\r
+       if (pOverlapped == NULL) {\r
+               EnterCriticalSection(&m_CritSecWrite);\r
+               WriteFile(m_hFile, pMad, bytes, &bytes, &m_OverlapWrite);\r
+               hr = GetOverlappedResult(&m_OverlapWrite, &bytes, TRUE);\r
+               LeaveCriticalSection(&m_CritSecWrite);\r
        } else {\r
-               return HRESULT_FROM_WIN32(GetLastError());\r
+               if (WriteFile(m_hFile, pMad, bytes, &bytes, pOverlapped)) {\r
+                       hr = NOERROR;\r
+               } else {\r
+                       hr = HRESULT_FROM_WIN32(GetLastError());\r
+               }\r
        }\r
+\r
+       return hr;\r
 }\r
 \r
 STDMETHODIMP CWMProvider::\r
 Receive(WM_MAD *pMad, SIZE_T BufferSize, OVERLAPPED *pOverlapped)\r
 {\r
        DWORD bytes;\r
+       HRESULT hr;\r
 \r
-       if (WmReadFile(m_hFile, pMad, (DWORD) BufferSize, &bytes, pOverlapped)) {\r
-               return NOERROR;\r
+       if (pOverlapped == NULL) {\r
+               EnterCriticalSection(&m_CritSecRead);\r
+               ReadFile(m_hFile, pMad, (DWORD) BufferSize, &bytes, &m_OverlapRead);\r
+               hr = GetOverlappedResult(&m_OverlapRead, &bytes, TRUE);\r
+               LeaveCriticalSection(&m_CritSecRead);\r
        } else {\r
-               return HRESULT_FROM_WIN32(GetLastError());\r
+               if (ReadFile(m_hFile, pMad, (DWORD) BufferSize, &bytes, pOverlapped)) {\r
+                       hr = NOERROR;\r
+               } else {\r
+                       hr = HRESULT_FROM_WIN32(GetLastError());\r
+               }\r
        }\r
+\r
+       return hr;\r
 }\r
index b75c2c2..47b23ad 100644 (file)
@@ -100,14 +100,6 @@ protected:
                                                                                  LPVOID lpOutBuffer, DWORD nOutBufferSize,\r
                                                                                  LPDWORD lpBytesReturned,\r
                                                                                  LPOVERLAPPED lpOverlapped);\r
-       STDMETHODIMP_(BOOL) WmReadFile(HANDLE hFile, LPVOID lpBuffer,\r
-                                                                  DWORD nNumberOfBytesToRead,\r
-                                                                  LPDWORD lpNumberOfBytesRead,\r
-                                                                  LPOVERLAPPED lpOverlapped);\r
-       STDMETHODIMP_(BOOL) WmWriteFile(HANDLE hFile, LPVOID lpBuffer,\r
-                                                                       DWORD nNumberIfBytesToWrite,\r
-                                                                       LPDWORD lpNumberOfBytesWritten,\r
-                                                                       LPOVERLAPPED lpOverlapped);\r
 \r
        OVERLAPPED                              m_OverlapWrite;\r
        OVERLAPPED                              m_OverlapRead;\r