summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2021-01-21 22:28:11 +0100
committerMax Kellermann <max@musicpd.org>2021-01-21 22:28:11 +0100
commitd56a51cb5ea28836f76db76251787b8a1c44feb0 (patch)
treeaad0f015be92b16b45496941813bfaabe9e711bf /src/net
parent065a0c09f88e7157d24b53be8bf5f29d1127c0d0 (diff)
parent9e2d09dabc5abc8cc98c339c6fd34c769125096c (diff)
Merge branch 'v0.22.x'
Diffstat (limited to 'src/net')
-rw-r--r--src/net/SocketError.hxx73
1 files changed, 69 insertions, 4 deletions
diff --git a/src/net/SocketError.hxx b/src/net/SocketError.hxx
index 8e8db1ddf..44989c52f 100644
--- a/src/net/SocketError.hxx
+++ b/src/net/SocketError.hxx
@@ -52,14 +52,79 @@ GetSocketError() noexcept
#endif
}
-gcc_const
-static inline bool
-IsSocketErrorAgain(socket_error_t code) noexcept
+constexpr bool
+IsSocketErrorInProgress(socket_error_t code) noexcept
{
#ifdef _WIN32
return code == WSAEINPROGRESS;
#else
- return code == EAGAIN;
+ return code == EINPROGRESS;
+#endif
+}
+
+constexpr bool
+IsSocketErrorWouldBlock(socket_error_t code) noexcept
+{
+#ifdef _WIN32
+ return code == WSAEWOULDBLOCK;
+#else
+ return code == EWOULDBLOCK;
+#endif
+}
+
+constexpr bool
+IsSocketErrorConnectWouldBlock(socket_error_t code) noexcept
+{
+#if defined(_WIN32) || defined(__linux__)
+ /* on Windows, WSAEINPROGRESS is for blocking sockets and
+ WSAEWOULDBLOCK for non-blocking sockets */
+ /* on Linux, EAGAIN==EWOULDBLOCK is for local sockets and
+ EINPROGRESS is for all other sockets */
+ return IsSocketErrorInProgress(code) || IsSocketErrorWouldBlock(code);
+#else
+ /* on all other operating systems, there's just EINPROGRESS */
+ return IsSocketErrorInProgress(code);
+#endif
+}
+
+constexpr bool
+IsSocketErrorSendWouldBlock(socket_error_t code) noexcept
+{
+#ifdef _WIN32
+ /* on Windows, WSAEINPROGRESS is for blocking sockets and
+ WSAEWOULDBLOCK for non-blocking sockets */
+ return IsSocketErrorInProgress(code) || IsSocketErrorWouldBlock(code);
+#else
+ /* on all other operating systems, there's just EAGAIN==EWOULDBLOCK */
+ return IsSocketErrorWouldBlock(code);
+#endif
+}
+
+constexpr bool
+IsSocketErrorReceiveWouldBlock(socket_error_t code) noexcept
+{
+#ifdef _WIN32
+ /* on Windows, WSAEINPROGRESS is for blocking sockets and
+ WSAEWOULDBLOCK for non-blocking sockets */
+ return IsSocketErrorInProgress(code) || IsSocketErrorWouldBlock(code);
+#else
+ /* on all other operating systems, there's just
+ EAGAIN==EWOULDBLOCK */
+ return IsSocketErrorWouldBlock(code);
+#endif
+}
+
+constexpr bool
+IsSocketErrorAcceptWouldBlock(socket_error_t code) noexcept
+{
+#ifdef _WIN32
+ /* on Windows, WSAEINPROGRESS is for blocking sockets and
+ WSAEWOULDBLOCK for non-blocking sockets */
+ return IsSocketErrorInProgress(code) || IsSocketErrorWouldBlock(code);
+#else
+ /* on all other operating systems, there's just
+ EAGAIN==EWOULDBLOCK */
+ return IsSocketErrorWouldBlock(code);
#endif
}