Check for correct timeout error in cgsem_mswait
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
diff --git a/util.c b/util.c
index 2de5c1c..4c53df2 100644
--- a/util.c
+++ b/util.c
@@ -2472,7 +2472,7 @@ int _cgsem_mswait(cgsem_t *cgsem, int ms, const char *file, const char *func, co
timeraddspec(&abs_timeout, &ts_now);
ret = sem_timedwait(cgsem, &abs_timeout);
- if (unlikely(ret && ret != ETIMEDOUT))
+ if (unlikely(ret && !sock_timeout()))
quitfrom(1, file, func, line, "Failed to sem_timedwait errno=%d cgsem=0x%p", errno, cgsem);
return ret;
}
diff --git a/util.h b/util.h
index 0786065..8127e78 100644
--- a/util.h
+++ b/util.h
@@ -20,6 +20,10 @@
{
return (errno == EAGAIN || errno == EWOULDBLOCK);
}
+ static inline bool sock_timeout(void)
+ {
+ return (errno == ETIMEDOUT);
+ }
#elif defined WIN32
#include <ws2tcpip.h>
#include <winsock2.h>
@@ -37,6 +41,10 @@
{
return (WSAGetLastError() == WSAEWOULDBLOCK);
}
+ static inline bool sock_timeout(void)
+ {
+ return (WSAGetLastError() == WSAETIMEDOUT);
+ }
#ifndef SHUT_RDWR
#define SHUT_RDWR SD_BOTH
#endif