3c95e373493d97f66bb36ea7f121373bc7f9d4e0
[novacoin.git] / src / compat.h
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
7
8 #ifdef WIN32
9 #define _WIN32_WINNT 0x0501
10 #define WIN32_LEAN_AND_MEAN 1
11 #ifndef NOMINMAX
12 #define NOMINMAX
13 #endif
14 #ifndef _MSC_VER
15 #ifdef FD_SETSIZE
16 #undef FD_SETSIZE
17 #endif
18 #define FD_SETSIZE 1024 // max number of fds in fd_set
19 #endif
20 #include <winsock2.h>
21 #include <mswsock.h>
22 #include <ws2tcpip.h>
23 #else
24 #include <sys/types.h>
25 #include <sys/socket.h>
26 #include <sys/fcntl.h>
27 #include <arpa/inet.h>
28 #include <netdb.h>
29 #include <net/if.h>
30 #include <netinet/in.h>
31 #include <ifaddrs.h>
32
33 typedef u_int SOCKET;
34 #endif
35
36 #ifdef WIN32
37 #define MSG_NOSIGNAL        0
38 #define MSG_DONTWAIT        0
39 typedef int socklen_t;
40 #else
41 #include "errno.h"
42 #define WSAGetLastError()   errno
43 #define WSAEINVAL           EINVAL
44 #define WSAEALREADY         EALREADY
45 #define WSAEWOULDBLOCK      EWOULDBLOCK
46 #define WSAEMSGSIZE         EMSGSIZE
47 #define WSAEINTR            EINTR
48 #define WSAEINPROGRESS      EINPROGRESS
49 #define WSAEADDRINUSE       EADDRINUSE
50 #define WSAENOTSOCK         EBADF
51 #define INVALID_SOCKET      (SOCKET)(~0)
52 #define SOCKET_ERROR        -1
53 #endif
54
55 inline int myclosesocket(SOCKET& hSocket)
56 {
57     if (hSocket == INVALID_SOCKET)
58         return WSAENOTSOCK;
59 #ifdef WIN32
60     int ret = closesocket(hSocket);
61 #else
62     int ret = close(hSocket);
63 #endif
64     hSocket = INVALID_SOCKET;
65     return ret;
66 }
67 #define closesocket(s)      myclosesocket(s)
68
69
70 #endif