Planeshift
psNetConnection Class Reference

Client-side UDP handler. More...

#include <connection.h>

Public Member Functions

virtual void Broadcast (MsgEntry *me, int scope, int guildID)
 Broadcasting makes no sense in a single connection class. Just wraps SendMessage. More...
 
bool Connect (const char *server, int port)
 Connects to the server and starts the thread to poll it. More...
 
virtual void DecRef ()
 Necessary CS definition and stub function. More...
 
void DisConnect ()
 Kills the thread and closes the socket. More...
 
virtual int GetRefCount ()
 
virtual void IncRef ()
 Necessary CS definition and stub function. More...
 
bool Initialize (iObjectRegistry *object_reg)
 Just some basic initialization for the class. More...
 
virtual void Multicast (MsgEntry *me, const csArray< PublishDestination > &multi, uint32_t except, float range)
 Multicasting makes no sense in a single connection class. Just wraps SendMessage. More...
 
 psNetConnection (int queueLength=100)
 Creates a queue of messages queueLength wide. More...
 
virtual ~psNetConnection ()
 Disconnects and terminates the thread. More...
 
- Public Member Functions inherited from NetBase
void AddFilterLogMessage (int type)
 Add a new message type to the LogMessage message filter list. More...
 
bool AddMsgQueue (MsgQueue *, objID minID=0, objID maxID=0xffffffff)
 This adds another message queue (for other threads) These queues are for reading off. More...
 
bool Bind (const char *addr, int port)
 Binds the socket to the specified address (only needed on server. More...
 
bool Bind (const IN_ADDR &addr, int port)
 
bool CheckIn (void)
 this receives an Incoming Packet and analyses it More...
 
bool Flush (MsgQueue *queue)
 Flush all messages in given queue. More...
 
iEngine * GetEngine ()
 Get the Engine. More...
 
csTicks GetPing (void)
 
psNetMsgProfilesGetProfs ()
 
uint32_t GetRandomID ()
 return a random ID that can be used for messages More...
 
void InvertLogMessageFilter ()
 Invert the LogMessage filter. More...
 
bool IsReady ()
 Is this connection ready to use? More...
 
csString LogMessageFilter (const char *arg)
 Pars and configure user filter settings. More...
 
void LogMessageFilterClear ()
 Clear all message type from the LogMessage message filter list. More...
 
void LogMessageFilterDump ()
 Dump the current filter settings. More...
 
void LogMessages (char dir, MsgEntry *me)
 Log the message to LOG_MESSAGE. More...
 
 NetBase (int outqueuelen=100)
 you can specify how much messages the ouptput queue can contain before being full. More...
 
void ProcessNetwork (csTicks timeout)
 This function is the heart of NetBase - it look for new incoming packets and sends packets in the outgoing queue. More...
 
bool QueueMessage (MsgEntry *me)
 This adds a completed message to any queues that are signed up. More...
 
void RemoveFilterLogMessage (int type)
 Remove a message type from the LogMessage message filter list. More...
 
void RemoveMsgQueue (MsgQueue *)
 this removes a queue More...
 
virtual bool SendMessage (MsgEntry *me)
 Put a message into the outgoing queue. More...
 
virtual bool SendMessage (MsgEntry *me, NetPacketQueueRefCount *queue)
 
bool SendOut (void)
 sendOut sends the next packet in the outgoing message queue More...
 
void SetEngine (iEngine *engine)
 Set the Engine. More...
 
void SetLogMessageFilterHex (bool filterhex)
 Set the filter hex messages flag. More...
 
void SetMsgStrings (csStringSet *msgstrings, csStringHashReversible *msgstringshash)
 Set the MsgString Hash. More...
 
void ToggleReceiveMessageFilter ()
 Toggle the global receive LogMessage filter. More...
 
void ToggleSendMessageFilter ()
 Toggle the global send LogMessage filter. More...
 
virtual ~NetBase ()
 

Protected Member Functions

void CheckLinkDead (csTicks time)
 This checks the time since the last packet received from the server. More...
 
virtual ConnectionGetConnByIP (LPSOCKADDR_IN addr)
 Returns the same address back if the address is correct. NULL if not. More...
 
virtual ConnectionGetConnByNum (uint32_t clientnum)
 Returns the server connection if the clientnum is 0. More...
 
virtual bool HandleUnknownClient (LPSOCKADDR_IN addr, MsgEntry *data)
 Another overridden function only used by multi-connection class NetManager. More...
 
void Run ()
 this is the main thread function... More...
 
- Protected Member Functions inherited from NetBase
bool BuildMessage (psNetPacketEntry *pkt, Connection *&connection, LPSOCKADDR_IN addr)
 This takes incoming packets and rebuilds psMessages from them. More...
 
csPtr< MsgEntryCheckCompleteMessage (uint32_t client, uint32_t id)
 This adds the incoming packet to the pending packets tree, and builds the psMessageBytes struct and MsgEntry struct if complete. More...
 
bool CheckDoublePackets (Connection *connection, psNetPacketEntry *pkt)
 This tries to drop packets that received doubled. More...
 
void CheckFragmentTimeouts (void)
 This checks the list of packets waiting to be assembled into complete messages. More...
 
void CheckResendPkts (void)
 This cycles through set of pkts awaiting ack and resends old ones. More...
 
void Close (bool force=true)
 
bool FilterLogMessage (int type, char dir)
 Check if the given message type should be logged or not. More...
 
int GetIPByName (LPSOCKADDR_IN addr, const char *name)
 some helper functions... More...
 
bool HandleAck (psNetPacketEntry *pkt, Connection *connection, LPSOCKADDR_IN addr)
 This takes incoming packets and examines them for priority. More...
 
void HandleCompletedMessage (MsgEntry *me, Connection *&connection, LPSOCKADDR_IN addr, psNetPacketEntry *pkt)
 This receives only fully reassembled messages and adds to appropriate queues. More...
 
bool Init (bool autobind=true)
 This initialises the socket lib and creates a listening UDP socket, if you're the client you should set port to zero, so a random free port is user. More...
 
int RecvFrom (LPSOCKADDR_IN addr, socklen_t *socklen, void *buf, unsigned int maxsize)
 small inliner for receiving packets... More...
 
bool SendFinalPacket (psNetPacketEntry *pkt)
 Send packet to the clientnum given by clientnum in psNetPacketEntry. More...
 
bool SendFinalPacket (psNetPacketEntry *pkt, LPSOCKADDR_IN addr)
 This only sends out a packet. More...
 
bool SendMergedPackets (NetPacketQueue *q)
 This attempts to merge as many packets as possible into one before sending. More...
 
bool SendSinglePacket (psNetPacketEntry *pkt)
 This does the sending and puts the packet in "awaiting ack" if necessary. More...
 
int SendTo (LPSOCKADDR_IN addr, const void *data, unsigned int size)
 Wrapper to encapsulate the sendto call and provide for retry if the buffer is full. More...
 

Protected Attributes

MsgQueueinQueue
 This is the inbound queue to the client. More...
 
iObjectRegistry * object_reg
 
Connectionserver
 Connection class holds the IP address and port we are using here. More...
 
bool shouldRun
 When this is false, thread will finish it's last loop and exit. More...
 
- Protected Attributes inherited from NetBase
unsigned int avgIndex
 
csHash< csRef< psNetPacketEntry >, PacketKeyawaitingack
 Packets Awaiting Ack pool. More...
 
csArray< MsgQueue * > inqueues
 Incoming message queue vector. More...
 
csTicks lastSendReport
 
csRef< NetPacketQueueRefCountNetworkQueue
 Outgoing message queue. More...
 
psNetMsgProfilesprofs
 
bool ready
 is the connection ready? More...
 
unsigned int resendIndex
 
size_t resends [RESENDAVGCOUNT]
 
GenericRefQueue< NetPacketQueueRefCount, csWeakRef > senders
 weak referenced list of outbound queues with waiting data so disconnected clients won't receive packets More...
 
SendQueueStats_t sendStats [NETAVGCOUNT]
 
long totalcountin
 total packages transferred by this object More...
 
long totalcountout
 
long totaltransferin
 total bytes transferred by this object More...
 
long totaltransferout
 

Additional Inherited Members

- Public Types inherited from NetBase
enum  broadcasttype {
  BC_EVERYONEBUTSELF = 1, BC_GROUP = 2, BC_GUILD = 3, BC_SECTOR = 4,
  BC_EVERYONE = 5, BC_FINALPACKET = 6
}
 
- Static Public Member Functions inherited from NetBase
static AccessPointersGetAccessPointers ()
 Get the access pointers. More...
 
- Public Attributes inherited from NetBase
struct timeval timeout
 The timeout to use when waiting for new incoming packets. More...
 
- Static Protected Attributes inherited from NetBase
static int socklibrefcount
 System Socket lib initialized? More...
 

Detailed Description

Client-side UDP handler.

Implementation of client side network connection on top of the common network code in psnet. For details about the functions look at connection.h and netbase.h. This class differs from NetManager in that it only has a single connection (to the server) as opposed to NetManager which is managing many client connections at once. This means several functions are overridden as empty functions because they aren't relevant with a single connection.

Definition at line 42 of file connection.h.

Constructor & Destructor Documentation

psNetConnection::psNetConnection ( int  queueLength = 100)

Creates a queue of messages queueLength wide.

virtual psNetConnection::~psNetConnection ( )
virtual

Disconnects and terminates the thread.

Member Function Documentation

virtual void psNetConnection::Broadcast ( MsgEntry me,
int  scope,
int  guildID 
)
virtual

Broadcasting makes no sense in a single connection class. Just wraps SendMessage.

Implements NetBase.

void psNetConnection::CheckLinkDead ( csTicks  time)
protected

This checks the time since the last packet received from the server.

This function tracks how long it has been since the last packet was received from the server. If it has been longer than LINKDEAD_TIMEOUT msec, then it attempts to send a packet to the server just to get a response. If this goes longer than 5 retries, it kills the client.

bool psNetConnection::Connect ( const char *  server,
int  port 
)

Connects to the server and starts the thread to poll it.

Opens a non-blocking UDP socket to the specified server on the specified port, and kicks off the thread which will handle sending and receiving on this socket.

Parameters
serverThe text hostname or IP address of the destination
portThe port number to try on the server.
Returns
True if successful connection is made, false if error.
virtual void psNetConnection::DecRef ( )
inlinevirtual

Necessary CS definition and stub function.

Definition at line 79 of file connection.h.

void psNetConnection::DisConnect ( )

Kills the thread and closes the socket.

virtual Connection* psNetConnection::GetConnByIP ( LPSOCKADDR_IN  addr)
protectedvirtual

Returns the same address back if the address is correct. NULL if not.

Implements NetBase.

virtual Connection* psNetConnection::GetConnByNum ( uint32_t  clientnum)
protectedvirtual

Returns the server connection if the clientnum is 0.

Implements NetBase.

virtual int psNetConnection::GetRefCount ( )
inlinevirtual

Definition at line 82 of file connection.h.

virtual bool psNetConnection::HandleUnknownClient ( LPSOCKADDR_IN  addr,
MsgEntry data 
)
protectedvirtual

Another overridden function only used by multi-connection class NetManager.

Implements NetBase.

virtual void psNetConnection::IncRef ( )
inlinevirtual

Necessary CS definition and stub function.

Definition at line 76 of file connection.h.

bool psNetConnection::Initialize ( iObjectRegistry *  object_reg)

Just some basic initialization for the class.

virtual void psNetConnection::Multicast ( MsgEntry me,
const csArray< PublishDestination > &  multi,
uint32_t  except,
float  range 
)
virtual

Multicasting makes no sense in a single connection class. Just wraps SendMessage.

Implements NetBase.

void psNetConnection::Run ( )
protected

this is the main thread function...

Member Data Documentation

MsgQueue* psNetConnection::inQueue
protected

This is the inbound queue to the client.

This class adds messages to this queue, and ClientMsgHandler pulls them out of this queue.

See also
ClientMsgHandler.

Definition at line 106 of file connection.h.

iObjectRegistry* psNetConnection::object_reg
protected

Definition at line 110 of file connection.h.

Connection* psNetConnection::server
protected

Connection class holds the IP address and port we are using here.

Definition at line 109 of file connection.h.

bool psNetConnection::shouldRun
protected

When this is false, thread will finish it's last loop and exit.

Definition at line 113 of file connection.h.


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