Author: mturk Date: Thu Sep 3 20:29:36 2009 New Revision: 811108 URL: http://svn.apache.org/viewvc?rev=811108&view=rev Log: Make sure ACR_GET_OS_ERROR always returns non zero
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h?rev=811108&r1=811107&r2=811108&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h (original) +++ commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h Thu Sep 3 20:29:36 2009 @@ -1366,16 +1366,37 @@ /** @} */ #if defined(WIN32) && !defined(DOXYGEN) +/** + * Special version of GetLastError that never returns 0 + * If GetLastError is zero, ERROR_RETRY (EAGAIN) is returned instead. + * Make sure you call ACR_GET_OS_ERROR only when error happens. + */ +static __inline DWORD _SysGetLastError() +{ + DWORD err = GetLastError(); + return err == ERROR_SUCCESS ? ERROR_RETRY : err; +} + +/** + * Special version of WSAGetLastError that never returns 0 + * If WSAGetLastError is zero, WSAEWOULDBLOCK (EAGAIN) is returned instead. + * Make sure you call ACR_GET_NETOS_ERROR only when error happens. + */ +static __inline DWORD _NetGetLastError() +{ + DWORD err = WSAGetLastError(); + return err == ERROR_SUCCESS ? WSAEWOULDBLOCK : err; +} #define ACR_FROM_OS_ERROR(e) (e == 0 ? ACR_SUCCESS : e + ACR_OS_START_SYSERR) #define ACR_TO_OS_ERROR(e) (e == 0 ? ACR_SUCCESS : e - ACR_OS_START_SYSERR) -#define ACR_GET_OS_ERROR() (ACR_FROM_OS_ERROR(GetLastError())) +#define ACR_GET_OS_ERROR() (ACR_FROM_OS_ERROR(_SysGetLastError())) #define ACR_SET_OS_ERROR(e) (SetLastError(ACR_TO_OS_ERROR(e))) /* A special case, only socket calls require this: */ -#define ACR_GET_NETOS_ERROR() (ACR_FROM_OS_ERROR(WSAGetLastError())) +#define ACR_GET_NETOS_ERROR() (ACR_FROM_OS_ERROR(_NetGetLastError())) #define ACR_SET_NETOS_ERROR(e) (WSASetLastError(ACR_TO_OS_ERROR(e))) /* ACR CANONICAL ERROR TESTS */ @@ -1437,6 +1458,7 @@ || (s) == ACR_OS_START_SYSERR + ERROR_NESTING_NOT_ALLOWED \ || (s) == ACR_OS_START_SYSERR + ERROR_MAX_THRDS_REACHED \ || (s) == ACR_OS_START_SYSERR + ERROR_LOCK_VIOLATION \ + || (s) == ACR_OS_START_SYSERR + ERROR_RETRY \ || (s) == ACR_OS_START_SYSERR + WSAEWOULDBLOCK) #define ACR_STATUS_IS_EINTR(s) ((s) == ACR_EINTR \ || (s) == ACR_OS_START_SYSERR + WSAEINTR) @@ -1485,12 +1507,12 @@ #define ACR_FROM_OS_ERROR(e) (e) #define ACR_TO_OS_ERROR(e) (e) -#define ACR_GET_OS_ERROR() (errno) +#define ACR_GET_OS_ERROR() (errno ? errno : EAGAIN) #define ACR_SET_OS_ERROR(e) (errno = (e)) /* A special case, only socket calls require this: */ -#define ACR_GET_NETOS_ERROR() (errno) +#define ACR_GET_NETOS_ERROR() (errno ? errno : EAGAIN) #define ACR_SET_NETOS_ERROR(e) (errno = (e)) /**