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:
NetworkSocketHandler NetworkAdminSocketHandler NetworkContentSocketHandler NetworkGameSocketHandler ServerNetworkAdminSocketHandler ClientNetworkContentSocketHandler ClientNetworkGameSocketHandler ServerNetworkGameSocketHandler

Public Member Functions

bool IsConnected () const
 Whether this socket is currently bound to a socket. More...
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. More...
virtual void SendPacket (Packet *packet)
 This function puts the packet in the send-queue and it is send as soon as possible. More...
SendPacketsState SendPackets (bool closing_down=false)
 Sends all the buffered packets out for this client. More...
virtual PacketReceivePacket ()
 Receives a packet for the given client. More...
bool CanSendReceive ()
 Check whether this socket can send or receive something. More...
bool HasSendQueue ()
 Whether there is something pending in the send queue. More...
 NetworkTCPSocketHandler (SOCKET s=INVALID_SOCKET)
 Construct a socket handler for a TCP connection. More...
- 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. More...
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. More...
void ReceiveGRFIdentifier (Packet *p, GRFIdentifier *grf)
 Deserializes the GRFIdentifier (GRF ID and MD5 checksum) from the packet. More...
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. More...

Data Fields

 The socket currently connected to.
bool writable
 Can we write to this socket?

Private Attributes

 Packets that are awaiting delivery.
 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::NetworkTCPSocketHandler ( SOCKET  s = INVALID_SOCKET)

Construct a socket handler for a TCP connection.

sThe just opened TCP connection.

Definition at line 27 of file tcp.cpp.

References CloseConnection(), and sock.

Referenced by HasSendQueue().

Member Function Documentation

◆ CanSendReceive()

bool NetworkTCPSocketHandler::CanSendReceive ( )

Check whether this socket can send or receive something.

true when there is something to receive.
Sets writable if more data can be sent.

Definition at line 229 of file tcp.cpp.

References sock, and writable.

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

◆ CloseConnection()

NetworkRecvStatus NetworkTCPSocketHandler::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.

errorWhether we quit under an error condition or not.
new status of the connection.

Reimplemented from NetworkSocketHandler.

Reimplemented in NetworkGameSocketHandler, and NetworkAdminSocketHandler.

Definition at line 42 of file tcp.cpp.

References NetworkSocketHandler::CloseConnection(), NETWORK_RECV_STATUS_OKAY, Packet::next, packet_queue, packet_recv, and writable.

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

◆ HasSendQueue()

bool NetworkTCPSocketHandler::HasSendQueue ( )

Whether there is something pending in the send queue.

true when something is pending in the send queue.

Definition at line 57 of file tcp.h.

References NetworkTCPSocketHandler().

◆ IsConnected()

bool NetworkTCPSocketHandler::IsConnected ( ) const

Whether this socket is currently bound to a socket.

true when the socket is bound, false otherwise

Definition at line 43 of file tcp.h.

References CanSendReceive(), CloseConnection(), error(), ReceivePacket(), SendPacket(), and SendPackets().

Referenced by ReceivePacket(), and SendPackets().

◆ ReceivePacket()

Packet * NetworkTCPSocketHandler::ReceivePacket ( )

◆ SendPacket()

void NetworkTCPSocketHandler::SendPacket ( Packet packet)

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)

packetthe packet to send

Definition at line 65 of file tcp.cpp.

Referenced by ClientNetworkContentSocketHandler::DownloadSelectedContentFallback(), IsConnected(), 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::SendCompanyNew(), ClientNetworkGameSocketHandler::SendCompanyPassword(), ServerNetworkAdminSocketHandler::SendCompanyRemove(), ServerNetworkGameSocketHandler::SendCompanyUpdate(), ServerNetworkGameSocketHandler::SendConfigUpdate(), ServerNetworkAdminSocketHandler::SendConsole(), ServerNetworkAdminSocketHandler::SendDate(), ServerNetworkAdminSocketHandler::SendError(), ClientNetworkGameSocketHandler::SendError(), ServerNetworkGameSocketHandler::SendError(), ServerNetworkGameSocketHandler::SendErrorQuit(), ClientNetworkGameSocketHandler::SendGamePassword(), ServerNetworkAdminSocketHandler::SendGameScript(), ClientNetworkGameSocketHandler::SendGetMap(), ServerNetworkGameSocketHandler::SendJoin(), 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(), and ServerNetworkGameSocketHandler::SendWelcome().

◆ SendPackets()

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

closing_downWhether we are closing down the connection.
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 IsConnected(), NetworkDisconnect(), ServerNetworkAdminSocketHandler::Send(), ClientNetworkGameSocketHandler::Send(), and ClientNetworkContentSocketHandler::SendReceive().

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