mirror of
https://github.com/ValveSoftware/GameNetworkingSockets.git
synced 2026-05-29 16:20:34 +00:00
Improve platform compatibility
Replace a bunch of non-standard defines with standard ones Don't #define POSIX in public header or test for it. Fixes #228. (We shoulkd probably also make this change to Steamworks headers.) Use IsLinux(), IsPosix(), etc instead of #ifdef LINUX or #ifdef POSIX Moved some platform socket stuff out of steamnetworkingsockets_platform.h and into platform_sockets.h. (none of this is actually particular to steamnetworkingsockets.) Some platforms don't have IPv6 support.
This commit is contained in:
+3
-3
@@ -158,11 +158,11 @@ function(set_target_common_gns_properties TGT)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(CMAKE_SYSTEM_NAME MATCHES Linux)
|
if(CMAKE_SYSTEM_NAME MATCHES Linux)
|
||||||
target_compile_definitions(${TGT} PUBLIC POSIX LINUX)
|
target_compile_definitions(${TGT} PUBLIC LINUX)
|
||||||
elseif(CMAKE_SYSTEM_NAME MATCHES Darwin)
|
elseif(CMAKE_SYSTEM_NAME MATCHES Darwin)
|
||||||
target_compile_definitions(${TGT} PUBLIC POSIX OSX)
|
target_compile_definitions(${TGT} PUBLIC OSX)
|
||||||
elseif(CMAKE_SYSTEM_NAME MATCHES FreeBSD)
|
elseif(CMAKE_SYSTEM_NAME MATCHES FreeBSD)
|
||||||
target_compile_definitions(${TGT} PUBLIC POSIX FREEBSD)
|
target_compile_definitions(${TGT} PUBLIC FREEBSD)
|
||||||
elseif(CMAKE_SYSTEM_NAME MATCHES Windows)
|
elseif(CMAKE_SYSTEM_NAME MATCHES Windows)
|
||||||
target_compile_definitions(${TGT} PUBLIC _WINDOWS)
|
target_compile_definitions(${TGT} PUBLIC _WINDOWS)
|
||||||
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
#include <steam/steam_api.h>
|
#include <steam/steam_api.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
#include <windows.h> // Ug, for NukeProcess -- see below
|
#include <windows.h> // Ug, for NukeProcess -- see below
|
||||||
#else
|
#else
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -43,7 +43,7 @@ SteamNetworkingMicroseconds g_logTimeZero;
|
|||||||
// down the thread that is reading from stdin.
|
// down the thread that is reading from stdin.
|
||||||
static void NukeProcess( int rc )
|
static void NukeProcess( int rc )
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
ExitProcess( rc );
|
ExitProcess( rc );
|
||||||
#else
|
#else
|
||||||
(void)rc; // Unused formal parameter
|
(void)rc; // Unused formal parameter
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
#include <steam/isteamnetworkingutils.h>
|
#include <steam/isteamnetworkingutils.h>
|
||||||
#include <steam/steamnetworkingcustomsignaling.h>
|
#include <steam/steamnetworkingcustomsignaling.h>
|
||||||
|
|
||||||
#ifdef POSIX
|
#ifdef VALVE_POSIX
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|||||||
@@ -17,11 +17,13 @@
|
|||||||
typedef unsigned char uint8;
|
typedef unsigned char uint8;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined( __GNUC__ ) && !defined(_WIN32) && !defined(POSIX)
|
#if ( defined(POSIX) || defined(_POSIX_VERSION) || ( defined( __GNUC__ ) && !defined(_WIN32) ) ) && !defined(VALVE_POSIX)
|
||||||
|
#define VALVE_POSIX 1
|
||||||
|
#endif
|
||||||
|
#ifdef __GNUC__
|
||||||
#if __GNUC__ < 4
|
#if __GNUC__ < 4
|
||||||
#error "Steamworks requires GCC 4.X (4.2 or 4.4 have been tested)"
|
#error "Steamworks requires GCC 4.X (4.2 or 4.4 have been tested)"
|
||||||
#endif
|
#endif
|
||||||
#define POSIX 1
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__LP64__) || defined(__x86_64__) || defined(_WIN64) || defined(__aarch64__) || defined(__s390x__)
|
#if defined(__LP64__) || defined(__x86_64__) || defined(_WIN64) || defined(__aarch64__) || defined(__s390x__)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
#define _X86INTRIN_H_INCLUDED
|
#define _X86INTRIN_H_INCLUDED
|
||||||
#endif
|
#endif
|
||||||
#include "winlite.h"
|
#include "winlite.h"
|
||||||
#elif defined(POSIX)
|
#elif IsPosix()
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -397,7 +397,7 @@ void CCrypto::GenerateRandomBlock( void *pvDest, int cubDest )
|
|||||||
bool bRtlGenRandomOK = s_pfnRtlGenRandom && ( s_pfnRtlGenRandom( pubDest, (unsigned long)cubDest ) == TRUE );
|
bool bRtlGenRandomOK = s_pfnRtlGenRandom && ( s_pfnRtlGenRandom( pubDest, (unsigned long)cubDest ) == TRUE );
|
||||||
AssertFatal( bRtlGenRandomOK );
|
AssertFatal( bRtlGenRandomOK );
|
||||||
|
|
||||||
#elif defined(POSIX)
|
#elif IsPosix()
|
||||||
|
|
||||||
// Reading from /dev/urandom is threadsafe, but possibly slow due to a kernel
|
// Reading from /dev/urandom is threadsafe, but possibly slow due to a kernel
|
||||||
// spinlock or mutex protecting access to the internal PRNG state. In theory,
|
// spinlock or mutex protecting access to the internal PRNG state. In theory,
|
||||||
|
|||||||
@@ -85,7 +85,7 @@
|
|||||||
|
|
||||||
// Linux had a few areas where it didn't construct objects in the same order that Windows does.
|
// Linux had a few areas where it didn't construct objects in the same order that Windows does.
|
||||||
// So when CVProfile::CVProfile() would access g_pMemAlloc, it would crash because the allocator wasn't initalized yet.
|
// So when CVProfile::CVProfile() would access g_pMemAlloc, it would crash because the allocator wasn't initalized yet.
|
||||||
#if defined( GNUC ) || defined ( COMPILER_GCC ) || defined( COMPILER_SNC )
|
#if defined( __GNUC__ ) || defined ( COMPILER_GCC ) || defined( COMPILER_SNC )
|
||||||
#define CONSTRUCT_EARLY __attribute__((init_priority(101)))
|
#define CONSTRUCT_EARLY __attribute__((init_priority(101)))
|
||||||
#else
|
#else
|
||||||
#define CONSTRUCT_EARLY
|
#define CONSTRUCT_EARLY
|
||||||
@@ -93,7 +93,7 @@
|
|||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define SELECTANY __declspec(selectany)
|
#define SELECTANY __declspec(selectany)
|
||||||
#elif defined(GNUC) || defined ( COMPILER_GCC ) || defined( COMPILER_SNC )
|
#elif defined(__GNUC__) || defined ( COMPILER_GCC ) || defined( COMPILER_SNC )
|
||||||
#define SELECTANY __attribute__((weak))
|
#define SELECTANY __attribute__((weak))
|
||||||
#else
|
#else
|
||||||
#define SELECTANY static
|
#define SELECTANY static
|
||||||
@@ -105,7 +105,7 @@
|
|||||||
#if defined(_WIN32) && !defined(_XBOX)
|
#if defined(_WIN32) && !defined(_XBOX)
|
||||||
#define PLAT_DECL_EXPORT __declspec( dllexport )
|
#define PLAT_DECL_EXPORT __declspec( dllexport )
|
||||||
#define PLAT_DECL_IMPORT __declspec( dllimport )
|
#define PLAT_DECL_IMPORT __declspec( dllimport )
|
||||||
#elif defined(GNUC) || defined(COMPILER_GCC)
|
#elif defined(__GNUC__) || defined(COMPILER_GCC)
|
||||||
#define PLAT_DECL_EXPORT __attribute__((visibility("default")))
|
#define PLAT_DECL_EXPORT __attribute__((visibility("default")))
|
||||||
#define PLAT_DECL_IMPORT
|
#define PLAT_DECL_IMPORT
|
||||||
#elif defined(_XBOX) || defined(COMPILER_SNC)
|
#elif defined(_XBOX) || defined(COMPILER_SNC)
|
||||||
@@ -156,7 +156,7 @@
|
|||||||
#define __stdcall __attribute__ ((__stdcall__))
|
#define __stdcall __attribute__ ((__stdcall__))
|
||||||
#endif
|
#endif
|
||||||
#define FASTCALL
|
#define FASTCALL
|
||||||
#elif defined(POSIX)
|
#elif IsPosix()
|
||||||
#define __stdcall
|
#define __stdcall
|
||||||
#define __cdecl
|
#define __cdecl
|
||||||
#define STDCALL
|
#define STDCALL
|
||||||
@@ -167,7 +167,7 @@
|
|||||||
#define NOINLINE __declspec(noinline)
|
#define NOINLINE __declspec(noinline)
|
||||||
#define NORETURN __declspec(noreturn)
|
#define NORETURN __declspec(noreturn)
|
||||||
#define FORCEINLINE __forceinline
|
#define FORCEINLINE __forceinline
|
||||||
#elif defined(GNUC) || defined(COMPILER_GCC) || defined(COMPILER_SNC)
|
#elif defined(__GNUC__) || defined(COMPILER_GCC) || defined(COMPILER_SNC)
|
||||||
#define NOINLINE __attribute__ ((noinline))
|
#define NOINLINE __attribute__ ((noinline))
|
||||||
#define NORETURN __attribute__ ((noreturn))
|
#define NORETURN __attribute__ ((noreturn))
|
||||||
#if defined(COMPILER_GCC) || defined(COMPILER_SNC)
|
#if defined(COMPILER_GCC) || defined(COMPILER_SNC)
|
||||||
|
|||||||
@@ -48,10 +48,6 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ( defined(LINUX) || defined(OSX) || defined(ANDROID) ) && !defined(POSIX)
|
|
||||||
#define POSIX
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(_WIN32) && !defined(WINDED)
|
#if defined(_WIN32) && !defined(WINDED)
|
||||||
#if defined(_M_IX86)
|
#if defined(_M_IX86)
|
||||||
#define __i386__ 1
|
#define __i386__ 1
|
||||||
@@ -110,6 +106,10 @@
|
|||||||
#define IsRetail() false
|
#define IsRetail() false
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef IsPosix
|
||||||
|
#error "Too soon"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
#define IsRelease() false
|
#define IsRelease() false
|
||||||
#define IsDebug() true
|
#define IsDebug() true
|
||||||
@@ -122,29 +122,41 @@
|
|||||||
#define IsXboxOne() true
|
#define IsXboxOne() true
|
||||||
#define IsConsole() true
|
#define IsConsole() true
|
||||||
#elif defined( NN_NINTENDO_SDK )
|
#elif defined( NN_NINTENDO_SDK )
|
||||||
#if !defined(POSIX) && !defined(_WIN32)
|
#ifndef _WIN32
|
||||||
#define POSIX
|
#define IsPosix() true
|
||||||
#endif
|
#endif
|
||||||
#define IsNintendoSwitch() true
|
#define IsNintendoSwitch() true
|
||||||
#define IsConsole() true
|
#define IsConsole() true
|
||||||
#elif defined( _PS5 )
|
#elif defined( __PROSPERO__ )
|
||||||
#ifndef POSIX
|
#define IsPosix() true
|
||||||
#define POSIX
|
|
||||||
#endif
|
|
||||||
#define IsPS5() true
|
#define IsPS5() true
|
||||||
#define IsConsole() true
|
#define IsConsole() true
|
||||||
|
#elif defined( __ORBIS__ )
|
||||||
|
#define IsPosix() true
|
||||||
|
#define IsPS4() true
|
||||||
|
#define IsConsole() true
|
||||||
#elif defined( _WIN32 )
|
#elif defined( _WIN32 )
|
||||||
#define IsWindows() true
|
#define IsWindows() true
|
||||||
#define IsPC() true
|
#define IsPC() true
|
||||||
#elif defined(POSIX)
|
#elif defined( __ANDROID__ ) || defined( ANDROID )
|
||||||
#define IsPC() true
|
#define IsAndroid() true
|
||||||
#ifdef LINUX
|
#define IsPosix() true
|
||||||
#define IsLinux() true
|
#elif defined(__APPLE__)
|
||||||
#endif
|
#include <TargetConditionals.h>
|
||||||
#ifdef OSX
|
#if defined( TARGET_OS_MAC )
|
||||||
#define SUPPORTS_IOPOLLINGHELPER
|
#define SUPPORTS_IOPOLLINGHELPER
|
||||||
#define IsOSX() true
|
#define IsOSX() true
|
||||||
|
#define IsPosix() true
|
||||||
|
//#elif defined( TARGET_OS_IPHONE )
|
||||||
|
#else
|
||||||
|
#error "Unsupported platform"
|
||||||
#endif
|
#endif
|
||||||
|
#elif defined( LINUX ) || defined( __LINUX__ ) || defined(linux) || defined(__linux) || defined(__linux__)
|
||||||
|
#define IsLinux() true
|
||||||
|
#define IsPosix() true
|
||||||
|
#elif defined( _POSIX_VERSION ) || defined( POSIX ) || defined( VALVE_POSIX )
|
||||||
|
#define IsPosix() true
|
||||||
|
#define IsPC() true
|
||||||
#else
|
#else
|
||||||
#error Undefined platform
|
#error Undefined platform
|
||||||
#endif
|
#endif
|
||||||
@@ -155,6 +167,9 @@
|
|||||||
#ifndef IsPC
|
#ifndef IsPC
|
||||||
#define IsPC() false
|
#define IsPC() false
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef IsAndroid
|
||||||
|
#define IsAndroid() false
|
||||||
|
#endif
|
||||||
#ifndef IsConsole
|
#ifndef IsConsole
|
||||||
#define IsConsole() false
|
#define IsConsole() false
|
||||||
#endif
|
#endif
|
||||||
@@ -164,15 +179,17 @@
|
|||||||
#ifndef IsXboxOne
|
#ifndef IsXboxOne
|
||||||
#define IsXboxOne() false
|
#define IsXboxOne() false
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef IsPS4
|
||||||
|
#define IsPS4() false
|
||||||
|
#endif
|
||||||
#ifndef IsPS5
|
#ifndef IsPS5
|
||||||
#define IsPS5() false
|
#define IsPS5() false
|
||||||
#endif
|
#endif
|
||||||
|
#define IsPlaystation() ( IsPS4() || IsPS5() )
|
||||||
#ifndef IsLinux
|
#ifndef IsLinux
|
||||||
#define IsLinux() false
|
#define IsLinux() false
|
||||||
#endif
|
#endif
|
||||||
#ifdef POSIX
|
#ifndef IsPosix
|
||||||
#define IsPosix() true
|
|
||||||
#else
|
|
||||||
#define IsPosix() false
|
#define IsPosix() false
|
||||||
#endif
|
#endif
|
||||||
#ifndef IsOSX
|
#ifndef IsOSX
|
||||||
@@ -185,13 +202,6 @@
|
|||||||
#define IsARM() false
|
#define IsARM() false
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#ifndef IsAndroid
|
|
||||||
#ifdef ANDROID
|
|
||||||
#define IsAndroid() true
|
|
||||||
#else
|
|
||||||
#define IsAndroid() false
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Detect if RTTI is enabled in the current compile
|
// Detect if RTTI is enabled in the current compile
|
||||||
#if defined(__clang__)
|
#if defined(__clang__)
|
||||||
|
|||||||
@@ -47,16 +47,18 @@
|
|||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#define PLAT_DLL_EXT "dll"
|
#define PLAT_DLL_EXT "dll"
|
||||||
#elif defined(LINUX)
|
#elif IsLinux()
|
||||||
#define PLAT_DLL_EXT "so"
|
#define PLAT_DLL_EXT "so"
|
||||||
#elif defined(OSX)
|
#elif IsOSX()
|
||||||
#define PLAT_DLL_EXT "dylib"
|
#define PLAT_DLL_EXT "dylib"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#define PLAT_PATH_SLASH "\\"
|
#define PLAT_PATH_SLASH "\\"
|
||||||
#elif defined(POSIX)
|
#elif IsPosix()
|
||||||
#define PLAT_PATH_SLASH "/"
|
#define PLAT_PATH_SLASH "/"
|
||||||
|
#else
|
||||||
|
#error "?"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined( _PS3 )
|
#if defined( _PS3 )
|
||||||
@@ -64,7 +66,7 @@
|
|||||||
#define PATH_MAX CELL_GAME_PATH_MAX
|
#define PATH_MAX CELL_GAME_PATH_MAX
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (!defined(_WIN32) || defined(WINDED)) && defined(POSIX)
|
#if (!defined(_WIN32) || defined(WINDED)) && IsPosix()
|
||||||
#define MAX_PATH PATH_MAX
|
#define MAX_PATH PATH_MAX
|
||||||
#define _MAX_PATH PATH_MAX
|
#define _MAX_PATH PATH_MAX
|
||||||
#endif
|
#endif
|
||||||
@@ -149,7 +151,7 @@ FORCEINLINE unsigned __int64 PLAT_CPU_TIME()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#elif defined(POSIX)
|
#elif IsPosix()
|
||||||
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
@@ -252,7 +254,7 @@ char (*RtlpNumberOf( UNALIGNED T (&)[N] ))[N];
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif defined(LINUX)
|
#elif IsLinux()
|
||||||
|
|
||||||
// On Linux/gcc, RtlpNumberOf doesn't work well with pointers to structs
|
// On Linux/gcc, RtlpNumberOf doesn't work well with pointers to structs
|
||||||
// that are defined function locally. Here we have an alternative implementation
|
// that are defined function locally. Here we have an alternative implementation
|
||||||
@@ -318,7 +320,7 @@ struct ErrorIfIsPointerNotArrayGivenToARRAYSIZE<false>
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Don't define for Windows, since it is defined unconditionally in winnt.h.
|
// Don't define for Windows, since it is defined unconditionally in winnt.h.
|
||||||
#if !defined( UNREFERENCED_PARAMETER ) && !defined( WIN32 )
|
#if !defined( UNREFERENCED_PARAMETER ) && !defined( _WIN32 )
|
||||||
#define UNREFERENCED_PARAMETER(parm) NOTE_UNUSED(parm)
|
#define UNREFERENCED_PARAMETER(parm) NOTE_UNUSED(parm)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ typedef uint32 uint32_t;
|
|||||||
// NOTE: int64_t must match the compiler stdint.h definition
|
// NOTE: int64_t must match the compiler stdint.h definition
|
||||||
// and so may not match the Steam int64. Mixing the two is
|
// and so may not match the Steam int64. Mixing the two is
|
||||||
// error-prone so always use the Steam non-_t types in Steam code.
|
// error-prone so always use the Steam non-_t types in Steam code.
|
||||||
#if defined(COMPILER_GCC) && defined(PLATFORM_64BITS) && !defined(__MINGW32__) && !defined(OSX) && !(defined(IOS) || defined(TVOS))
|
#if defined(COMPILER_GCC) && defined(PLATFORM_64BITS) && !defined(__MINGW32__) && !IsOSX() && !(defined(IOS) || defined(TVOS))
|
||||||
#define INT64_DIFFERENT_FROM_INT64_T 1
|
#define INT64_DIFFERENT_FROM_INT64_T 1
|
||||||
typedef long int int64_t;
|
typedef long int int64_t;
|
||||||
typedef unsigned long int uint64_t;
|
typedef unsigned long int uint64_t;
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
#pragma GCC diagnostic ignored "-Wtype-limits"
|
#pragma GCC diagnostic ignored "-Wtype-limits"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if IsPS5() /* This is the wrong way to detect this. HALP */
|
#if defined( __PROSPERO__ ) || defined( __ORBIS__ ) /* This is the wrong way to detect this. HALP */
|
||||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||||
#pragma GCC diagnostic ignored "-Wreorder-ctor"
|
#pragma GCC diagnostic ignored "-Wreorder-ctor"
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
#include "minbase/minbase_macros.h"
|
#include "minbase/minbase_macros.h"
|
||||||
#include "minbase/minbase_endian.h"
|
#include "minbase/minbase_endian.h"
|
||||||
|
|
||||||
#ifdef POSIX
|
#if IsPosix()
|
||||||
typedef int SOCKET;
|
typedef int SOCKET;
|
||||||
#define INVALID_SOCKET (-1)
|
#define INVALID_SOCKET (-1)
|
||||||
#else
|
#else
|
||||||
@@ -53,7 +53,7 @@
|
|||||||
|
|
||||||
#include "platformtime.h"
|
#include "platformtime.h"
|
||||||
|
|
||||||
#if defined( POSIX )
|
#if IsPosix()
|
||||||
|
|
||||||
// handle mapping windows names used in tier0 to posix names in one place
|
// handle mapping windows names used in tier0 to posix names in one place
|
||||||
#define _snprintf snprintf //validator.cpp
|
#define _snprintf snprintf //validator.cpp
|
||||||
|
|||||||
+34
-12
@@ -1,13 +1,34 @@
|
|||||||
//====== Copyright Valve Corporation, All rights reserved. ====================
|
//====== Copyright Valve Corporation, All rights reserved. ====================
|
||||||
//
|
//
|
||||||
// Include the relevant platform-specific headers for socket-related stuff,
|
// Include the relevant platform-specific headers for socket-related
|
||||||
// and declare some functions make them look similar
|
// stuff, and declare some functions make them look as similar to
|
||||||
|
// plain BSD sockets as possible.
|
||||||
|
//
|
||||||
|
// This includes a bunch of stuff. DO NOT INCLUDE THIS FROM A HEADER
|
||||||
//
|
//
|
||||||
|
// Some things that will be defined by this file:
|
||||||
|
//
|
||||||
|
// closesocket()
|
||||||
|
// GetLastSocketError()
|
||||||
|
// SetSocketNonBlocking()
|
||||||
|
//
|
||||||
|
// USE_EPOLL or USE_POLL
|
||||||
|
// If USE_EPOLL:
|
||||||
|
// EPollHandle, INVALID_EPOLL_HANDLE, EPollCreate()
|
||||||
|
//
|
||||||
|
// WAKE_THREAD_USING_EVENT or WAKE_THREAD_USING_SOCKET_PAIR
|
||||||
|
// If WAKE_THREAD_USING_EVENT:
|
||||||
|
// ThreadWakeEvent, INVALID_THREAD_WAKE_EVENT, SetWakeThreadEvent()
|
||||||
|
|
||||||
#ifndef STEAMNETWORKINGSOCKETS_PLATFORM_H
|
#ifndef TIER0_PLATFORM_SOCKETS_H
|
||||||
#define STEAMNETWORKINGSOCKETS_PLATFORM_H
|
#define TIER0_PLATFORM_SOCKETS_H
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "platform.h"
|
||||||
|
|
||||||
|
// !KLUDGE!
|
||||||
|
typedef char SteamNetworkingErrMsg[ 1024 ];
|
||||||
|
|
||||||
// Socket headers
|
// Socket headers
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
//#include <windows.h>
|
//#include <windows.h>
|
||||||
@@ -45,12 +66,11 @@
|
|||||||
|
|
||||||
#elif IsNintendoSwitch()
|
#elif IsNintendoSwitch()
|
||||||
// NDA-protected material, so all this is in a separate file
|
// NDA-protected material, so all this is in a separate file
|
||||||
#include "clientlib/nswitch/steamnetworkingsockets_platform_nswitch.h"
|
#include "platform_sockets_nswitch.h"
|
||||||
#elif IsPS5()
|
#elif IsPlaystation()
|
||||||
// NDA-protected material, so all this is in a separate file
|
// NDA-protected material, so all this is in a separate file
|
||||||
#include "clientlib/ps5/steamnetworkingsockets_platform_ps5.h"
|
#include "platform_sockets_playstation.h"
|
||||||
|
#elif IsPosix()
|
||||||
#else
|
|
||||||
|
|
||||||
// POSIX-ish platform (Linux, OSX, Android, IOS)
|
// POSIX-ish platform (Linux, OSX, Android, IOS)
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@@ -61,7 +81,7 @@
|
|||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#ifndef ANDROID
|
#if !IsAndroid()
|
||||||
#include <ifaddrs.h>
|
#include <ifaddrs.h>
|
||||||
#endif
|
#endif
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
@@ -95,7 +115,7 @@
|
|||||||
inline EPollHandle EPollCreate( SteamNetworkingErrMsg &errMsg )
|
inline EPollHandle EPollCreate( SteamNetworkingErrMsg &errMsg )
|
||||||
{
|
{
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
#ifdef LINUX
|
#if IsLinux()
|
||||||
flags |= EPOLL_CLOEXEC;
|
flags |= EPOLL_CLOEXEC;
|
||||||
#endif
|
#endif
|
||||||
EPollHandle e = epoll_create1( flags );
|
EPollHandle e = epoll_create1( flags );
|
||||||
@@ -113,6 +133,8 @@
|
|||||||
// instead of a socket pair?
|
// instead of a socket pair?
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
#else
|
||||||
|
#error "How do?"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // #ifndef STEAMNETWORKINGSOCKETS_PLATFORM_H
|
#endif // _H
|
||||||
@@ -31,7 +31,7 @@ typedef unsigned char uint8;
|
|||||||
typedef unsigned char BYTE;
|
typedef unsigned char BYTE;
|
||||||
typedef unsigned char byte;
|
typedef unsigned char byte;
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
#include <tchar.h>
|
#include <tchar.h>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#elif defined( _PS3 )
|
#elif defined( _PS3 )
|
||||||
@@ -85,7 +85,7 @@ typedef char tchar;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if defined( _MSC_VER ) || defined( WIN32 )
|
#if defined( _MSC_VER ) || defined( _WIN32 )
|
||||||
typedef wchar_t uchar16;
|
typedef wchar_t uchar16;
|
||||||
typedef unsigned int uchar32;
|
typedef unsigned int uchar32;
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(POSIX)
|
#ifdef __GNUC__
|
||||||
// clang will error if the symbol visibility for an object changes between static libraries (and/or your main dylib)
|
// clang will error if the symbol visibility for an object changes between static libraries (and/or your main dylib)
|
||||||
// so force the FmtStr templates and importantly the global scAsserted below to hidden (i.e don't escape the dll) forcefully
|
// so force the FmtStr templates and importantly the global scAsserted below to hidden (i.e don't escape the dll) forcefully
|
||||||
#pragma GCC visibility push(hidden)
|
#pragma GCC visibility push(hidden)
|
||||||
@@ -318,7 +318,7 @@ void CFmtStrN< SIZE_BUF, QT, ON_STACK >::Set( const char *pchValue, int nSize )
|
|||||||
m_nLength = CopyStringLength( BaseClass::m_szBuf, pchValue, nMaxLength );
|
m_nLength = CopyStringLength( BaseClass::m_szBuf, pchValue, nMaxLength );
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(POSIX)
|
#ifdef __GNUC__
|
||||||
#pragma GCC visibility pop
|
#pragma GCC visibility pop
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
// Forward declarations of tag types and some template helper classes
|
// Forward declarations of tag types and some template helper classes
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#if !defined( OSX ) && !defined( IOS ) && !defined( TVOS ) && !defined(COMPILER_CLANG)
|
#if !IsOSX() && !defined( IOS ) && !defined( TVOS ) && !defined(COMPILER_CLANG)
|
||||||
namespace std
|
namespace std
|
||||||
{
|
{
|
||||||
struct forward_iterator_tag;
|
struct forward_iterator_tag;
|
||||||
|
|||||||
@@ -104,13 +104,13 @@ extern void V_StripTrailingWhitespaceASCII( char *pch );
|
|||||||
// trim whitespace from both ends of the string
|
// trim whitespace from both ends of the string
|
||||||
extern int V_StrTrim( char *pStr );
|
extern int V_StrTrim( char *pStr );
|
||||||
|
|
||||||
#ifdef POSIX
|
#if IsPosix()
|
||||||
#ifdef ANDROID
|
#if IsAndroid()
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#endif
|
#endif
|
||||||
#define _atoi64 atoll
|
#define _atoi64 atoll
|
||||||
#define _wtoi(arg) wcstol(arg, NULL, 10)
|
#define _wtoi(arg) wcstol(arg, NULL, 10)
|
||||||
#ifdef ANDROID
|
#if IsAndroid()
|
||||||
// TODO - Android doesn't support wcstoi64, so just use a basic implementation of our own.
|
// TODO - Android doesn't support wcstoi64, so just use a basic implementation of our own.
|
||||||
#define _wcstoi64 vstdlib_wcstoi64
|
#define _wcstoi64 vstdlib_wcstoi64
|
||||||
#define _wcstoui64 vstdlib_wcstoui64
|
#define _wcstoui64 vstdlib_wcstoui64
|
||||||
@@ -124,7 +124,7 @@ extern int V_StrTrim( char *pStr );
|
|||||||
#define _strtoi64 strtoll
|
#define _strtoi64 strtoll
|
||||||
#define _strtoui64 strtoull
|
#define _strtoui64 strtoull
|
||||||
#define _vsnprintf vsnprintf
|
#define _vsnprintf vsnprintf
|
||||||
#if defined(OSX) || defined(ANDROID)
|
#if IsOSX() || IsAndroid()
|
||||||
// TODO - OSX doesn't support wcscasecmp until 10.7, so just
|
// TODO - OSX doesn't support wcscasecmp until 10.7, so just
|
||||||
// use a basic implementation of our own.
|
// use a basic implementation of our own.
|
||||||
#define _wcsicmp vstdlib_wcsicmp
|
#define _wcsicmp vstdlib_wcsicmp
|
||||||
@@ -139,7 +139,7 @@ extern int V_StrTrim( char *pStr );
|
|||||||
#endif
|
#endif
|
||||||
#define TEXT(str) str
|
#define TEXT(str) str
|
||||||
|
|
||||||
#endif // POSIX
|
#endif // IsPosix()
|
||||||
|
|
||||||
END_TIER0_NAMESPACE
|
END_TIER0_NAMESPACE
|
||||||
|
|
||||||
|
|||||||
@@ -2384,7 +2384,7 @@ const char *CSteamNetworkingUtils::GetBuildString()
|
|||||||
|
|
||||||
const char *CSteamNetworkingUtils::GetPlatformString()
|
const char *CSteamNetworkingUtils::GetPlatformString()
|
||||||
{
|
{
|
||||||
#if defined( NN_NINTENDO_SDK )
|
#if IsNintendoSwitch()
|
||||||
return "nswitch";
|
return "nswitch";
|
||||||
#elif defined( _GAMECORE )
|
#elif defined( _GAMECORE )
|
||||||
// Is this right? This might actually require a system call.
|
// Is this right? This might actually require a system call.
|
||||||
@@ -2392,11 +2392,11 @@ const char *CSteamNetworkingUtils::GetPlatformString()
|
|||||||
#elif defined( _STADIA )
|
#elif defined( _STADIA )
|
||||||
// Not sure if this works.
|
// Not sure if this works.
|
||||||
return "stadia";
|
return "stadia";
|
||||||
#elif defined( _XBOX_ONE )
|
#elif IsXboxOne()
|
||||||
return "xbone";
|
return "xbone";
|
||||||
#elif defined( _PS4 )
|
#elif IsPS4()
|
||||||
return "ps4";
|
return "ps4";
|
||||||
#elif defined( _PS5 )
|
#elif IsPS5()
|
||||||
return "ps5";
|
return "ps5";
|
||||||
#elif defined( TVOS ) || defined( __TVOS__ )
|
#elif defined( TVOS ) || defined( __TVOS__ )
|
||||||
return "tvos";
|
return "tvos";
|
||||||
@@ -2408,13 +2408,13 @@ const char *CSteamNetworkingUtils::GetPlatformString()
|
|||||||
#else
|
#else
|
||||||
return "osx";
|
return "osx";
|
||||||
#endif
|
#endif
|
||||||
#elif defined( OSX )
|
#elif IsOSX()
|
||||||
return "osx";
|
return "osx";
|
||||||
#elif defined( ANDROID ) || defined( __ANDROID__ )
|
#elif IsAndroid()
|
||||||
return "android";
|
return "android";
|
||||||
#elif defined( _WINDOWS )
|
#elif defined( _WINDOWS )
|
||||||
return "windows";
|
return "windows";
|
||||||
#elif defined( LINUX ) || defined( __LINUX__ ) || defined(linux) || defined(__linux) || defined(__linux__)
|
#elif IsLinux()
|
||||||
return "linux";
|
return "linux";
|
||||||
#elif defined( FREEBSD ) || defined( __FreeBSD__ )
|
#elif defined( FREEBSD ) || defined( __FreeBSD__ )
|
||||||
return "freebsd";
|
return "freebsd";
|
||||||
|
|||||||
@@ -15,16 +15,8 @@
|
|||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
|
||||||
#ifdef POSIX
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <sched.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <netdb.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "steamnetworkingsockets_lowlevel.h"
|
#include "steamnetworkingsockets_lowlevel.h"
|
||||||
#include "../steamnetworkingsockets_platform.h"
|
#include <tier0/platform_sockets.h>
|
||||||
#include "../steamnetworkingsockets_internal.h"
|
#include "../steamnetworkingsockets_internal.h"
|
||||||
#include "../steamnetworkingsockets_thinker.h"
|
#include "../steamnetworkingsockets_thinker.h"
|
||||||
#include "steamnetworkingsockets_connections.h"
|
#include "steamnetworkingsockets_connections.h"
|
||||||
@@ -33,6 +25,18 @@
|
|||||||
#include <tier1/utllinkedlist.h>
|
#include <tier1/utllinkedlist.h>
|
||||||
#include "crypto.h"
|
#include "crypto.h"
|
||||||
|
|
||||||
|
#if IsPosix()
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <sched.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#if !IsNintendoSwitch()
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#endif
|
||||||
|
#ifdef STEAMNETWORKINGSOCKETS_ENABLE_RESOLVEHOSTNAME
|
||||||
|
#include <netdb.h>
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <tier0/memdbgoff.h>
|
#include <tier0/memdbgoff.h>
|
||||||
|
|
||||||
// Ugggggggggg MSVC VS2013 STL bug: try_lock_for doesn't actually respect the timeout, it always ends up using an infinite timeout.
|
// Ugggggggggg MSVC VS2013 STL bug: try_lock_for doesn't actually respect the timeout, it always ends up using an infinite timeout.
|
||||||
@@ -888,6 +892,33 @@ static void UpdateFakeRateLimitTokenBuckets( SteamNetworkingMicroseconds usecNow
|
|||||||
inline IRawUDPSocket::IRawUDPSocket() {}
|
inline IRawUDPSocket::IRawUDPSocket() {}
|
||||||
inline IRawUDPSocket::~IRawUDPSocket() {}
|
inline IRawUDPSocket::~IRawUDPSocket() {}
|
||||||
|
|
||||||
|
|
||||||
|
// Perform gather-based send, on platform that doesn't have sendmsg
|
||||||
|
#ifdef PLATFORM_NO_SENDMSG
|
||||||
|
bool sendto_gather( int sockfd, int nChunks, const iovec *pChunks, sockaddr *pAddr, socklen_t addrSize )
|
||||||
|
{
|
||||||
|
COMPILE_TIME_ASSERT( k_cbSteamNetworkingSocketsMaxUDPMsgLen < 1500 );
|
||||||
|
char pkt[ 2048 ];
|
||||||
|
char *max = pkt + sizeof(pkt);
|
||||||
|
char *d = pkt;
|
||||||
|
for ( int i = 0 ; i < nChunks ; ++i )
|
||||||
|
{
|
||||||
|
const iovec &chunk = pChunks[i];
|
||||||
|
if ( d + chunk.iov_len > max )
|
||||||
|
{
|
||||||
|
AssertMsg( false, "Gather send too big!" );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
memcpy( d, chunk.iov_base, chunk.iov_len );
|
||||||
|
d += chunk.iov_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
ssize_t cbTotal = d - pkt;
|
||||||
|
ssize_t r = sendto( sockfd, pkt, cbTotal, 0, pAddr, addrSize );
|
||||||
|
return ( r == cbTotal );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
class CRawUDPSocketImpl final : public IRawUDPSocket
|
class CRawUDPSocketImpl final : public IRawUDPSocket
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -917,6 +948,7 @@ public:
|
|||||||
inline bool BReallySendRawPacket( int nChunks, const iovec *pChunks, const netadr_t &adrTo ) const
|
inline bool BReallySendRawPacket( int nChunks, const iovec *pChunks, const netadr_t &adrTo ) const
|
||||||
{
|
{
|
||||||
Assert( m_socket != INVALID_SOCKET );
|
Assert( m_socket != INVALID_SOCKET );
|
||||||
|
Assert( nChunks > 0 );
|
||||||
|
|
||||||
// Add a tag. If we end up holding the lock for a long time, this tag
|
// Add a tag. If we end up holding the lock for a long time, this tag
|
||||||
// will tell us how many packets were sent
|
// will tell us how many packets were sent
|
||||||
@@ -927,8 +959,13 @@ public:
|
|||||||
socklen_t addrSize;
|
socklen_t addrSize;
|
||||||
if ( m_nAddressFamilies & k_nAddressFamily_IPv6 )
|
if ( m_nAddressFamilies & k_nAddressFamily_IPv6 )
|
||||||
{
|
{
|
||||||
addrSize = sizeof(sockaddr_in6);
|
#ifdef PLATFORM_NO_IPV6
|
||||||
adrTo.ToSockadrIPV6( &destAddress );
|
Assert( false );
|
||||||
|
return false;
|
||||||
|
#else
|
||||||
|
addrSize = sizeof(sockaddr_in6);
|
||||||
|
adrTo.ToSockadrIPV6( &destAddress );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -953,7 +990,7 @@ public:
|
|||||||
SteamNetworkingMicroseconds usecSendStart = SteamNetworkingSockets_GetLocalTimestamp();
|
SteamNetworkingMicroseconds usecSendStart = SteamNetworkingSockets_GetLocalTimestamp();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef _WIN32
|
||||||
// Confirm that iovec and WSABUF are indeed bitwise equivalent
|
// Confirm that iovec and WSABUF are indeed bitwise equivalent
|
||||||
COMPILE_TIME_ASSERT( sizeof( iovec ) == sizeof( WSABUF ) );
|
COMPILE_TIME_ASSERT( sizeof( iovec ) == sizeof( WSABUF ) );
|
||||||
COMPILE_TIME_ASSERT( offsetof( iovec, iov_len ) == offsetof( WSABUF, len ) );
|
COMPILE_TIME_ASSERT( offsetof( iovec, iov_len ) == offsetof( WSABUF, len ) );
|
||||||
@@ -992,17 +1029,30 @@ public:
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
msghdr msg;
|
bool bResult;
|
||||||
msg.msg_name = (sockaddr *)&destAddress;
|
if ( nChunks == 1 )
|
||||||
msg.msg_namelen = addrSize;
|
{
|
||||||
msg.msg_iov = const_cast<struct iovec *>( pChunks );
|
ssize_t r = sendto( m_socket, pChunks->iov_base, pChunks->iov_len, 0, (sockaddr *)&destAddress, addrSize );
|
||||||
msg.msg_iovlen = nChunks;
|
bResult = ( r == (ssize_t)pChunks->iov_len );
|
||||||
msg.msg_control = nullptr;
|
}
|
||||||
msg.msg_controllen = 0;
|
else
|
||||||
msg.msg_flags = 0;
|
{
|
||||||
|
#ifdef PLATFORM_NO_SENDMSG
|
||||||
|
bResult = sendto_gather( m_socket, nChunks, pChunks, (sockaddr *)&destAddress, addrSize );
|
||||||
|
#else
|
||||||
|
msghdr msg;
|
||||||
|
msg.msg_name = (sockaddr *)&destAddress;
|
||||||
|
msg.msg_namelen = addrSize;
|
||||||
|
msg.msg_iov = const_cast<struct iovec *>( pChunks );
|
||||||
|
msg.msg_iovlen = nChunks;
|
||||||
|
msg.msg_control = nullptr;
|
||||||
|
msg.msg_controllen = 0;
|
||||||
|
msg.msg_flags = 0;
|
||||||
|
|
||||||
int r = ::sendmsg( m_socket, &msg, 0 );
|
ssize_t r = sendmsg( m_socket, &msg, 0 );
|
||||||
bool bResult = ( r >= 0 ); // just check for -1 for error, since we don't want to take the time here to scan the iovec and sum up the expected total number of bytes sent
|
bResult = ( r >= 0 ); // just check for -1 for error, since we don't want to take the time here to scan the iovec and sum up the expected total number of bytes sent
|
||||||
|
#endif
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef STEAMNETWORKINGSOCKETS_LOWLEVEL_TIME_SOCKET_CALLS
|
#ifdef STEAMNETWORKINGSOCKETS_LOWLEVEL_TIME_SOCKET_CALLS
|
||||||
@@ -1284,6 +1334,11 @@ static CPacketLaggerRecv s_packetLagQueueRecv;
|
|||||||
#ifdef USE_POLL
|
#ifdef USE_POLL
|
||||||
static CUtlVector<pollfd> s_vecPollFDs;
|
static CUtlVector<pollfd> s_vecPollFDs;
|
||||||
static bool s_bRecreatePollList = true;
|
static bool s_bRecreatePollList = true;
|
||||||
|
|
||||||
|
#ifndef POLLEVENT_INVALID
|
||||||
|
#define POLLEVENT_INVALID (-1)
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_EPOLL
|
#ifdef USE_EPOLL
|
||||||
@@ -1461,16 +1516,16 @@ void CRawUDPSocketImpl::Close()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static SOCKET OpenUDPSocketBoundToSockAddr( const void *sockaddr, size_t len, SteamNetworkingErrMsg &errMsg, int *pnIPv6AddressFamilies, int nBindInterface = -1 )
|
static SOCKET OpenUDPSocketBoundToSockAddr( const void *pSockaddr, size_t len, SteamNetworkingErrMsg &errMsg, int *pnIPv6AddressFamilies, int nBindInterface = -1 )
|
||||||
{
|
{
|
||||||
unsigned int opt;
|
unsigned int opt;
|
||||||
|
|
||||||
const sockaddr_in *inaddr = (const sockaddr_in *)sockaddr;
|
const sockaddr_in *inaddr = (const sockaddr_in *)pSockaddr;
|
||||||
|
|
||||||
// Select socket type. For linux, use the "close on exec" flag, so that the
|
// Select socket type. For linux, use the "close on exec" flag, so that the
|
||||||
// socket will not be inherited by any child process that we spawn.
|
// socket will not be inherited by any child process that we spawn.
|
||||||
int sockType = SOCK_DGRAM;
|
int sockType = SOCK_DGRAM;
|
||||||
#ifdef LINUX
|
#if IsLinux()
|
||||||
sockType |= SOCK_CLOEXEC;
|
sockType |= SOCK_CLOEXEC;
|
||||||
#endif
|
#endif
|
||||||
#if IsNintendoSwitch() && !defined( _WIN32 )
|
#if IsNintendoSwitch() && !defined( _WIN32 )
|
||||||
@@ -1514,36 +1569,43 @@ static SOCKET OpenUDPSocketBoundToSockAddr( const void *sockaddr, size_t len, St
|
|||||||
// Handle IP v6 dual stack?
|
// Handle IP v6 dual stack?
|
||||||
if ( pnIPv6AddressFamilies )
|
if ( pnIPv6AddressFamilies )
|
||||||
{
|
{
|
||||||
|
#ifdef PLATFORM_NO_IPV6
|
||||||
|
Assert( false ); // Caller should check this define
|
||||||
|
V_strcpy_safe( errMsg, "No IPV6 support" );
|
||||||
|
closesocket( sock );
|
||||||
|
return INVALID_SOCKET;
|
||||||
|
#else
|
||||||
|
|
||||||
// Enable dual stack?
|
// Enable dual stack?
|
||||||
opt = ( *pnIPv6AddressFamilies == k_nAddressFamily_IPv6 ) ? 1 : 0;
|
opt = ( *pnIPv6AddressFamilies == k_nAddressFamily_IPv6 ) ? 1 : 0;
|
||||||
if ( setsockopt( sock, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&opt, sizeof( opt ) ) != 0 )
|
if ( setsockopt( sock, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&opt, sizeof( opt ) ) != 0 )
|
||||||
{
|
|
||||||
if ( *pnIPv6AddressFamilies == k_nAddressFamily_IPv6 )
|
|
||||||
{
|
{
|
||||||
// Spew a warning, but continue
|
if ( *pnIPv6AddressFamilies == k_nAddressFamily_IPv6 )
|
||||||
SpewWarning( "Failed to set socket for IPv6 only (IPV6_V6ONLY=1). Error code 0x%08X. Continuing anyway.\n", GetLastSocketError() );
|
{
|
||||||
|
// Spew a warning, but continue
|
||||||
|
SpewWarning( "Failed to set socket for IPv6 only (IPV6_V6ONLY=1). Error code 0x%08X. Continuing anyway.\n", GetLastSocketError() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Dual stack required, or only requested?
|
||||||
|
if ( *pnIPv6AddressFamilies == k_nAddressFamily_DualStack )
|
||||||
|
{
|
||||||
|
V_sprintf_safe( errMsg, "Failed to set socket for dual stack (IPV6_V6ONLY=0). Error code 0x%08X.", GetLastSocketError() );
|
||||||
|
closesocket( sock );
|
||||||
|
return INVALID_SOCKET;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Let caller know we're IPv6 only, and spew about this.
|
||||||
|
SpewWarning( "Failed to set socket for dual stack (IPV6_V6ONLY=0). Error code 0x%08X. Continuing using IPv6 only!\n", GetLastSocketError() );
|
||||||
|
*pnIPv6AddressFamilies = k_nAddressFamily_IPv6;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Dual stack required, or only requested?
|
// Tell caller what they've got
|
||||||
if ( *pnIPv6AddressFamilies == k_nAddressFamily_DualStack )
|
*pnIPv6AddressFamilies = opt ? k_nAddressFamily_IPv6 : k_nAddressFamily_DualStack;
|
||||||
{
|
|
||||||
V_sprintf_safe( errMsg, "Failed to set socket for dual stack (IPV6_V6ONLY=0). Error code 0x%08X.", GetLastSocketError() );
|
|
||||||
closesocket( sock );
|
|
||||||
return INVALID_SOCKET;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Let caller know we're IPv6 only, and spew about this.
|
|
||||||
SpewWarning( "Failed to set socket for dual stack (IPV6_V6ONLY=0). Error code 0x%08X. Continuing using IPv6 only!\n", GetLastSocketError() );
|
|
||||||
*pnIPv6AddressFamilies = k_nAddressFamily_IPv6;
|
|
||||||
}
|
}
|
||||||
}
|
#endif
|
||||||
else
|
|
||||||
{
|
|
||||||
// Tell caller what they've got
|
|
||||||
*pnIPv6AddressFamilies = opt ? k_nAddressFamily_IPv6 : k_nAddressFamily_DualStack;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bind to particular interface
|
// Bind to particular interface
|
||||||
@@ -1586,7 +1648,7 @@ static SOCKET OpenUDPSocketBoundToSockAddr( const void *sockaddr, size_t len, St
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Bind it to specific desired local port/IP
|
// Bind it to specific desired local port/IP
|
||||||
if ( bind( sock, (struct sockaddr *)sockaddr, (socklen_t)len ) == -1 )
|
if ( bind( sock, (struct sockaddr *)pSockaddr, (socklen_t)len ) == -1 )
|
||||||
{
|
{
|
||||||
V_sprintf_safe( errMsg, "Failed to bind socket. Error code 0x%08X.", GetLastSocketError() );
|
V_sprintf_safe( errMsg, "Failed to bind socket. Error code 0x%08X.", GetLastSocketError() );
|
||||||
closesocket( sock );
|
closesocket( sock );
|
||||||
@@ -1659,31 +1721,33 @@ static CRawUDPSocketImpl *OpenRawUDPSocketInternal( CRecvPacketCallback callback
|
|||||||
|
|
||||||
// Try IPv6?
|
// Try IPv6?
|
||||||
SOCKET sock = INVALID_SOCKET;
|
SOCKET sock = INVALID_SOCKET;
|
||||||
if ( nAddressFamilies & k_nAddressFamily_IPv6 )
|
#ifndef PLATFORM_NO_IPV6
|
||||||
{
|
if ( nAddressFamilies & k_nAddressFamily_IPv6 )
|
||||||
sockaddr_in6 address6;
|
|
||||||
memset( &address6, 0, sizeof(address6) );
|
|
||||||
address6.sin6_family = AF_INET6;
|
|
||||||
memcpy( address6.sin6_addr.s6_addr, addrLocal.m_ipv6, 16 );
|
|
||||||
address6.sin6_port = BigWord( addrLocal.m_port );
|
|
||||||
|
|
||||||
// Try to get socket
|
|
||||||
int nIPv6AddressFamilies = nAddressFamilies;
|
|
||||||
sock = OpenUDPSocketBoundToSockAddr( &address6, sizeof(address6), errMsg, &nIPv6AddressFamilies, nBindInterface );
|
|
||||||
|
|
||||||
if ( sock == INVALID_SOCKET )
|
|
||||||
{
|
{
|
||||||
// Allowing fallback to IPv4?
|
sockaddr_in6 address6;
|
||||||
if ( nAddressFamilies != k_nAddressFamily_Auto )
|
memset( &address6, 0, sizeof(address6) );
|
||||||
return nullptr;
|
address6.sin6_family = AF_INET6;
|
||||||
|
memcpy( address6.sin6_addr.s6_addr, addrLocal.m_ipv6, 16 );
|
||||||
|
address6.sin6_port = BigWord( addrLocal.m_port );
|
||||||
|
|
||||||
// Continue below, we'll try IPv4
|
// Try to get socket
|
||||||
|
int nIPv6AddressFamilies = nAddressFamilies;
|
||||||
|
sock = OpenUDPSocketBoundToSockAddr( &address6, sizeof(address6), errMsg, &nIPv6AddressFamilies, nBindInterface );
|
||||||
|
|
||||||
|
if ( sock == INVALID_SOCKET )
|
||||||
|
{
|
||||||
|
// Allowing fallback to IPv4?
|
||||||
|
if ( nAddressFamilies != k_nAddressFamily_Auto )
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
// Continue below, we'll try IPv4
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nAddressFamilies = nIPv6AddressFamilies;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
#endif
|
||||||
{
|
|
||||||
nAddressFamilies = nIPv6AddressFamilies;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try IPv4?
|
// Try IPv4?
|
||||||
if ( sock == INVALID_SOCKET )
|
if ( sock == INVALID_SOCKET )
|
||||||
@@ -1721,11 +1785,13 @@ static CRawUDPSocketImpl *OpenRawUDPSocketInternal( CRecvPacketCallback callback
|
|||||||
const sockaddr_in *boundaddr4 = (const sockaddr_in *)&addrBound;
|
const sockaddr_in *boundaddr4 = (const sockaddr_in *)&addrBound;
|
||||||
addrLocal.SetIPv4( BigDWord( boundaddr4->sin_addr.s_addr ), BigWord( boundaddr4->sin_port ) );
|
addrLocal.SetIPv4( BigDWord( boundaddr4->sin_addr.s_addr ), BigWord( boundaddr4->sin_port ) );
|
||||||
}
|
}
|
||||||
|
#ifndef PLATFORM_NO_IPV6
|
||||||
else if ( addrBound.ss_family == AF_INET6 )
|
else if ( addrBound.ss_family == AF_INET6 )
|
||||||
{
|
{
|
||||||
const sockaddr_in6 *boundaddr6 = (const sockaddr_in6 *)&addrBound;
|
const sockaddr_in6 *boundaddr6 = (const sockaddr_in6 *)&addrBound;
|
||||||
addrLocal.SetIPv6( boundaddr6->sin6_addr.s6_addr, BigWord( boundaddr6->sin6_port ) );
|
addrLocal.SetIPv6( boundaddr6->sin6_addr.s6_addr, BigWord( boundaddr6->sin6_port ) );
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Assert( false );
|
Assert( false );
|
||||||
@@ -1978,7 +2044,7 @@ static bool PollRawUDPSockets( int nMaxTimeoutMS, bool bManualPoll )
|
|||||||
Assert( f != INVALID_SOCKET ); \
|
Assert( f != INVALID_SOCKET ); \
|
||||||
p.fd = f; \
|
p.fd = f; \
|
||||||
p.events = POLLRDNORM; \
|
p.events = POLLRDNORM; \
|
||||||
p.revents = -1; /* Make sure kernel is clearing events properly */ \
|
p.revents = POLLEVENT_INVALID; /* Make sure kernel is clearing events properly */ \
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( CRawUDPSocketImpl *pSock: s_vecRawSockets )
|
for ( CRawUDPSocketImpl *pSock: s_vecRawSockets )
|
||||||
@@ -2015,7 +2081,7 @@ static bool PollRawUDPSockets( int nMaxTimeoutMS, bool bManualPoll )
|
|||||||
struct epoll_event epoll_events[ 32 ];
|
struct epoll_event epoll_events[ 32 ];
|
||||||
int num_epoll_events = epoll_wait( s_epollfd, epoll_events, V_ARRAYSIZE( epoll_events ), nMaxTimeoutMS );
|
int num_epoll_events = epoll_wait( s_epollfd, epoll_events, V_ARRAYSIZE( epoll_events ), nMaxTimeoutMS );
|
||||||
#elif defined( USE_POLL )
|
#elif defined( USE_POLL )
|
||||||
poll( s_vecPollFDs.Base(), s_vecPollFDs.Count(), nMaxTimeoutMS );
|
int poll_result = poll( s_vecPollFDs.Base(), s_vecPollFDs.Count(), nMaxTimeoutMS );
|
||||||
#elif defined( _WIN32 )
|
#elif defined( _WIN32 )
|
||||||
WaitForSingleObject( s_hEventWakeThread, nMaxTimeoutMS );
|
WaitForSingleObject( s_hEventWakeThread, nMaxTimeoutMS );
|
||||||
#else
|
#else
|
||||||
@@ -2099,6 +2165,41 @@ static bool PollRawUDPSockets( int nMaxTimeoutMS, bool bManualPoll )
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
// On POSIX, check return value, and also handle the wake "fd"
|
||||||
|
#ifdef USE_POLL
|
||||||
|
{
|
||||||
|
|
||||||
|
// Make sure we actually got some descriptors with data
|
||||||
|
if ( poll_result <= 0 )
|
||||||
|
{
|
||||||
|
if ( poll_result < 0 )
|
||||||
|
SpewWarning( "poll() returned %d, errno %d\n", poll_result, errno );
|
||||||
|
goto exit_polling;
|
||||||
|
}
|
||||||
|
|
||||||
|
pollfd &wake = s_vecPollFDs[ nSocketsToPoll ];
|
||||||
|
if ( (int)( wake.revents & POLLRDNORM ) )
|
||||||
|
{
|
||||||
|
Assert( wake.revents != POLLEVENT_INVALID );
|
||||||
|
#if defined( WAKE_THREAD_USING_EVENT )
|
||||||
|
Assert( wake.fd == s_hEventWakeThread );
|
||||||
|
ClearWakeThreadEvent( wake, s_hEventWakeThread );
|
||||||
|
#elif defined( WAKE_THREAD_USING_SOCKET_PAIR )
|
||||||
|
Assert( wake.fd == s_hSockWakeThreadRead );
|
||||||
|
|
||||||
|
// Just eat one request for now.
|
||||||
|
// I think it's probably safe to eat all of them, but
|
||||||
|
// it's a small optimization and I don't want to debug
|
||||||
|
// it is that's not true.
|
||||||
|
char buf[8];
|
||||||
|
::recv( s_hSockWakeThreadRead, buf, sizeof(buf), 0 );
|
||||||
|
#else
|
||||||
|
#error "How did we wake up?"
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Not using epoll, just check all sockets
|
// Not using epoll, just check all sockets
|
||||||
for ( int idx = 0 ; idx < nSocketsToPoll ; ++idx )
|
for ( int idx = 0 ; idx < nSocketsToPoll ; ++idx )
|
||||||
{
|
{
|
||||||
@@ -2117,7 +2218,7 @@ static bool PollRawUDPSockets( int nMaxTimeoutMS, bool bManualPoll )
|
|||||||
#elif defined( USE_POLL )
|
#elif defined( USE_POLL )
|
||||||
if ( !( s_vecPollFDs[ idx ].revents & POLLRDNORM ) )
|
if ( !( s_vecPollFDs[ idx ].revents & POLLRDNORM ) )
|
||||||
continue;
|
continue;
|
||||||
Assert( s_vecPollFDs[ idx ].revents != -1 ); // Make sure kernel actually populated this
|
Assert( s_vecPollFDs[ idx ].revents != POLLEVENT_INVALID ); // Make sure kernel actually populated this
|
||||||
#else
|
#else
|
||||||
#error "How to tell if we need to drain socket?"
|
#error "How to tell if we need to drain socket?"
|
||||||
#endif
|
#endif
|
||||||
@@ -2127,32 +2228,6 @@ static bool PollRawUDPSockets( int nMaxTimeoutMS, bool bManualPoll )
|
|||||||
if ( !DrainSocket( pSock ) )
|
if ( !DrainSocket( pSock ) )
|
||||||
goto exit_polling;
|
goto exit_polling;
|
||||||
}
|
}
|
||||||
|
|
||||||
// On POSIX, check for draining the thread wake "socket"
|
|
||||||
#ifdef USE_POLL
|
|
||||||
{
|
|
||||||
pollfd &wake = s_vecPollFDs[ nSocketsToPoll ];
|
|
||||||
if ( wake.revents & POLLRDNORM )
|
|
||||||
{
|
|
||||||
Assert( wake.revents != -1 );
|
|
||||||
#if defined( WAKE_THREAD_USING_EVENT )
|
|
||||||
Assert( wake.fd == s_hEventWakeThread );
|
|
||||||
ClearWakeThreadEvent( wake, s_hEventWakeThread )
|
|
||||||
#elif defined( WAKE_THREAD_USING_SOCKET_PAIR )
|
|
||||||
Assert( wake.fd == s_hSockWakeThreadRead );
|
|
||||||
|
|
||||||
// Just eat one request for now.
|
|
||||||
// I think it's probably safe to eat all of them, but
|
|
||||||
// it's a small optimization and I don't want to debug
|
|
||||||
// it is that's not true.
|
|
||||||
char buf[8];
|
|
||||||
::recv( s_hSockWakeThreadRead, buf, sizeof(buf), 0 );
|
|
||||||
#else
|
|
||||||
#error "How did we wake up?"
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif // USE_EPOLL, else
|
#endif // USE_EPOLL, else
|
||||||
|
|
||||||
exit_polling:
|
exit_polling:
|
||||||
@@ -2687,7 +2762,7 @@ static void SteamNetworkingThreadProc()
|
|||||||
// for packets to arrive.
|
// for packets to arrive.
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
DbgVerify( SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_HIGHEST ) );
|
DbgVerify( SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_HIGHEST ) );
|
||||||
#elif defined(POSIX)
|
#elif IsPosix()
|
||||||
// This probably won't work on Linux, because you cannot raise thread priority
|
// This probably won't work on Linux, because you cannot raise thread priority
|
||||||
// without being root. But on some systems it works. So we try, and if it
|
// without being root. But on some systems it works. So we try, and if it
|
||||||
// works, great.
|
// works, great.
|
||||||
@@ -3222,7 +3297,7 @@ bool BSteamNetworkingSocketsLowLevelAddRef( SteamNetworkingErrMsg &errMsg )
|
|||||||
V_sprintf_safe( errMsg, "nn::socket::EventFd. Error code 0x%08x.", GetLastError() );
|
V_sprintf_safe( errMsg, "nn::socket::EventFd. Error code 0x%08x.", GetLastError() );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#elif IsPS5()
|
#elif IsPlaystation()
|
||||||
// No additional setup needed here
|
// No additional setup needed here
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
@@ -3230,7 +3305,7 @@ bool BSteamNetworkingSocketsLowLevelAddRef( SteamNetworkingErrMsg &errMsg )
|
|||||||
Assert( s_hSockWakeThreadWrite == INVALID_SOCKET );
|
Assert( s_hSockWakeThreadWrite == INVALID_SOCKET );
|
||||||
|
|
||||||
int sockType = SOCK_DGRAM;
|
int sockType = SOCK_DGRAM;
|
||||||
#ifdef LINUX
|
#if IsLinux()
|
||||||
sockType |= SOCK_CLOEXEC;
|
sockType |= SOCK_CLOEXEC;
|
||||||
#endif
|
#endif
|
||||||
int sock[2];
|
int sock[2];
|
||||||
@@ -3344,7 +3419,7 @@ void SteamNetworkingSocketsLowLevelDecRef()
|
|||||||
nn::socket::Close( s_hEventWakeThread );
|
nn::socket::Close( s_hEventWakeThread );
|
||||||
s_hEventWakeThread = INVALID_SOCKET;
|
s_hEventWakeThread = INVALID_SOCKET;
|
||||||
}
|
}
|
||||||
#elif IsPS5()
|
#elif IsPlaystation()
|
||||||
// Nothing to do here
|
// Nothing to do here
|
||||||
#else
|
#else
|
||||||
if ( s_hSockWakeThreadRead != INVALID_SOCKET )
|
if ( s_hSockWakeThreadRead != INVALID_SOCKET )
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
#undef min
|
#undef min
|
||||||
#undef max
|
#undef max
|
||||||
#endif
|
#endif
|
||||||
#if defined( POSIX ) && defined( STEAMNETWORKINGSOCKETS_ENABLE_WEBRTC )
|
#if IsPosix() && defined( STEAMNETWORKINGSOCKETS_ENABLE_WEBRTC )
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -309,8 +309,8 @@ void CSteamNetworkConnectionP2P::CheckInitICE()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
g_SteamNetworkingSockets_CreateICESessionFunc = (CreateICESession_t)::GetProcAddress( h, pszExportFunc );
|
g_SteamNetworkingSockets_CreateICESessionFunc = (CreateICESession_t)::GetProcAddress( h, pszExportFunc );
|
||||||
#elif defined( POSIX )
|
#elif IsPosix()
|
||||||
#if defined( OSX ) || defined( IOS ) || defined( TVOS )
|
#if IsOSX() || defined( IOS ) || defined( TVOS )
|
||||||
static const char pszModule[] = "libsteamwebrtc.dylib";
|
static const char pszModule[] = "libsteamwebrtc.dylib";
|
||||||
#else
|
#else
|
||||||
static const char pszModule[] = "libsteamwebrtc.so";
|
static const char pszModule[] = "libsteamwebrtc.so";
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#ifdef STEAMNETWORKINGSOCKETS_ENABLE_ICE
|
#ifdef STEAMNETWORKINGSOCKETS_ENABLE_ICE
|
||||||
|
|
||||||
#include "csteamnetworkingsockets.h"
|
#include "csteamnetworkingsockets.h"
|
||||||
#include "../steamnetworkingsockets_platform.h"
|
#include <tier0/platform_sockets.h>
|
||||||
#include "crypto.h"
|
#include "crypto.h"
|
||||||
|
|
||||||
// Put everything in a namespace, so we don't violate the one definition rule
|
// Put everything in a namespace, so we don't violate the one definition rule
|
||||||
|
|||||||
+15
-14
@@ -22,26 +22,30 @@ using namespace SteamNetworkingSocketsLib;
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#ifdef POSIX
|
#if IsPosix()
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#if !IsPS5()
|
#if !IsPlaystation()
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#endif
|
#endif
|
||||||
#endif // POSIX
|
#endif // POSIX
|
||||||
|
|
||||||
#ifdef LINUX
|
#if IsLinux()
|
||||||
#include <sys/ptrace.h>
|
#include <sys/ptrace.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef OSX
|
#if IsOSX()
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if IsPlaystation() && defined(_DEBUG)
|
||||||
|
// NDA material
|
||||||
|
#endif
|
||||||
|
|
||||||
bool Plat_IsInDebugSession()
|
bool Plat_IsInDebugSession()
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
return (IsDebuggerPresent() != 0);
|
return (IsDebuggerPresent() != 0);
|
||||||
#elif defined(OSX)
|
#elif IsOSX()
|
||||||
int mib[4];
|
int mib[4];
|
||||||
struct kinfo_proc info;
|
struct kinfo_proc info;
|
||||||
size_t size;
|
size_t size;
|
||||||
@@ -53,7 +57,7 @@ bool Plat_IsInDebugSession()
|
|||||||
info.kp_proc.p_flag = 0;
|
info.kp_proc.p_flag = 0;
|
||||||
sysctl(mib,4,&info,&size,NULL,0);
|
sysctl(mib,4,&info,&size,NULL,0);
|
||||||
return ((info.kp_proc.p_flag & P_TRACED) == P_TRACED);
|
return ((info.kp_proc.p_flag & P_TRACED) == P_TRACED);
|
||||||
#elif defined(LINUX)
|
#elif IsLinux()
|
||||||
static FILE *fp;
|
static FILE *fp;
|
||||||
if ( !fp )
|
if ( !fp )
|
||||||
{
|
{
|
||||||
@@ -80,15 +84,12 @@ bool Plat_IsInDebugSession()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (nTracePid != 0);
|
return (nTracePid != 0);
|
||||||
#elif IsPS5()
|
#elif IsPlaystation()
|
||||||
// There might be a way to tell. Do we care?
|
// NDA material
|
||||||
|
#elif IsNintendoSwitch()
|
||||||
return false;
|
return false;
|
||||||
#elif defined( _PS3 )
|
#else
|
||||||
#ifdef _CERT
|
#error "HALP"
|
||||||
return false;
|
|
||||||
#else
|
|
||||||
return snIsDebuggerPresent();
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,16 +9,20 @@
|
|||||||
#else
|
#else
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#if defined OSX
|
#if IsOSX()
|
||||||
#include <mach/mach.h>
|
#include <mach/mach.h>
|
||||||
#include <mach/mach_time.h>
|
#include <mach/mach_time.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if IsNintendoSwitch()
|
||||||
|
// NDA material
|
||||||
|
#endif
|
||||||
|
|
||||||
BEGIN_TIER0_NAMESPACE
|
BEGIN_TIER0_NAMESPACE
|
||||||
|
|
||||||
#if defined( _WIN32 ) || IsOSX()
|
#if defined( _WIN32 ) || IsOSX() || IsNintendoSwitch()
|
||||||
static uint64 g_TickFrequency;
|
static uint64 g_TickFrequency;
|
||||||
static double g_TickFrequencyDouble;
|
static double g_TickFrequencyDouble;
|
||||||
static double g_TicksToUS;
|
static double g_TicksToUS;
|
||||||
@@ -59,6 +63,8 @@ static uint64 InitTicks()
|
|||||||
g_TickFrequencyDouble = (double) TimebaseInfo.denom / (double) TimebaseInfo.numer * 1.0e9;
|
g_TickFrequencyDouble = (double) TimebaseInfo.denom / (double) TimebaseInfo.numer * 1.0e9;
|
||||||
g_TickFrequency = (uint64)( g_TickFrequencyDouble + 0.5 );
|
g_TickFrequency = (uint64)( g_TickFrequencyDouble + 0.5 );
|
||||||
g_TickBase = mach_absolute_time();
|
g_TickBase = mach_absolute_time();
|
||||||
|
#elif IsNintendoSwitch()
|
||||||
|
// NDA material
|
||||||
#elif IsPosix()
|
#elif IsPosix()
|
||||||
// TickFrequency is constant since clock_gettime always returns nanoseconds
|
// TickFrequency is constant since clock_gettime always returns nanoseconds
|
||||||
timespec TimeSpec;
|
timespec TimeSpec;
|
||||||
@@ -68,7 +74,7 @@ static uint64 InitTicks()
|
|||||||
#error Unknown platform
|
#error Unknown platform
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined( _WIN32 ) || defined( OSX )
|
#if defined( _WIN32 ) || IsOSX() || IsNintendoSwitch()
|
||||||
g_TicksToUS = 1.0e6 / g_TickFrequencyDouble;
|
g_TicksToUS = 1.0e6 / g_TickFrequencyDouble;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -97,6 +103,8 @@ uint64 Plat_RelativeTicks()
|
|||||||
}
|
}
|
||||||
#elif IsOSX()
|
#elif IsOSX()
|
||||||
Ticks = mach_absolute_time();
|
Ticks = mach_absolute_time();
|
||||||
|
#elif IsNintendoSwitch()
|
||||||
|
// NDA material
|
||||||
#elif IsPosix()
|
#elif IsPosix()
|
||||||
timespec TimeSpec;
|
timespec TimeSpec;
|
||||||
clock_gettime( CLOCK_MONOTONIC, &TimeSpec );
|
clock_gettime( CLOCK_MONOTONIC, &TimeSpec );
|
||||||
|
|||||||
@@ -3,14 +3,7 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#include <tier1/netadr.h>
|
#include <tier1/netadr.h>
|
||||||
|
#include <tier0/platform_sockets.h>
|
||||||
#ifdef WIN32
|
|
||||||
#include <ws2tcpip.h>
|
|
||||||
#undef SetPort
|
|
||||||
#else
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <vstdlib/strtools.h>
|
#include <vstdlib/strtools.h>
|
||||||
#include "ipv6text.h"
|
#include "ipv6text.h"
|
||||||
@@ -456,6 +449,7 @@ bool CIPAddress::SetFromSockadr(const void *addr, size_t addr_size, uint16 *punP
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef PLATFORM_NO_IPV6
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
{
|
{
|
||||||
if ( addr_size < sizeof(sockaddr_in6) )
|
if ( addr_size < sizeof(sockaddr_in6) )
|
||||||
@@ -473,6 +467,7 @@ bool CIPAddress::SetFromSockadr(const void *addr, size_t addr_size, uint16 *punP
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -686,6 +681,7 @@ size_t CIPAndPort::ToSockadr(void *addr, size_t addr_size) const
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
#ifndef PLATFORM_NO_IPV6
|
||||||
case k_EIPTypeV6:
|
case k_EIPTypeV6:
|
||||||
{
|
{
|
||||||
if ( addr_size < sizeof(sockaddr_in6) )
|
if ( addr_size < sizeof(sockaddr_in6) )
|
||||||
@@ -702,6 +698,7 @@ size_t CIPAndPort::ToSockadr(void *addr, size_t addr_size) const
|
|||||||
struct_size = sizeof(sockaddr_in6);
|
struct_size = sizeof(sockaddr_in6);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
#endif // #ifndef PLATFORM_NO_IPV6
|
||||||
}
|
}
|
||||||
|
|
||||||
return struct_size;
|
return struct_size;
|
||||||
@@ -713,6 +710,7 @@ size_t CIPAndPort::ToSockadr(void *addr, size_t addr_size) const
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Purpose: Convert to an ipv6 sockaddr structure
|
// Purpose: Convert to an ipv6 sockaddr structure
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
#ifndef PLATFORM_NO_IPV6
|
||||||
void CIPAndPort::ToSockadrIPV6(void *addr, size_t addr_size) const
|
void CIPAndPort::ToSockadrIPV6(void *addr, size_t addr_size) const
|
||||||
{
|
{
|
||||||
memset( addr, 0, addr_size);
|
memset( addr, 0, addr_size);
|
||||||
@@ -728,3 +726,4 @@ void CIPAndPort::ToSockadrIPV6(void *addr, size_t addr_size) const
|
|||||||
s->sin6_scope_id = m_unIPv6Scope;
|
s->sin6_scope_id = m_unIPv6Scope;
|
||||||
s->sin6_port = BigWord( m_usPort );
|
s->sin6_port = BigWord( m_usPort );
|
||||||
}
|
}
|
||||||
|
#endif // PLATFORM_NO_IPV6
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#include "winlite.h"
|
#include "winlite.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef POSIX
|
#if IsPosix()
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user