aboutsummaryrefslogtreecommitdiff
path: root/src/compat.h
diff options
context:
space:
mode:
authorVasil Dimov <vd@FreeBSD.org>2020-12-04 15:11:25 +0100
committerVasil Dimov <vd@FreeBSD.org>2021-03-01 17:36:16 +0100
commit42c779f503eb8437b6232773a4a2472306cc9f3d (patch)
treeb8e4af2a0a315f717f13589b8f66db3926ac56e9 /src/compat.h
parentea1845315a109eb105113cb5fbb6f869e1cf010c (diff)
net: extend Sock with methods for robust send & read until terminator
Introduce two high level, convenience methods in the `Sock` class: * `SendComplete()`: keep trying to send the specified data until either successfully sent all of it, timeout or interrupted. * `RecvUntilTerminator()`: read until a terminator is encountered (never after it), timeout or interrupted. These will be convenient in the I2P SAM implementation. `SendComplete()` can also be used in the SOCKS5 implementation instead of calling `send()` directly.
Diffstat (limited to 'src/compat.h')
-rw-r--r--src/compat.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/compat.h b/src/compat.h
index 640be23546..3449bc2661 100644
--- a/src/compat.h
+++ b/src/compat.h
@@ -44,6 +44,7 @@ typedef unsigned int SOCKET;
#define WSAEINVAL EINVAL
#define WSAEALREADY EALREADY
#define WSAEWOULDBLOCK EWOULDBLOCK
+#define WSAEAGAIN EAGAIN
#define WSAEMSGSIZE EMSGSIZE
#define WSAEINTR EINTR
#define WSAEINPROGRESS EINPROGRESS
@@ -51,6 +52,14 @@ typedef unsigned int SOCKET;
#define WSAENOTSOCK EBADF
#define INVALID_SOCKET (SOCKET)(~0)
#define SOCKET_ERROR -1
+#else
+#ifndef WSAEAGAIN
+#ifdef EAGAIN
+#define WSAEAGAIN EAGAIN
+#else
+#define WSAEAGAIN WSAEWOULDBLOCK
+#endif
+#endif
#endif
#ifdef WIN32