ua_log_socket_error.h 833 B

1234567891011121314151617181920212223242526272829303132333435
  1. /* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  2. * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
  3. #ifndef UA_LOG_SOCKET_ERROR_H_
  4. #define UA_LOG_SOCKET_ERROR_H_
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. #ifdef _WIN32
  9. #include <winsock2.h>
  10. #define UA_LOG_SOCKET_ERRNO_WRAP(LOG) { \
  11. char *errno_str = NULL; \
  12. FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, \
  13. NULL, WSAGetLastError(), \
  14. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), \
  15. (LPSTR)&errno_str, 0, NULL); \
  16. LOG; \
  17. LocalFree(errno_str); \
  18. }
  19. #else
  20. #define UA_LOG_SOCKET_ERRNO_WRAP(LOG) { \
  21. char *errno_str = strerror(errno); \
  22. LOG; \
  23. }
  24. #endif
  25. #ifdef __cplusplus
  26. } // extern "C"
  27. #endif
  28. #endif /* UA_LOG_SOCKET_ERROR_H_ */