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