Update Bugreport Links
[bitcoinplatinum.git] / src / compat.h
blob79ebb9323a63f8285df49b8277035835f091c4bd
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2012 The Bitcoin developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #ifndef _BITCOIN_COMPAT_H
6 #define _BITCOIN_COMPAT_H 1
8 #ifdef WIN32
9 #define _WIN32_WINNT 0x0501
10 #define WIN32_LEAN_AND_MEAN 1
11 #ifndef NOMINMAX
12 #define NOMINMAX
13 #endif
14 #include <winsock2.h>
15 #include <mswsock.h>
16 #include <ws2tcpip.h>
17 #else
18 #include <sys/types.h>
19 #include <sys/socket.h>
20 #include <sys/fcntl.h>
21 #include <arpa/inet.h>
22 #include <netdb.h>
23 #include <net/if.h>
24 #include <netinet/in.h>
25 #include <ifaddrs.h>
26 #endif
28 typedef u_int SOCKET;
29 #ifdef WIN32
30 #define MSG_NOSIGNAL 0
31 #define MSG_DONTWAIT 0
32 typedef int socklen_t;
33 #else
34 #include "errno.h"
35 #define WSAGetLastError() errno
36 #define WSAEINVAL EINVAL
37 #define WSAEALREADY EALREADY
38 #define WSAEWOULDBLOCK EWOULDBLOCK
39 #define WSAEMSGSIZE EMSGSIZE
40 #define WSAEINTR EINTR
41 #define WSAEINPROGRESS EINPROGRESS
42 #define WSAEADDRINUSE EADDRINUSE
43 #define WSAENOTSOCK EBADF
44 #define INVALID_SOCKET (SOCKET)(~0)
45 #define SOCKET_ERROR -1
46 #endif
48 inline int myclosesocket(SOCKET& hSocket)
50 if (hSocket == INVALID_SOCKET)
51 return WSAENOTSOCK;
52 #ifdef WIN32
53 int ret = closesocket(hSocket);
54 #else
55 int ret = close(hSocket);
56 #endif
57 hSocket = INVALID_SOCKET;
58 return ret;
60 #define closesocket(s) myclosesocket(s)
63 #endif