Update License in File Headers
[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 typedef u_int SOCKET;
9 #ifdef WIN32
10 #define MSG_NOSIGNAL        0
11 #define MSG_DONTWAIT        0
12 typedef int socklen_t;
13 #else
14 #include "errno.h"
15 #define WSAGetLastError()   errno
16 #define WSAEINVAL           EINVAL
17 #define WSAEALREADY         EALREADY
18 #define WSAEWOULDBLOCK      EWOULDBLOCK
19 #define WSAEMSGSIZE         EMSGSIZE
20 #define WSAEINTR            EINTR
21 #define WSAEINPROGRESS      EINPROGRESS
22 #define WSAEADDRINUSE       EADDRINUSE
23 #define WSAENOTSOCK         EBADF
24 #define INVALID_SOCKET      (SOCKET)(~0)
25 #define SOCKET_ERROR        -1
26 #endif
27
28 inline int myclosesocket(SOCKET& hSocket)
29 {
30     if (hSocket == INVALID_SOCKET)
31         return WSAENOTSOCK;
32 #ifdef WIN32
33     int ret = closesocket(hSocket);
34 #else
35     int ret = close(hSocket);
36 #endif
37     hSocket = INVALID_SOCKET;
38     return ret;
39 }
40 #define closesocket(s)      myclosesocket(s)
41
42 #endif