aboutsummaryrefslogtreecommitdiff
path: root/src/unittest
ModeNameSize
-rw-r--r--CMakeLists.txt1275logplain
-rw-r--r--test.cpp18178logplain
-rw-r--r--test.h5903logplain
-rw-r--r--test_areastore.cpp4232logplain
-rw-r--r--test_collision.cpp5235logplain
-rw-r--r--test_compression.cpp4902logplain
-rw-r--r--test_connection.cpp8761logplain
-rw-r--r--test_filepath.cpp7928logplain
-rw-r--r--test_inventory.cpp3085logplain
-rw-r--r--test_keycode.cpp3341logplain
-rw-r--r--test_map_settings_manager.cpp7962logplain
-rw-r--r--test_mapnode.cpp1685logplain
-rw-r--r--test_nodedef.cpp1901logplain
-rw-r--r--test_noderesolver.cpp6652logplain
-rw-r--r--test_noise.cpp14699logplain
-rw-r--r--test_objdef.cpp2782logplain
-rw-r--r--test_player.cpp2709logplain
-rw-r--r--test_profiler.cpp1844logplain
-rw-r--r--test_random.cpp10526logplain
-rw-r--r--test_schematic.cpp8331logplain
-rw-r--r--test_serialization.cpp20359logplain
-rw-r--r--test_settings.cpp5842logplain
-rw-r--r--test_socket.cpp3932logplain
-rw-r--r--test_threading.cpp4383logplain
-rw-r--r--test_utilities.cpp9053logplain
-rw-r--r--test_voxelalgorithms.cpp7874logplain
-rw-r--r--test_voxelmanipulator.cpp3157logplain
span class="hl ppc">#include "constants.h" #include "debug.h" #include "settings.h" #include "log.h" #ifdef _WIN32 // Without this some of the network functions are not found on mingw #ifndef _WIN32_WINNT #define _WIN32_WINNT 0x0501 #endif #include <windows.h> #include <winsock2.h> #include <ws2tcpip.h> #define LAST_SOCKET_ERR() WSAGetLastError() typedef SOCKET socket_t; typedef int socklen_t; #else #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <fcntl.h> #include <netdb.h> #include <unistd.h> #include <arpa/inet.h> #define LAST_SOCKET_ERR() (errno) typedef int socket_t; #endif // Set to true to enable verbose debug output bool socket_enable_debug_output = false; // yuck static bool g_sockets_initialized = false; // Initialize sockets void sockets_init() { #ifdef _WIN32 // Windows needs sockets to be initialized before use WSADATA WsaData; if (WSAStartup(MAKEWORD(2, 2), &WsaData) != NO_ERROR) throw SocketException("WSAStartup failed"); #endif g_sockets_initialized = true; } void sockets_cleanup() { #ifdef _WIN32 // On Windows, cleanup sockets after use WSACleanup(); #endif } /* UDPSocket */ UDPSocket::UDPSocket(bool ipv6) { init(ipv6, false); } bool UDPSocket::init(bool ipv6, bool noExceptions) { if (!g_sockets_initialized) { dstream << "Sockets not initialized" << std::endl; return false; } // Use IPv6 if specified m_addr_family = ipv6 ? AF_INET6 : AF_INET; m_handle = socket(m_addr_family, SOCK_DGRAM, IPPROTO_UDP); if (socket_enable_debug_output) { dstream << "UDPSocket(" << (int)m_handle << ")::UDPSocket(): ipv6 = " << (ipv6 ? "true" : "false") << std::endl; } if (m_handle <= 0) { if (noExceptions) { return false; } throw SocketException(std::string("Failed to create socket: error ") + itos(LAST_SOCKET_ERR())); } setTimeoutMs(0); if (m_addr_family == AF_INET6) { // Allow our socket to accept both IPv4 and IPv6 connections // required on Windows: // https://msdn.microsoft.com/en-us/library/windows/desktop/bb513665(v=vs.85).aspx int value = 0; setsockopt(m_handle, IPPROTO_IPV6, IPV6_V6ONLY, reinterpret_cast<char *>(&value), sizeof(value)); } return true; } UDPSocket::~UDPSocket() { if (socket_enable_debug_output) { dstream << "UDPSocket( " << (int)m_handle << ")::~UDPSocket()" << std::endl; } #ifdef _WIN32 closesocket(m_handle); #else close(m_handle); #endif } void UDPSocket::Bind(Address addr) { if (socket_enable_debug_output) { dstream << "UDPSocket(" << (int)m_handle << ")::Bind(): " << addr.serializeString() << ":" << addr.getPort() << std::endl; } if (addr.getFamily() != m_addr_family) { static const char *errmsg = "Socket and bind address families do not match"; errorstream << "Bind failed: " << errmsg << std::endl; throw SocketException(errmsg); } if (m_addr_family == AF_INET6) { struct sockaddr_in6 address; memset(&address, 0, sizeof(address)); address = addr.getAddress6(); address.sin6_family = AF_INET6; address.sin6_port = htons(addr.getPort()); if (bind(m_handle, (const struct sockaddr *)&address, sizeof(struct sockaddr_in6)) < 0) { dstream << (int)m_handle << ": Bind failed: " << strerror(errno) << std::endl; throw SocketException("Failed to bind socket"); } } else { struct sockaddr_in address; memset(&address, 0, sizeof(address)); address = addr.getAddress(); address.sin_family = AF_INET; address.sin_port = htons(addr.getPort());