NetworkUDPSocketHandler Class Reference

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

#include <udp.h>

Inheritance diagram for NetworkUDPSocketHandler:
NetworkSocketHandler ClientNetworkUDPSocketHandler MasterNetworkUDPSocketHandler ServerNetworkUDPSocketHandler

Public Member Functions

 NetworkUDPSocketHandler (NetworkAddressList *bind=NULL)
 Create an UDP socket but don't listen yet.
virtual ~NetworkUDPSocketHandler ()
 On destructing of this class, the socket needs to be closed.
bool Listen ()
 Start listening on the given host and port.
void Close ()
 Close the given UDP socket.
void SendPacket (Packet *p, NetworkAddress *recv, bool all=false, bool broadcast=false)
 Send a packet over UDP.
void ReceivePackets ()
 Receive a packet at UDP level.
void Send_NetworkGameInfo (Packet *p, const NetworkGameInfo *info)
 Serializes the NetworkGameInfo struct to the packet.
void Recv_NetworkGameInfo (Packet *p, NetworkGameInfo *info)
 Deserializes the NetworkGameInfo struct from the packet.

Protected Member Functions

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.
 DECLARE_UDP_RECEIVE_COMMAND (PACKET_UDP_CLIENT_FIND_SERVER)
 DECLARE_UDP_RECEIVE_COMMAND (PACKET_UDP_SERVER_RESPONSE)
 DECLARE_UDP_RECEIVE_COMMAND (PACKET_UDP_CLIENT_DETAIL_INFO)
 DECLARE_UDP_RECEIVE_COMMAND (PACKET_UDP_SERVER_DETAIL_INFO)
 DECLARE_UDP_RECEIVE_COMMAND (PACKET_UDP_SERVER_REGISTER)
 DECLARE_UDP_RECEIVE_COMMAND (PACKET_UDP_MASTER_ACK_REGISTER)
 DECLARE_UDP_RECEIVE_COMMAND (PACKET_UDP_CLIENT_GET_LIST)
 DECLARE_UDP_RECEIVE_COMMAND (PACKET_UDP_MASTER_RESPONSE_LIST)
 DECLARE_UDP_RECEIVE_COMMAND (PACKET_UDP_SERVER_UNREGISTER)
 DECLARE_UDP_RECEIVE_COMMAND (PACKET_UDP_CLIENT_GET_NEWGRFS)
 DECLARE_UDP_RECEIVE_COMMAND (PACKET_UDP_SERVER_NEWGRFS)
 DECLARE_UDP_RECEIVE_COMMAND (PACKET_UDP_MASTER_SESSION_KEY)
void HandleUDPPacket (Packet *p, NetworkAddress *client_addr)
 Handle an incoming packets by sending it to the correct function.
virtual void HandleIncomingNetworkGameInfoGRFConfig (GRFConfig *config)
 Function that is called for every GRFConfig that is read when receiving a NetworkGameInfo.

Protected Attributes

NetworkAddressList bind
 The address to bind to.
SocketList sockets
 The opened sockets.

Detailed Description

Base socket handler for all UDP sockets.

Definition at line 110 of file udp.h.


Constructor & Destructor Documentation

NetworkUDPSocketHandler::NetworkUDPSocketHandler ( NetworkAddressList bind = NULL  ) 

Create an UDP socket but don't listen yet.

Parameters:
bind the addresses to bind to.

Definition at line 25 of file udp.cpp.

References SmallVector< T, S >::Append(), SmallVector< T, S >::Begin(), and SmallVector< T, S >::End().


Member Function Documentation

NetworkRecvStatus NetworkUDPSocketHandler::CloseConnection ( bool  error = true  )  [protected, 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.

Definition at line 68 of file udp.cpp.

References NETWORK_RECV_STATUS_OKAY.

virtual void NetworkUDPSocketHandler::HandleIncomingNetworkGameInfoGRFConfig ( GRFConfig config  )  [inline, protected, virtual]

Function that is called for every GRFConfig that is read when receiving a NetworkGameInfo.

Only grfid and md5sum are set, the rest is zero. This function must set all appropriate fields. This GRF is later appended to the grfconfig list of the NetworkGameInfo.

Parameters:
config the GRF to handle

Reimplemented in ClientNetworkUDPSocketHandler.

Definition at line 143 of file udp.h.

Referenced by Recv_NetworkGameInfo().

void NetworkUDPSocketHandler::HandleUDPPacket ( Packet p,
NetworkAddress client_addr 
) [protected]
bool NetworkUDPSocketHandler::Listen (  ) 

Start listening on the given host and port.

Returns:
true if at least one port is listening

Definition at line 45 of file udp.cpp.

References SmallVector< T, S >::Begin(), bind, Close(), SmallVector< T, S >::End(), SmallVector< T, S >::Length(), and sockets.

Referenced by SendPacket().

void NetworkUDPSocketHandler::Recv_NetworkGameInfo ( Packet p,
NetworkGameInfo info 
)
void NetworkUDPSocketHandler::Send_NetworkGameInfo ( Packet p,
const NetworkGameInfo info 
)
void NetworkUDPSocketHandler::SendPacket ( Packet p,
NetworkAddress recv,
bool  all = false,
bool  broadcast = false 
)

Send a packet over UDP.

Parameters:
p the packet to send
recv the receiver (target) of the packet
all send the packet using all sockets that can send it
broadcast whether to send a broadcast message

Definition at line 81 of file udp.cpp.

References SmallVector< T, S >::Begin(), Packet::buffer, SmallVector< T, S >::End(), NetworkAddress::GetAddress(), NetworkAddress::GetAddressAsString(), NetworkAddress::GetAddressLength(), NetworkAddress::IsFamily(), SmallVector< T, S >::Length(), Listen(), Packet::PrepareToSend(), Packet::size, and sockets.

Referenced by NetworkUDPQueryServerThread().


Field Documentation

The address to bind to.

Definition at line 113 of file udp.h.

Referenced by Listen().

The opened sockets.

Definition at line 115 of file udp.h.

Referenced by Close(), Listen(), ReceivePackets(), and SendPacket().


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

Generated on Sun Nov 14 14:42:53 2010 for OpenTTD by  doxygen 1.6.1