Remove headers.h
[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 license.txt 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 #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 <ifaddrs.h>
25 #endif
26 #ifdef BSD
27 #include <netinet/in.h>
28 #endif
29
30 typedef u_int SOCKET;
31 #ifdef WIN32
32 #define MSG_NOSIGNAL        0
33 #define MSG_DONTWAIT        0
34 typedef int socklen_t;
35 #else
36 #include "errno.h"
37 #define WSAGetLastError()   errno
38 #define WSAEINVAL           EINVAL
39 #define WSAEALREADY         EALREADY
40 #define WSAEWOULDBLOCK      EWOULDBLOCK
41 #define WSAEMSGSIZE         EMSGSIZE
42 #define WSAEINTR            EINTR
43 #define WSAEINPROGRESS      EINPROGRESS
44 #define WSAEADDRINUSE       EADDRINUSE
45 #define WSAENOTSOCK         EBADF
46 #define INVALID_SOCKET      (SOCKET)(~0)
47 #define SOCKET_ERROR        -1
48 #endif
49
50 inline int myclosesocket(SOCKET& hSocket)
51 {
52     if (hSocket == INVALID_SOCKET)
53         return WSAENOTSOCK;
54 #ifdef WIN32
55     int ret = closesocket(hSocket);
56 #else
57     int ret = close(hSocket);
58 #endif
59     hSocket = INVALID_SOCKET;
60     return ret;
61 }
62 #define closesocket(s)      myclosesocket(s)
63
64
65 #endif