OpenTTD Source: TCPConnecter Class Reference

OpenTTD Source 1.11.0-RC1

Public Member Functions | Static Public Member Functions | Protected Attributes | Private Member Functions | Static Private Member Functions | Private Attributes
TCPConnecter Class Reference

"Helper" class for creating TCP connections in a non-blocking manner More...

`#include <tcp.h>`

Inheritance diagram for TCPConnecter:

## Public Member Functions
| TCPConnecter (const NetworkAddress &address)
| Create a new connecter for the given address. More...
virtual | ~TCPConnecter ()
| Silence the warnings.
virtual void | OnConnect (SOCKET s)
| Callback when the connection succeeded. More...
virtual void | OnFailure ()
| Callback for when the connection attempt failed.

## Static Public Member Functions
static void | CheckCallbacks ()
| Check whether we need to call the callback, i.e. More...
static void | KillAll ()
| Kill all connection attempts.

## Protected Attributes
NetworkAddress | address
| Address we're connecting to.

## Private Member Functions
void | Connect ()
| The actual connection function.

## Static Private Member Functions
static void | ThreadEntry (TCPConnecter *param)
| Entry point for the new threads. More...

## Private Attributes
std::atomic< bool > | connected
| Whether we succeeded in making the connection.
std::atomic< bool > | aborted
| Whether we bailed out (i.e. connection making failed)
bool | killed
| Whether we got killed.
SOCKET | sock
| The socket we're connecting with.

## Detailed Description

"Helper" class for creating TCP connections in a non-blocking manner

Definition at line 64 of file tcp.h.

## Constructor & Destructor Documentation

## ◆ TCPConnecter()

TCPConnecter::TCPConnecter | ( | const NetworkAddress & | address | ) |

Create a new connecter for the given address.

Parameters

  address | the (un)resolved address to connect to

Definition at line 26 of file tcp_connect.cpp.

References _tcp_connecters, Connect(), StartNewThread(), and ThreadEntry().

## Member Function Documentation

## ◆ CheckCallbacks()

void TCPConnecter::CheckCallbacks | ( |  | ) |
| static

Check whether we need to call the callback, i.e.

whether we have connected or aborted and call the appropriate callback for that. It's done this way to ease on the locking that would otherwise be needed everywhere.

Definition at line 65 of file tcp_connect.cpp.

References _tcp_connecters, aborted, connected, killed, OnConnect(), OnFailure(), and sock.

Referenced by NetworkBackgroundLoop().

## ◆ OnConnect()

virtual void TCPConnecter::OnConnect | ( | SOCKET | s | ) |
| inlinevirtual

Callback when the connection succeeded.

Parameters

  s | the socket that we opened

Reimplemented in NetworkContentConnecter, TCPClientConnecter, TCPQueryConnecter, and NetworkHTTPContentConnecter.

Definition at line 88 of file tcp.h.

Referenced by CheckCallbacks().

## ◆ ThreadEntry()

void TCPConnecter::ThreadEntry | ( | TCPConnecter * | param | ) |
| staticprivate

Entry point for the new threads.

Parameters

  param | the TCPConnecter instance to call Connect on.

Definition at line 54 of file tcp_connect.cpp.

References Connect().

Referenced by TCPConnecter().

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

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