OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
12 #ifndef NETWORK_CORE_TCP_H
13 #define NETWORK_CORE_TCP_H
41 bool IsConnected()
const {
return this->sock != INVALID_SOCKET; }
static void CheckCallbacks()
Check whether we need to call the callback, i.e.
TCPConnecter(const NetworkAddress &address)
Create a new connecter for the given address.
virtual void OnConnect(SOCKET s)
Callback when the connection succeeded.
std::atomic< bool > aborted
Whether we bailed out (i.e. connection making failed)
"Helper" class for creating TCP connections in a non-blocking manner
SocketHandler for all network sockets in OpenTTD.
@ SPS_CLOSED
The connection got closed.
bool IsConnected() const
Whether this socket is currently bound to a socket.
SOCKET sock
The socket currently connected to.
@ SPS_ALL_SENT
All packets in the queue are sent.
virtual Packet * ReceivePacket()
Receives a packet for the given client.
Packet * packet_recv
Partially received packet.
SendPacketsState
The states of sending the packets.
NetworkRecvStatus CloseConnection(bool error=true) override
Close the current connection; for TCP this will be mostly equivalent to Close(), but for UDP it just ...
bool killed
Whether we got killed.
virtual void SendPacket(Packet *packet)
This function puts the packet in the send-queue and it is send as soon as possible.
bool HasSendQueue()
Whether there is something pending in the send queue.
Internal entity of a packet.
static void KillAll()
Kill all connection attempts.
NetworkAddress address
Address we're connecting to.
NetworkTCPSocketHandler(SOCKET s=INVALID_SOCKET)
Construct a socket handler for a TCP connection.
bool writable
Can we write to this socket?
@ SPS_NONE_SENT
The buffer is still full, so no (parts of) packets could be sent.
SOCKET sock
The socket we're connecting with.
SendPacketsState SendPackets(bool closing_down=false)
Sends all the buffered packets out for this client.
Wrapper for (un)resolved network addresses; there's no reason to transform a numeric IP to a string a...
bool CanSendReceive()
Check whether this socket can send or receive something.
std::atomic< bool > connected
Whether we succeeded in making the connection.
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
static void ThreadEntry(TCPConnecter *param)
Entry point for the new threads.
virtual ~TCPConnecter()
Silence the warnings.
virtual void OnFailure()
Callback for when the connection attempt failed.
void Connect()
The actual connection function.
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
@ SPS_PARTLY_SENT
The packets are partly sent; there are more packets to be sent in the queue.
Base socket handler for all TCP sockets.
Packet * packet_queue
Packets that are awaiting delivery.