OpenTTD Source  20240919-master-gdf0233f4c2
os_abstraction.cpp File Reference
#include "stdafx.h"
#include "os_abstraction.h"
#include "../../string_func.h"
#include "../../3rdparty/fmt/format.h"
#include <mutex>
#include "../../safeguards.h"

Go to the source code of this file.

Functions

bool SetNonBlocking ([[maybe_unused]] SOCKET d)
 Try to set the socket into non-blocking mode. More...
 
bool SetNoDelay ([[maybe_unused]] SOCKET d)
 Try to set the socket to not delay sending. More...
 
bool SetReusePort (SOCKET d)
 Try to set the socket to reuse ports. More...
 
NetworkError GetSocketError (SOCKET d)
 Get the error from a socket, if any. More...
 

Detailed Description

OS specific implementations of functions of the OS abstraction layer for network stuff.

The general idea is to have simple abstracting functions for things that require different implementations for different environments. In here the functions, and their documentation, are defined only once and the implementation contains the #ifdefs to change the implementation. Since Windows is usually different that is usually the first case, after that the behaviour is usually Unix/BSD-like with occasional variation.

Definition in file os_abstraction.cpp.

Function Documentation

◆ GetSocketError()

NetworkError GetSocketError ( SOCKET  d)

Get the error from a socket, if any.

Parameters
dThe socket to get the error from.
Returns
The errno on the socket.

Definition at line 184 of file os_abstraction.cpp.

Referenced by TCPConnecter::CheckActivity().

◆ SetNoDelay()

bool SetNoDelay ( [[maybe_unused] ] SOCKET  d)

Try to set the socket to not delay sending.

Parameters
dThe socket to disable the delaying for.
Returns
True if disabling the delaying succeeded, otherwise false.

Definition at line 151 of file os_abstraction.cpp.

Referenced by TCPListenHandler< ServerNetworkGameSocketHandler, PACKET_SERVER_FULL, PACKET_SERVER_BANNED >::AcceptClient(), TCPConnecter::Connect(), and ListenLoopProc().

◆ SetNonBlocking()

bool SetNonBlocking ( [[maybe_unused] ] SOCKET  d)

Try to set the socket into non-blocking mode.

Parameters
dThe socket to set the non-blocking more for.
Returns
True if setting the non-blocking mode succeeded, otherwise false.

Definition at line 133 of file os_abstraction.cpp.

Referenced by TCPListenHandler< ServerNetworkGameSocketHandler, PACKET_SERVER_FULL, PACKET_SERVER_BANNED >::AcceptClient(), TCPConnecter::Connect(), ListenLoopProc(), and NetworkUDPSocketHandler::ReceivePackets().

◆ SetReusePort()

bool SetReusePort ( SOCKET  d)

Try to set the socket to reuse ports.

Parameters
dThe socket to reuse ports on.
Returns
True if disabling the delaying succeeded, otherwise false.

Definition at line 167 of file os_abstraction.cpp.

Referenced by TCPConnecter::Connect(), and ListenLoopProc().