OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- Data Structures
- Class Hierarchy
- Data Fields

Public Member Functions | Data Fields | Private Attributes
NetworkTCPSocketHandler Class Reference

Base socket handler for all TCP sockets. More...

`#include <tcp.h>`

Inheritance diagram for NetworkTCPSocketHandler:

## Public Member Functions
bool | IsConnected () const
| Whether this socket is currently bound to a socket.
virtual NetworkRecvStatus | CloseConnection (bool error=true)
| Close the current connection; for TCP this will be mostly equivalent to Close(), but for UDP it just means the packet has to be dropped.
virtual void | SendPacket (Packet *packet)
| This function puts the packet in the send-queue and it is send as soon as possible.
SendPacketsState | SendPackets (bool closing_down=false)
| Sends all the buffered packets out for this client.
virtual Packet * | ReceivePacket ()
| Receives a packet for the given client.
bool | CanSendReceive ()
| Check whether this socket can send or receive something.
bool | HasSendQueue ()
| Whether there is something pending in the send queue.
| NetworkTCPSocketHandler (SOCKET s=INVALID_SOCKET)
| Construct a socket handler for a TCP connection.
Public Member Functions inherited from NetworkSocketHandler
| NetworkSocketHandler ()
| Create a new unbound socket.
virtual | ~NetworkSocketHandler ()
| Close the socket when destructing the socket handler.
virtual void | Close ()
| Really close the socket.
bool | HasClientQuit () const
| Whether the current client connected to the socket has quit.
void | Reopen ()
| Reopen the socket so we can send/receive stuff again.
void | SendGRFIdentifier (Packet *p, const GRFIdentifier *grf)
| Serializes the GRFIdentifier (GRF ID and MD5 checksum) to the packet.
void | ReceiveGRFIdentifier (Packet *p, GRFIdentifier *grf)
| Deserializes the GRFIdentifier (GRF ID and MD5 checksum) from the packet.
void | SendCompanyInformation (Packet *p, const struct Company *c, const struct NetworkCompanyStats *stats, uint max_len=NETWORK_COMPANY_NAME_LENGTH)
| Package some generic company information into a packet.

## Data Fields
SOCKET | sock
| The socket currently connected to.
bool | writable
| Can we write to this socket?

## Private Attributes
Packet * | packet_queue
| Packets that are awaiting delivery.
Packet * | packet_recv
| Partially received packet.

## Detailed Description

Base socket handler for all TCP sockets.

Definition at line 31 of file tcp.h.

## Constructor & Destructor Documentation

NetworkTCPSocketHandler::NetworkTCPSocketHandler | ( | SOCKET | s = `INVALID_SOCKET` | ) |

Construct a socket handler for a TCP connection.

Parameters

  s | The just opened TCP connection.

Definition at line 27 of file tcp.cpp.

## Member Function Documentation

bool NetworkTCPSocketHandler::CanSendReceive | ( |  | ) |

Check whether this socket can send or receive something.

Returns
  `true` when there is something to receive.

Note
  Sets writable if more data can be sent.

Definition at line 229 of file tcp.cpp.

References sock, and writable.

Referenced by ClientNetworkGameSocketHandler::Receive(), and ClientNetworkContentSocketHandler::SendReceive().

NetworkRecvStatus NetworkTCPSocketHandler::CloseConnection | ( | bool | error = `true` | ) |
| virtual

Close the current connection; for TCP this will be mostly equivalent to Close(), but for UDP it just means the packet has to be dropped.

Parameters

  error | Whether we quit under an error condition or not.

Returns
  new status of the connection.

Reimplemented from NetworkSocketHandler.

Reimplemented in NetworkGameSocketHandler, and NetworkAdminSocketHandler.

Definition at line 42 of file tcp.cpp.

References NETWORK_RECV_STATUS_OKAY, Packet::next, packet_queue, packet_recv, and writable.

Referenced by NetworkContentSocketHandler::Close(), ReceivePacket(), and SendPackets().

bool NetworkTCPSocketHandler::HasSendQueue | ( |  | ) |
| inline

Whether there is something pending in the send queue.

Returns
  true when something is pending in the send queue.

Definition at line 57 of file tcp.h.

References packet_queue.

bool NetworkTCPSocketHandler::IsConnected | ( |  | ) | const
| inline

Whether this socket is currently bound to a socket.

Returns
  true when the socket is bound, false otherwise

Definition at line 43 of file tcp.h.

References sock.

Referenced by ReceivePacket(), and SendPackets().

Packet * NetworkTCPSocketHandler::ReceivePacket | ( |  | ) |
| virtual

Receives a packet for the given client.

Returns
  The received packet (or NULL when it didn't receive one)

Reimplemented in ServerNetworkGameSocketHandler.

Definition at line 149 of file tcp.cpp.

References Packet::buffer, CloseConnection(), DEBUG, IsConnected(), packet_recv, Packet::pos, Packet::PrepareToRead(), Packet::ReadRawPacketSize(), SEND_MTU, Packet::size, and sock.

Referenced by NetworkContentSocketHandler::ReceivePackets(), NetworkAdminSocketHandler::ReceivePackets(), and NetworkGameSocketHandler::ReceivePackets().

void NetworkTCPSocketHandler::SendPacket | ( | Packet * | packet | ) |
| virtual

This function puts the packet in the send-queue and it is send as soon as possible.

This is the next tick, or maybe one tick later if the OS-network-buffer is full)

Parameters

  packet | the packet to send

Definition at line 65 of file tcp.cpp.

References Packet::buffer, Packet::next, packet_queue, Packet::PrepareToSend(), ReallocT(), and Packet::size.

Referenced by ClientNetworkContentSocketHandler::DownloadSelectedContentFallback(), ClientNetworkContentSocketHandler::RequestContentList(), ClientNetworkGameSocketHandler::SendAck(), ServerNetworkAdminSocketHandler::SendChat(), ClientNetworkGameSocketHandler::SendChat(), ServerNetworkGameSocketHandler::SendChat(), ServerNetworkAdminSocketHandler::SendClientError(), ServerNetworkAdminSocketHandler::SendClientInfo(), ServerNetworkGameSocketHandler::SendClientInfo(), ServerNetworkAdminSocketHandler::SendClientJoin(), ServerNetworkAdminSocketHandler::SendClientQuit(), ServerNetworkAdminSocketHandler::SendClientUpdate(), ServerNetworkAdminSocketHandler::SendCmdLogging(), ServerNetworkAdminSocketHandler::SendCmdNames(), ClientNetworkGameSocketHandler::SendCommand(), ServerNetworkGameSocketHandler::SendCommand(), ServerNetworkAdminSocketHandler::SendCompanyEconomy(), ServerNetworkGameSocketHandler::SendCompanyInfo(), ServerNetworkAdminSocketHandler::SendCompanyInfo(), ClientNetworkGameSocketHandler::SendCompanyInformationQuery(), ServerNetworkAdminSocketHandler::SendCompanyNew(), ClientNetworkGameSocketHandler::SendCompanyPassword(), ServerNetworkAdminSocketHandler::SendCompanyRemove(), ServerNetworkAdminSocketHandler::SendCompanyStats(), ServerNetworkAdminSocketHandler::SendCompanyUpdate(), ServerNetworkGameSocketHandler::SendCompanyUpdate(), ServerNetworkGameSocketHandler::SendConfigUpdate(), ServerNetworkAdminSocketHandler::SendConsole(), ServerNetworkAdminSocketHandler::SendDate(), ServerNetworkAdminSocketHandler::SendError(), ClientNetworkGameSocketHandler::SendError(), ServerNetworkGameSocketHandler::SendError(), ServerNetworkGameSocketHandler::SendErrorQuit(), ServerNetworkGameSocketHandler::SendFrame(), ClientNetworkGameSocketHandler::SendGamePassword(), ServerNetworkAdminSocketHandler::SendGameScript(), ClientNetworkGameSocketHandler::SendGetMap(), ClientNetworkGameSocketHandler::SendJoin(), ServerNetworkGameSocketHandler::SendJoin(), ServerNetworkGameSocketHandler::SendMap(), ClientNetworkGameSocketHandler::SendMapOk(), ServerNetworkGameSocketHandler::SendMove(), ClientNetworkGameSocketHandler::SendMove(), ServerNetworkGameSocketHandler::SendNeedCompanyPassword(), ServerNetworkGameSocketHandler::SendNeedGamePassword(), ServerNetworkAdminSocketHandler::SendNewGame(), ServerNetworkGameSocketHandler::SendNewGame(), ServerNetworkGameSocketHandler::SendNewGRFCheck(), ClientNetworkGameSocketHandler::SendNewGRFsOk(), ServerNetworkAdminSocketHandler::SendPong(), ServerNetworkAdminSocketHandler::SendProtocol(), ServerNetworkGameSocketHandler::SendQuit(), ClientNetworkGameSocketHandler::SendQuit(), ServerNetworkAdminSocketHandler::SendRcon(), ClientNetworkGameSocketHandler::SendRCon(), ServerNetworkAdminSocketHandler::SendRconEnd(), ServerNetworkGameSocketHandler::SendRConResult(), ClientNetworkGameSocketHandler::SendSetName(), ClientNetworkGameSocketHandler::SendSetPassword(), ServerNetworkAdminSocketHandler::SendShutdown(), ServerNetworkGameSocketHandler::SendShutdown(), ServerNetworkGameSocketHandler::SendSync(), ServerNetworkGameSocketHandler::SendWait(), ServerNetworkGameSocketHandler::SendWelcome(), and ServerNetworkAdminSocketHandler::SendWelcome().

SendPacketsState NetworkTCPSocketHandler::SendPackets | ( | bool | closing_down = `false` | ) |

Sends all the buffered packets out for this client.

It stops when: 1) all packets are send (queue is empty) 2) the OS reports back that it can not send any more data right now (full network-buffer, it happens ;)) 3) sending took too long

Parameters

  closing_down | Whether we are closing down the connection.

Returns
  `true` if a (part of a) packet could be sent and the connection is not closed yet.

Definition at line 99 of file tcp.cpp.

References Packet::buffer, CloseConnection(), DEBUG, IsConnected(), Packet::next, packet_queue, Packet::pos, Packet::size, sock, SPS_ALL_SENT, SPS_CLOSED, SPS_NONE_SENT, SPS_PARTLY_SENT, and writable.

Referenced by ClientNetworkGameSocketHandler::CloseConnection(), ServerNetworkGameSocketHandler::CloseConnection(), NetworkDisconnect(), ServerNetworkAdminSocketHandler::Send(), ClientNetworkGameSocketHandler::Send(), ServerNetworkGameSocketHandler::SendMap(), and ClientNetworkContentSocketHandler::SendReceive().

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

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