OpenTTD Source: NetworkError Class Reference

OpenTTD Source 15.0-beta1

Public Member Functions | Static Public Member Functions | Private Attributes
NetworkError Class Reference

Abstraction of a network error where all implementation details of the error codes are encapsulated in this class and the abstraction layer. More...

`#include <os_abstraction.h>`

## Public Member Functions
| NetworkError (int error)
| Construct the network error with the given error code.
bool | HasError () const
| Check whether an error was actually set.
bool | WouldBlock () const
| Check whether this error describes that the operation would block.
bool | IsConnectionReset () const
| Check whether this error describes a connection reset.
bool | IsConnectInProgress () const
| Check whether this error describes a connect is in progress.
const std::string & | AsString () const
| Get the string representation of the error message.

## Static Public Member Functions
static NetworkError | GetLast ()
| Get the last network error.

## Private Attributes
int | error
| The underlying error number from errno or WSAGetLastError.
std::string | message
| The string representation of the error (set on first call to AsString).

## Detailed Description

Abstraction of a network error where all implementation details of the error codes are encapsulated in this class and the abstraction layer.

Definition at line 21 of file os_abstraction.h.

## Constructor & Destructor Documentation

## ◆ NetworkError()

NetworkError::NetworkError | ( | int | error | ) |

Construct the network error with the given error code.

Parameters

  error | The error code.

Definition at line 31 of file os_abstraction.cpp.

## Member Function Documentation

## ◆ AsString()

const std::string & NetworkError::AsString | ( |  | ) | const

Get the string representation of the error message.

Returns
  The string representation that will get overwritten by next calls.

Definition at line 80 of file os_abstraction.cpp.

References error, FS2OTTD(), and message.

Referenced by TCPConnecter::CheckActivity(), TCPConnecter::Connect(), NetworkTCPSocketHandler::ReceivePacket(), NetworkUDPSocketHandler::SendPacket(), and NetworkTCPSocketHandler::SendPackets().

## ◆ GetLast()

NetworkError NetworkError::GetLast | ( |  | ) |
| static

Get the last network error.

Returns
  The network error.

Definition at line 118 of file os_abstraction.cpp.

Referenced by TCPConnecter::CheckActivity(), TCPConnecter::Connect(), NetworkAddress::GetPeerAddress(), NetworkAddress::GetSockAddress(), ListenLoopProc(), NetworkTCPSocketHandler::ReceivePacket(), NetworkUDPSocketHandler::SendPacket(), and NetworkTCPSocketHandler::SendPackets().

## ◆ HasError()

bool NetworkError::HasError | ( |  | ) | const

Check whether an error was actually set.

Returns
  True iff an error was set.

Definition at line 109 of file os_abstraction.cpp.

References error.

Referenced by TCPConnecter::CheckActivity().

## ◆ IsConnectInProgress()

bool NetworkError::IsConnectInProgress | ( |  | ) | const

Check whether this error describes a connect is in progress.

Returns
  True iff the connect is already in progress.

Definition at line 67 of file os_abstraction.cpp.

References error.

## ◆ IsConnectionReset()

bool NetworkError::IsConnectionReset | ( |  | ) | const

Check whether this error describes a connection reset.

Returns
  True iff the connection is reset.

Definition at line 54 of file os_abstraction.cpp.

References error.

Referenced by NetworkTCPSocketHandler::ReceivePacket().

## ◆ WouldBlock()

bool NetworkError::WouldBlock | ( |  | ) | const

Check whether this error describes that the operation would block.

Returns
  True iff the operation would block.

Definition at line 39 of file os_abstraction.cpp.

References error.

Referenced by NetworkTCPSocketHandler::ReceivePacket(), and NetworkTCPSocketHandler::SendPackets().

## Field Documentation

## ◆ error

int NetworkError::error
| private

The underlying error number from errno or WSAGetLastError.

Definition at line 23 of file os_abstraction.h.

Referenced by AsString(), HasError(), IsConnectInProgress(), IsConnectionReset(), and WouldBlock().

## ◆ message

std::string NetworkError::message
| mutableprivate

The string representation of the error (set on first call to AsString).

Definition at line 24 of file os_abstraction.h.

Referenced by AsString().

The documentation for this class was generated from the following files:

- src/network/core/os_abstraction.h
- src/network/core/os_abstraction.cpp