2012-01-03 14:33:31 -08:00
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
2018-07-26 15:36:45 -07:00
|
|
|
// Copyright (c) 2009-2018 The Bitcoin Core developers
|
2014-12-12 20:09:33 -08:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2012-05-18 07:02:28 -07:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2013-04-12 22:13:08 -07:00
|
|
|
|
2014-11-03 07:16:40 -08:00
|
|
|
#ifndef BITCOIN_COMPAT_H
|
|
|
|
#define BITCOIN_COMPAT_H
|
2012-01-03 14:33:31 -08:00
|
|
|
|
2014-11-25 23:19:07 -08:00
|
|
|
#if defined(HAVE_CONFIG_H)
|
2017-11-09 16:57:53 -08:00
|
|
|
#include <config/bitcoin-config.h>
|
2014-11-25 23:19:07 -08:00
|
|
|
#endif
|
|
|
|
|
2018-02-26 18:45:57 -08:00
|
|
|
#include <type_traits>
|
|
|
|
|
|
|
|
// GCC 4.8 is missing some C++11 type_traits,
|
|
|
|
// https://www.gnu.org/software/gcc/gcc-5/changes.html
|
2018-08-23 03:17:43 -07:00
|
|
|
#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 5
|
|
|
|
#define IS_TRIVIALLY_CONSTRUCTIBLE std::has_trivial_default_constructor
|
2018-02-26 18:45:57 -08:00
|
|
|
#else
|
2018-08-23 03:17:43 -07:00
|
|
|
#define IS_TRIVIALLY_CONSTRUCTIBLE std::is_trivially_default_constructible
|
2018-02-26 18:45:57 -08:00
|
|
|
#endif
|
|
|
|
|
2012-04-15 13:10:54 -07:00
|
|
|
#ifdef WIN32
|
2013-10-11 06:37:36 -07:00
|
|
|
#ifdef _WIN32_WINNT
|
|
|
|
#undef _WIN32_WINNT
|
|
|
|
#endif
|
2012-04-15 13:10:54 -07:00
|
|
|
#define _WIN32_WINNT 0x0501
|
2013-11-27 07:13:04 -08:00
|
|
|
#ifndef WIN32_LEAN_AND_MEAN
|
2012-04-15 13:10:54 -07:00
|
|
|
#define WIN32_LEAN_AND_MEAN 1
|
2013-11-27 07:13:04 -08:00
|
|
|
#endif
|
2012-04-15 13:10:54 -07:00
|
|
|
#ifndef NOMINMAX
|
|
|
|
#define NOMINMAX
|
|
|
|
#endif
|
2013-10-11 06:37:36 -07:00
|
|
|
#ifdef FD_SETSIZE
|
|
|
|
#undef FD_SETSIZE // prevent redefinition compiler warning
|
|
|
|
#endif
|
2013-04-25 16:05:35 -07:00
|
|
|
#define FD_SETSIZE 1024 // max number of fds in fd_set
|
2013-04-12 22:13:08 -07:00
|
|
|
|
|
|
|
#include <winsock2.h> // Must be included before mswsock.h and windows.h
|
|
|
|
|
|
|
|
#include <mswsock.h>
|
|
|
|
#include <windows.h>
|
2012-04-15 13:10:54 -07:00
|
|
|
#include <ws2tcpip.h>
|
2017-11-09 12:06:49 -08:00
|
|
|
#include <stdint.h>
|
2012-04-15 13:10:54 -07:00
|
|
|
#else
|
2018-01-12 03:21:47 -08:00
|
|
|
#include <fcntl.h>
|
2014-05-02 11:45:03 -07:00
|
|
|
#include <sys/mman.h>
|
2016-11-27 03:08:39 -08:00
|
|
|
#include <sys/select.h>
|
2014-05-02 11:45:03 -07:00
|
|
|
#include <sys/socket.h>
|
2013-11-22 05:22:53 -08:00
|
|
|
#include <sys/types.h>
|
2014-05-02 11:45:03 -07:00
|
|
|
#include <net/if.h>
|
|
|
|
#include <netinet/in.h>
|
2015-10-21 16:52:29 -07:00
|
|
|
#include <netinet/tcp.h>
|
2012-04-15 13:10:54 -07:00
|
|
|
#include <arpa/inet.h>
|
2013-04-12 22:13:08 -07:00
|
|
|
#include <ifaddrs.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <unistd.h>
|
2012-04-15 13:10:54 -07:00
|
|
|
#endif
|
|
|
|
|
2017-03-05 01:29:37 -08:00
|
|
|
#ifndef WIN32
|
2017-03-05 01:51:21 -08:00
|
|
|
typedef unsigned int SOCKET;
|
2017-11-09 16:57:53 -08:00
|
|
|
#include <errno.h>
|
2012-01-03 14:33:31 -08:00
|
|
|
#define WSAGetLastError() errno
|
|
|
|
#define WSAEINVAL EINVAL
|
|
|
|
#define WSAEALREADY EALREADY
|
|
|
|
#define WSAEWOULDBLOCK EWOULDBLOCK
|
|
|
|
#define WSAEMSGSIZE EMSGSIZE
|
|
|
|
#define WSAEINTR EINTR
|
|
|
|
#define WSAEINPROGRESS EINPROGRESS
|
|
|
|
#define WSAEADDRINUSE EADDRINUSE
|
|
|
|
#define WSAENOTSOCK EBADF
|
|
|
|
#define INVALID_SOCKET (SOCKET)(~0)
|
|
|
|
#define SOCKET_ERROR -1
|
|
|
|
#endif
|
|
|
|
|
2014-08-21 06:50:59 -07:00
|
|
|
#ifdef WIN32
|
|
|
|
#ifndef S_IRUSR
|
|
|
|
#define S_IRUSR 0400
|
|
|
|
#define S_IWUSR 0200
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#define MAX_PATH 1024
|
|
|
|
#endif
|
2017-11-09 12:06:49 -08:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#if !defined(ssize_t)
|
|
|
|
#ifdef _WIN64
|
|
|
|
typedef int64_t ssize_t;
|
|
|
|
#else
|
|
|
|
typedef int32_t ssize_t;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
2014-08-21 06:50:59 -07:00
|
|
|
|
2014-11-21 01:38:27 -08:00
|
|
|
#if HAVE_DECL_STRNLEN == 0
|
|
|
|
size_t strnlen( const char *start, size_t max_len);
|
|
|
|
#endif // HAVE_DECL_STRNLEN
|
|
|
|
|
2018-01-26 02:48:56 -08:00
|
|
|
#ifndef WIN32
|
|
|
|
typedef void* sockopt_arg_type;
|
|
|
|
#else
|
|
|
|
typedef char* sockopt_arg_type;
|
|
|
|
#endif
|
|
|
|
|
2017-07-18 07:24:46 -07:00
|
|
|
bool static inline IsSelectableSocket(const SOCKET& s) {
|
2015-07-09 15:23:27 -07:00
|
|
|
#ifdef WIN32
|
|
|
|
return true;
|
|
|
|
#else
|
2015-07-20 08:10:02 -07:00
|
|
|
return (s < FD_SETSIZE);
|
2015-07-09 15:23:27 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-11-03 07:16:40 -08:00
|
|
|
#endif // BITCOIN_COMPAT_H
|