Files
@ r28024:510529c5fc82
Branch filter:
Location: cpp/openttd-patchpack/source/src/network/core/os_abstraction.h - annotation
r28024:510529c5fc82
4.4 KiB
text/x-c
Change: Use CARGO_LIST to show station cargo acceptance changes. (#11379)
This simplifies construction of the news message and allows for more than
two changes to be show in one line.
This simplifies construction of the news message and allows for more than
two changes to be show in one line.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r6121:a8ff6abe7fb2 r6121:a8ff6abe7fb2 r6121:a8ff6abe7fb2 r25351:31942544c033 r25351:31942544c033 r25351:31942544c033 r25351:31942544c033 r25351:31942544c033 r25351:31942544c033 r25351:31942544c033 r25351:31942544c033 r25351:31942544c033 r25351:31942544c033 r25351:31942544c033 r25351:31942544c033 r25351:31942544c033 r25351:31942544c033 r25351:31942544c033 r25686:fb6d0e17cffc r25351:31942544c033 r25351:31942544c033 r25351:31942544c033 r25351:31942544c033 r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r23088:6710c4c79ac6 r15377:73d1353690b1 r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r11562:5053c28cabcc r11562:5053c28cabcc r11562:5053c28cabcc r23857:d557d083443a r23857:d557d083443a r23857:d557d083443a r23857:d557d083443a r23857:d557d083443a r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r11571:db663bedabbd r23166:6e6fab1ad520 r23088:6710c4c79ac6 r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r27586:de8b0209a8bd r15142:8c4a39ffa5cb r14272:36cdf415cd1e r14272:36cdf415cd1e r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r23407:8313083e9002 r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r23407:8313083e9002 r23407:8313083e9002 r23407:8313083e9002 r23407:8313083e9002 r23407:8313083e9002 r27655:986c2bf7f296 r23407:8313083e9002 r23407:8313083e9002 r23407:8313083e9002 r5475:3f5cd13d1b63 r23407:8313083e9002 r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r5475:3f5cd13d1b63 r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r24439:3207de2680bf r25512:6d7fd1736081 r25512:6d7fd1736081 r25512:6d7fd1736081 r25512:6d7fd1736081 r25512:6d7fd1736081 r25512:6d7fd1736081 r25512:6d7fd1736081 r11363:6906c490a00e r5475:3f5cd13d1b63 r24441:8ae6bf969767 r24441:8ae6bf969767 r24441:8ae6bf969767 r24441:8ae6bf969767 r24441:8ae6bf969767 r24441:8ae6bf969767 r24441:8ae6bf969767 r24441:8ae6bf969767 r24441:8ae6bf969767 r24441:8ae6bf969767 r24441:8ae6bf969767 r24441:8ae6bf969767 r24441:8ae6bf969767 r24441:8ae6bf969767 r24441:8ae6bf969767 r24441:8ae6bf969767 r24441:8ae6bf969767 r24441:8ae6bf969767 r24441:8ae6bf969767 r24441:8ae6bf969767 r24441:8ae6bf969767 r24441:8ae6bf969767 r5475:3f5cd13d1b63 r25352:61444beef02a r25352:61444beef02a r25827:5a9ded1a0c1a r25352:61444beef02a r25288:32bdda38037d r11611:ffe270ad19c0 r24521:57ec498b9221 r24521:57ec498b9221 r11611:ffe270ad19c0 r5475:3f5cd13d1b63 | /*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file os_abstraction.h Network stuff has many things that needs to be
* included and/or implemented by default.
* All those things are in this file.
*/
#ifndef NETWORK_CORE_OS_ABSTRACTION_H
#define NETWORK_CORE_OS_ABSTRACTION_H
/**
* Abstraction of a network error where all implementation details of the
* error codes are encapsulated in this class and the abstraction layer.
*/
class NetworkError {
private:
int error; ///< The underlying error number from errno or WSAGetLastError.
mutable std::string message; ///< The string representation of the error (set on first call to #AsString).
public:
NetworkError(int error);
bool HasError() const;
bool WouldBlock() const;
bool IsConnectionReset() const;
bool IsConnectInProgress() const;
const std::string &AsString() const;
static NetworkError GetLast();
};
/* Include standard stuff per OS */
/* Windows stuff */
#if defined(_WIN32)
#include <errno.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>
/* Windows has some different names for some types */
typedef unsigned long in_addr_t;
/* Handle cross-compilation with --build=*-*-cygwin --host=*-*-mingw32 */
#if defined(__MINGW32__) && !defined(AI_ADDRCONFIG)
# define AI_ADDRCONFIG 0x00000400
#endif
#if !(defined(__MINGW32__) || defined(__CYGWIN__))
/* Windows has some different names for some types */
typedef SSIZE_T ssize_t;
typedef int socklen_t;
# define IPPROTO_IPV6 41
#endif /* !(__MINGW32__ && __CYGWIN__) */
#endif /* _WIN32 */
/* UNIX stuff */
#if defined(UNIX)
# if defined(OPENBSD) || defined(__NetBSD__)
# define AI_ADDRCONFIG 0
# endif
# define SOCKET int
# define INVALID_SOCKET -1
# define closesocket close
/* Need this for FIONREAD on solaris */
# define BSD_COMP
/* Includes needed for UNIX-like systems */
# include <unistd.h>
# include <sys/ioctl.h>
# include <sys/socket.h>
# include <netinet/in.h>
# include <netinet/tcp.h>
# include <arpa/inet.h>
# include <net/if.h>
# include <ifaddrs.h>
# if !defined(INADDR_NONE)
# define INADDR_NONE 0xffffffff
# endif
# if defined(__GLIBC__) && (__GLIBC__ <= 2) && (__GLIBC_MINOR__ <= 1)
typedef uint32_t in_addr_t;
# endif
# include <errno.h>
# include <sys/time.h>
# include <netdb.h>
# if defined(__EMSCRIPTEN__)
/* Emscripten doesn't support AI_ADDRCONFIG and errors out on it. */
# undef AI_ADDRCONFIG
# define AI_ADDRCONFIG 0
/* Emscripten says it supports FD_SETSIZE fds, but it really only supports 64.
* https://github.com/emscripten-core/emscripten/issues/1711 */
# undef FD_SETSIZE
# define FD_SETSIZE 64
# endif
/* Haiku says it supports FD_SETSIZE fds, but it really only supports 512. */
# if defined(__HAIKU__)
# undef FD_SETSIZE
# define FD_SETSIZE 512
# endif
#endif /* UNIX */
#ifdef __EMSCRIPTEN__
/**
* Emscripten doesn't set 'addrlen' for accept(), getsockname(), getpeername()
* and recvfrom(), which confuses other functions and causes them to crash.
* This function needs to be called after these four functions to make sure
* 'addrlen' is patched up.
*
* https://github.com/emscripten-core/emscripten/issues/12996
*
* @param address The address returned by those four functions.
* @return The correct value for addrlen.
*/
static inline socklen_t FixAddrLenForEmscripten(struct sockaddr_storage &address)
{
switch (address.ss_family) {
case AF_INET6: return sizeof(struct sockaddr_in6);
case AF_INET: return sizeof(struct sockaddr_in);
default: NOT_REACHED();
}
}
#endif
bool SetNonBlocking(SOCKET d);
bool SetNoDelay(SOCKET d);
bool SetReusePort(SOCKET d);
NetworkError GetSocketError(SOCKET d);
/* Make sure these structures have the size we expect them to be */
static_assert(sizeof(in_addr) == 4); ///< IPv4 addresses should be 4 bytes.
static_assert(sizeof(in6_addr) == 16); ///< IPv6 addresses should be 16 bytes.
#endif /* NETWORK_CORE_OS_ABSTRACTION_H */
|