Anoncoin  0.9.4
P2P Digital Currency
compat.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2013 The Bitcoin developers
3 // Copyright (c) 2013-2014 The Anoncoin Core developers
4 // Distributed under the MIT/X11 software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #ifndef _ANONCOIN_COMPAT_H
8 #define _ANONCOIN_COMPAT_H
9 
10 #ifdef WIN32
11 #ifdef _WIN32_WINNT
12 #undef _WIN32_WINNT
13 #endif
14 #define _WIN32_WINNT 0x0501
15 #ifndef WIN32_LEAN_AND_MEAN
16 #define WIN32_LEAN_AND_MEAN 1
17 #endif
18 #ifndef NOMINMAX
19 #define NOMINMAX
20 #endif
21 #ifdef FD_SETSIZE
22 #undef FD_SETSIZE // prevent redefinition compiler warning
23 #endif
24 #define FD_SETSIZE 1024 // max number of fds in fd_set
25 
26 #include <winsock2.h> // Must be included before mswsock.h and windows.h
27 
28 #include <mswsock.h>
29 #include <windows.h>
30 #include <ws2tcpip.h>
31 #else
32 #include <sys/fcntl.h>
33 #include <sys/mman.h>
34 #include <sys/socket.h>
35 #include <sys/types.h>
36 #include <net/if.h>
37 #include <netinet/in.h>
38 #include <arpa/inet.h>
39 #include <ifaddrs.h>
40 #include <limits.h>
41 #include <netdb.h>
42 #include <unistd.h>
43 #endif
44 
45 #ifdef WIN32
46 #define MSG_DONTWAIT 0
47 #else
48 typedef u_int SOCKET;
49 #include "errno.h"
50 #define WSAGetLastError() errno
51 #define WSAEINVAL EINVAL
52 #define WSAEALREADY EALREADY
53 #define WSAEWOULDBLOCK EWOULDBLOCK
54 #define WSAEMSGSIZE EMSGSIZE
55 #define WSAEINTR EINTR
56 #define WSAEINPROGRESS EINPROGRESS
57 #define WSAEADDRINUSE EADDRINUSE
58 #define WSAENOTSOCK EBADF
59 #define INVALID_SOCKET (SOCKET)(~0)
60 #define SOCKET_ERROR -1
61 #endif
62 
63 inline int myclosesocket(SOCKET& hSocket)
64 {
65  if (hSocket == INVALID_SOCKET)
66  return WSAENOTSOCK;
67 #ifdef WIN32
68  int ret = closesocket(hSocket);
69 #else
70  int ret = close(hSocket);
71 #endif
72  hSocket = INVALID_SOCKET;
73  return ret;
74 }
75 #define closesocket(s) myclosesocket(s)
76 
77 
78 #endif
#define closesocket(s)
Definition: compat.h:75
u_int SOCKET
Definition: compat.h:48
#define INVALID_SOCKET
Definition: compat.h:59
int myclosesocket(SOCKET &hSocket)
Definition: compat.h:63
#define WSAENOTSOCK
Definition: compat.h:58