LCOV - code coverage report
Current view: top level - src - compat.h (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 2 2 100.0 %
Date: 2020-09-26 01:30:44 Functions: 1 1 100.0 %

          Line data    Source code
       1             : // Copyright (c) 2009-2010 Satoshi Nakamoto
       2             : // Copyright (c) 2009-2018 The Bitcoin Core developers
       3             : // Distributed under the MIT software license, see the accompanying
       4             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       5             : 
       6             : #ifndef BITCOIN_COMPAT_H
       7             : #define BITCOIN_COMPAT_H
       8             : 
       9             : #if defined(HAVE_CONFIG_H)
      10             : #include <config/bitcoin-config.h>
      11             : #endif
      12             : 
      13             : #ifdef WIN32
      14             : #ifndef NOMINMAX
      15             : #define NOMINMAX
      16             : #endif
      17             : #ifdef FD_SETSIZE
      18             : #undef FD_SETSIZE // prevent redefinition compiler warning
      19             : #endif
      20             : #define FD_SETSIZE 1024 // max number of fds in fd_set
      21             : 
      22             : #include <winsock2.h>     // Must be included before mswsock.h and windows.h
      23             : 
      24             : #include <mswsock.h>
      25             : #include <windows.h>
      26             : #include <ws2tcpip.h>
      27             : #include <stdint.h>
      28             : #else
      29             : #include <fcntl.h>
      30             : #include <sys/mman.h>
      31             : #include <sys/select.h>
      32             : #include <sys/socket.h>
      33             : #include <sys/types.h>
      34             : #include <net/if.h>
      35             : #include <netinet/in.h>
      36             : #include <netinet/tcp.h>
      37             : #include <arpa/inet.h>
      38             : #include <ifaddrs.h>
      39             : #include <limits.h>
      40             : #include <netdb.h>
      41             : #include <unistd.h>
      42             : #endif
      43             : 
      44             : #ifndef WIN32
      45             : typedef unsigned int SOCKET;
      46             : #include <errno.h>
      47             : #define WSAGetLastError()   errno
      48             : #define WSAEINVAL           EINVAL
      49             : #define WSAEALREADY         EALREADY
      50             : #define WSAEWOULDBLOCK      EWOULDBLOCK
      51             : #define WSAEMSGSIZE         EMSGSIZE
      52             : #define WSAEINTR            EINTR
      53             : #define WSAEINPROGRESS      EINPROGRESS
      54             : #define WSAEADDRINUSE       EADDRINUSE
      55             : #define WSAENOTSOCK         EBADF
      56             : #define INVALID_SOCKET      (SOCKET)(~0)
      57             : #define SOCKET_ERROR        -1
      58             : #endif
      59             : 
      60             : #ifdef WIN32
      61             : #ifndef S_IRUSR
      62             : #define S_IRUSR             0400
      63             : #define S_IWUSR             0200
      64             : #endif
      65             : #else
      66             : #define MAX_PATH            1024
      67             : #endif
      68             : #ifdef _MSC_VER
      69             : #if !defined(ssize_t)
      70             : #ifdef _WIN64
      71             : typedef int64_t ssize_t;
      72             : #else
      73             : typedef int32_t ssize_t;
      74             : #endif
      75             : #endif
      76             : #endif
      77             : 
      78             : #if HAVE_DECL_STRNLEN == 0
      79             : size_t strnlen( const char *start, size_t max_len);
      80             : #endif // HAVE_DECL_STRNLEN
      81             : 
      82             : #ifndef WIN32
      83             : typedef void* sockopt_arg_type;
      84             : #else
      85             : typedef char* sockopt_arg_type;
      86             : #endif
      87             : 
      88             : // Note these both should work with the current usage of poll, but best to be safe
      89             : // WIN32 poll is broken https://daniel.haxx.se/blog/2012/10/10/wsapoll-is-broken/
      90             : // __APPLE__ poll is broke https://github.com/bitcoin/bitcoin/pull/14336#issuecomment-437384408
      91             : #if defined(__linux__)
      92             : #define USE_POLL
      93             : #endif
      94             : 
      95        1235 : bool static inline IsSelectableSocket(const SOCKET& s) {
      96             : #if defined(USE_POLL) || defined(WIN32)
      97             :     return true;
      98             : #else
      99        1235 :     return (s < FD_SETSIZE);
     100             : #endif
     101             : }
     102             : 
     103             : #endif // BITCOIN_COMPAT_H

Generated by: LCOV version 1.15