OpenTTD Source: TCPServerConnecter Class Reference

OpenTTD Source 15.0-RC2

Public Member Functions | Data Fields | Private Member Functions | Private Attributes
TCPServerConnecter Class Reference
Inheritance diagram for TCPServerConnecter:

## Public Member Functions
| TCPServerConnecter (std::string_view connection_string, uint16_t default_port)
| Create a new connecter for the server.
void | SetConnected (SOCKET sock)
| The connection was successfully established.
void | SetFailure ()
| The connection couldn't be established.
Public Member Functions inherited from TCPConnecter
| TCPConnecter (std::string_view connection_string, uint16_t default_port, const NetworkAddress &bind_address={}, int family=AF_UNSPEC)
| Create a new connecter for the given address.
virtual void | OnConnect (SOCKET s)
| Callback when the connection succeeded.
virtual void | OnFailure ()
| Callback for when the connection attempt failed.
void | Kill ()
| Kill this connecter.

## Data Fields
ServerAddress | server_address
| Address we are connecting to.

## Private Member Functions
bool | CheckActivity () override
| Check if there was activity for this connecter.

## Private Attributes
SOCKET | socket = INVALID_SOCKET
| The socket when a connection is established.

## Additional Inherited Members
Static Public Member Functions inherited from TCPConnecter
static void | CheckCallbacks ()
| Check whether we need to call the callback, i.e.
static void | KillAll ()
| Kill all connection attempts.
template<class T , typename... Args>
static std::shared_ptr< TCPConnecter > | Create (Args &&... args)
| Create the connecter, and initiate connecting by putting it in the collection of TCP connections to make.

## Detailed Description

Definition at line 155 of file tcp.h.

## Constructor & Destructor Documentation

## ◆ TCPServerConnecter()

TCPServerConnecter::TCPServerConnecter | ( | std::string_view | connection_string,
|  | uint16_t | default_port
| ) |  |

Create a new connecter for the server.

Parameters

  connection_string | The address to connect to.
  default_port | If not indicated in connection_string, what port to use.

Definition at line 41 of file tcp_connect.cpp.

References _network_coordinator_client, TCPConnecter::Connecting, ServerAddress::connection_string, ClientNetworkCoordinatorSocketHandler::ConnectToServer(), server_address, SERVER_ADDRESS_DIRECT, SERVER_ADDRESS_INVITE_CODE, TCPConnecter::status, TCPServerConnecter(), and ServerAddress::type.

Referenced by TCPServerConnecter().

## Member Function Documentation

## ◆ CheckActivity()

bool TCPServerConnecter::CheckActivity | ( |  | ) |
| overrideprivatevirtual

Check if there was activity for this connecter.

Returns
  True iff the TCPConnecter is done and can be cleaned up.

Reimplemented from TCPConnecter.

Definition at line 405 of file tcp_connect.cpp.

References TCPConnecter::CheckActivity(), TCPConnecter::Connected, TCPConnecter::Failure, TCPConnecter::killed, TCPConnecter::OnConnect(), TCPConnecter::OnFailure(), server_address, SERVER_ADDRESS_DIRECT, SERVER_ADDRESS_INVITE_CODE, socket, TCPConnecter::status, and ServerAddress::type.

## ◆ SetConnected()

void TCPServerConnecter::SetConnected | ( | SOCKET | sock | ) |

The connection was successfully established.

This socket is fully setup and ready to send/recv game protocol packets.

Parameters

  sock | The socket of the established connection.

Definition at line 440 of file tcp_connect.cpp.

References TCPConnecter::Connected, socket, and TCPConnecter::status.

## ◆ SetFailure()

void TCPServerConnecter::SetFailure | ( |  | ) |

The connection couldn't be established.

Definition at line 451 of file tcp_connect.cpp.

References TCPConnecter::Failure, and TCPConnecter::status.

## Field Documentation

## ◆ server_address

ServerAddress TCPServerConnecter::server_address

Address we are connecting to.

Definition at line 162 of file tcp.h.

Referenced by CheckActivity(), and TCPServerConnecter().

## ◆ socket

SOCKET TCPServerConnecter::socket = INVALID_SOCKET
| private

The socket when a connection is established.

Definition at line 157 of file tcp.h.

Referenced by CheckActivity(), and SetConnected().

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

- src/network/core/tcp.h
- src/network/core/tcp_connect.cpp