aboutsummaryrefslogtreecommitdiff
path: root/src/common/util.h
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2003-08-14 17:13:52 +0000
committerNick Mathewson <nickm@torproject.org>2003-08-14 17:13:52 +0000
commitcd3467bb01cb5bd98b2978fb50bdaa2f3227c980 (patch)
treed91d3689a009c3fa358bae94e883240e83fcb642 /src/common/util.h
parent88edae94076cc39d40a39f80b2d6ddadc88fe324 (diff)
downloadtor-cd3467bb01cb5bd98b2978fb50bdaa2f3227c980.tar
tor-cd3467bb01cb5bd98b2978fb50bdaa2f3227c980.tar.gz
Attempt to make sockets code work right on windows.
svn:r398
Diffstat (limited to 'src/common/util.h')
-rw-r--r--src/common/util.h28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/common/util.h b/src/common/util.h
index 3569632e9..0590f8ed7 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -13,6 +13,12 @@
#ifdef HAVE_TIME_H
#include <time.h>
#endif
+#if _MSC_VER > 1300
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#elif defined(_MSC_VER)
+#include <winsock.h>
+#endif
#ifndef HAVE_GETTIMEOFDAY
#ifdef HAVE_FTIME
#define USING_FAKE_TIMEVAL
@@ -23,7 +29,7 @@
#endif
#endif
-#ifdef _MSC_VER
+#ifdef MS_WINDOWS
/* Windows names string functions funnily. */
#define strncasecmp strnicmp
#define strcasecmp stricmp
@@ -55,4 +61,24 @@ void spawn_exit();
int tor_socketpair(int family, int type, int protocol, int fd[2]);
+/* For stupid historical reasons, windows sockets have an independent set of
+ * errnos which they use as the fancy strikes them.
+ */
+#ifdef MS_WINDOWS
+#define ERRNO_EAGAIN(e) ((e) == EAGAIN || \
+ (e) == WSAEWOULDBLOCK || \
+ (e) == EWOULDBLOCK)
+#define ERRNO_EINPROGRESS(e) ((e) == EINPROGRESS || \
+ (e) == WSAEINPROGRESS)
+#define ERRNO_CONN_EINPROGRESS(e) ((e) == EINPROGRESS || \
+ (e) == WSAEINPROGRESS || (e) == WSAEINVAL)
+int correct_socket_errno(int s);
+#else
+#define ERRNO_EAGAIN(e) ((e) == EAGAIN)
+#define ERRNO_EINPROGRESS(e) ((e) == EINPROGRESS)
+#define ERRNO_CONN_EINPROGRESS(e) ((e) == EINPROGRESS)
+#define correct_socket_errno(s) (errno)
+#endif
+
+
#endif