NetworkTCPSocketHandler Class Reference

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

#include <tcp.h>

Inheritance diagram for NetworkTCPSocketHandler:
NetworkSocketHandler NetworkClientSocket NetworkContentSocketHandler ClientNetworkContentSocketHandler

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.
void Send_Packet (Packet *packet)
 This function puts the packet in the send-queue and it is send as soon as possible.
bool Send_Packets (bool closing_down=false)
 Sends all the buffered packets out for this client.
bool IsPacketQueueEmpty ()
PacketRecv_Packet ()
 Receives a packet for the given client.
 NetworkTCPSocketHandler (SOCKET s=INVALID_SOCKET)

Data Fields

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

Private Attributes

Packetpacket_queue
 Packets that are awaiting delivery.
Packetpacket_recv
 Partially received packet.

Detailed Description

Base socket handler for all TCP sockets.

Definition at line 23 of file tcp.h.


Member Function Documentation

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 NetworkClientSocket.

Definition at line 36 of file tcp.cpp.

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

Referenced by NetworkContentSocketHandler::Close(), Recv_Packet(), and Send_Packets().

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 35 of file tcp.h.

References sock.

Referenced by Recv_Packet(), and Send_Packets().

Packet * NetworkTCPSocketHandler::Recv_Packet (  ) 

Receives a packet for the given client.

Parameters:
status the variable to store the status into
Returns:
the received packet (or NULL when it didn't receive one)

Definition at line 137 of file tcp.cpp.

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

Referenced by NetworkContentSocketHandler::Recv_Packets().

void NetworkTCPSocketHandler::Send_Packet ( 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)

Parameters:
packet the packet to send

Definition at line 59 of file tcp.cpp.

References Packet::next, packet_queue, and Packet::PrepareToSend().

bool NetworkTCPSocketHandler::Send_Packets ( 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.

Definition at line 86 of file tcp.cpp.

References Packet::buffer, CloseConnection(), IsConnected(), Packet::next, packet_queue, Packet::pos, Packet::size, sock, and writable.

Referenced by NetworkDisconnect(), and ClientNetworkContentSocketHandler::SendReceive().


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

Generated on Wed Feb 17 23:07:36 2010 for OpenTTD by  doxygen 1.6.1