Public Member Functions | Public Attributes | Protected Types | Protected Member Functions | Protected Attributes

kNet::MessageConnection Class Reference

Represents a single established network connection. More...

#include <MessageConnection.h>

Inheritance diagram for kNet::MessageConnection:
Inheritance graph
[legend]
Collaboration diagram for kNet::MessageConnection:
Collaboration graph
[legend]

List of all members.

Public Member Functions

ConnectionState GetConnectionState () const
 Returns the current connection state.
bool IsReadOpen () const
 Returns true if the peer has signalled it will not send any more data (the connection is half-closed or full-closed).
bool IsWriteOpen () const
 Returns true if we have signalled not to send any more data (the connection is half-closed or full-closed).
bool IsPending () const
 Returns true if the connection is in the ConnectionPending state and waiting for the other end to resolve/establish the connection.
bool Connected () const
 Returns true if this socket is connected, i.e. at least half-open in one way.
void RunModalClient ()
 Runs a modal processing loop and produces events for all inbound received data.
bool WaitToEstablishConnection (int maxMSecsToWait=500)
 Blocks for the given amount of time until the connection has transitioned away from ConnectionPending state.
void Disconnect (int maxMSecsToWait=500)
 Starts a benign disconnect procedure.
void Close (int maxMSecsToWait=500)
 Starts a forceful disconnect procedure.
NetworkMessageStartNewMessage (unsigned long id, size_t numBytes=0)
 Start building a new message with the given ID.
void EndAndQueueMessage (NetworkMessage *msg, size_t numBytes=(size_t)(-1), bool internalQueue=false)
 Finishes building the message and submits it to the outbound send queue.
void SendMessage (unsigned long id, bool reliable, bool inOrder, unsigned long priority, unsigned long contentID, const char *data, size_t numBytes)
 This is a conveniency function to access the above StartNewMessage/EndAndQueueMessage pair.
template<typename SerializableData >
void SendStruct (const SerializableData &data, unsigned long id, bool inOrder, bool reliable, unsigned long priority, unsigned long contentID=0)
 Sends a message using a serializable structure.
template<typename SerializableMessage >
void Send (const SerializableMessage &data, unsigned long contentID=0)
 Sends a message using a compiled message structure.
void PauseOutboundSends ()
 Stops all outbound sends until ResumeOutboundSends is called.
void ResumeOutboundSends ()
 Resumes sending of outbound messages.
size_t NumInboundMessagesPending () const
 Returns the number of messages that have been received from the network but haven't been handled by the application yet.
size_t NumOutboundMessagesPending () const
 Returns the number of messages in the outbound queue that are pending to be sent.
SocketGetSocket ()
 Returns the underlying raw socket. [main and worker thread].
EndPoint LocalEndPoint () const
 Returns an object that identifies the local endpoint (IP and port) this connection is connected to.
EndPoint RemoteEndPoint () const
 Returns an object that identifies the remote endpoint (IP and port) this connection is connected to.
void SetMaximumDataSendRate (int numBytesPerSec, int numDatagramsPerSec)
 Sets an upper limit to the data send rate for this connection.
void RegisterInboundMessageHandler (IMessageHandler *handler)
 Registers a new listener object for the events of this connection.
void Process (int maxMessagesToProcess=100)
 Fetches all newly received messages waiting in the inbound queue, and passes each of these to the message handler registered using RegisterInboundMessageHandler.
void WaitForMessage (int maxMSecsToWait)
 Waits for at most the given amount of time until a new message is received for processing.
NetworkMessageReceiveMessage (int maxMSecsToWait=-1)
 Returns the next message in the inbound queue.
void FreeMessage (NetworkMessage *msg)
 Frees up a NetworkMessage struct when it is no longer needed.
std::string ToString () const
 Returns a single-line message describing the connection state.
void DumpStatus () const
 Dumps a long multi-line status message of this connection state to stdout.
float RoundTripTime () const
 Returns the estimated RTT of the connection, in milliseconds. RTT is the time taken to communicate a message from client->host->client.
float Latency () const
 Returns the estimated delay time from this connection to host, in milliseconds.
float LastHeardTime () const
 Returns the number of milliseconds since we last received data from the socket.

Public Attributes

Lockable< ConnectionStatisticsstatistics
 Stores all the statistics about the current connection.

Protected Types

enum  PacketSendResult {
  PacketSendOK, PacketSendSocketClosed, PacketSendSocketFull, PacketSendNoMessages,
  PacketSendThrottled
}
 

Specifies the return value for the functions that send out network packets.

More...
enum  SocketReadResult { SocketReadOK, SocketReadError, SocketReadThrottled }
 

Specifies the result of a Socket read activity.

More...
typedef std::pair< u32, u32MsgContentIDPair
 A (messageID, contentID) pair.

Protected Member Functions

virtual PacketSendResult SendOutPacket ()=0
 Serializes several messages into a single UDP/TCP packet and sends it out to the wire.
virtual void SendOutPackets ()=0
 Sends out as many packets at one go as is allowed by the current send rate of the connection.
virtual unsigned long TimeUntilCanSendPacket () const =0
 Returns how many milliseconds need to be waited before this socket can try sending data the next time.
void UpdateConnection ()
 Performs the internal work tick that updates this connection.
virtual void DoUpdateConnection ()
 Overridden by a subclass of MessageConnection to do protocol-specific updates (private implementation -pattern).
void SetPeerClosed ()
 Marks that the peer has closed the connection and will not send any more application-level data.
Event NewOutboundMessagesEvent () const
 Posted when the application has pushed us some messages to handle.
virtual SocketReadResult ReadSocket (size_t &bytesRead)=0
 Reads all the new bytes available in the socket.
void SetWorkerThread (NetworkWorkerThread *thread)
 Sets the worker thread object that will handle this connection.
void HandleInboundMessage (packet_id_t packetID, const char *data, size_t numBytes)
NetworkMessageAllocateNewMessage ()
 Allocates a new NetworkMessage struct. [both worker and main thread].
void DetectConnectionTimeOut ()
 Checks if the connection has been silent too long and has now timed out.
void ComputeStats ()
 Refreshes RTT and other connection related statistics.
void AddOutboundStats (unsigned long numBytes, unsigned long numPackets, unsigned long numMessages)
 Adds a new entry for outbound data statistics.
void AddInboundStats (unsigned long numBytes, unsigned long numPackets, unsigned long numMessages)
 Adds a new entry for inbound data statistics.
void AcceptOutboundMessages ()
 Pulls in all new messages from the main thread to the worker thread side and admits them to the send priority queue.
virtual void PerformDisconnection ()=0
 Starts the socket-specific disconnection procedure.
void operator= (const MessageConnection &)
 Noncopyable, N/I.
 MessageConnection (const MessageConnection &)
 Noncopyable, N/I.
void ClearOutboundMessageWithContentID (NetworkMessage *msg)
bool CheckAndSaveContentIDStamp (u32 messageID, u32 contentID, packet_id_t packetID)
 Checks whether the given (messageID, contentID)-pair is already out-of-date and obsoleted by a newer packet and should not be processed.
void SplitAndQueueMessage (NetworkMessage *message, bool internalQueue, size_t maxFragmentSize)
 MessageConnection (Network *owner, NetworkServer *ownerServer, Socket *socket, ConnectionState startingState)
 Private ctor - MessageConnections are instantiated by Network and NetworkServer classes.

Protected Attributes

Networkowner
 The Network object inside which this MessageConnection lives.
NetworkServerownerServer
 If this MessageConnection represents a client connection on the server side, this gives the owner.
NetworkWorkerThread * workerThread
 Stores the thread that manages the background processing of this connection.
WaitFreeQueue< NetworkMessage * > outboundAcceptQueue
 A queue populated by the main thread to give out messages to the MessageConnection work thread to process.
WaitFreeQueue< NetworkMessage * > inboundMessageQueue
 A queue populated by the networking thread to hold all the incoming messages until the application can process them.
WaitFreeQueue< NetworkMessage * > outboundQueue
 A priority queue that maintains in order all the messages that are going out the pipe.
Lockable< FragmentedSendManager > fragmentedSends
 Tracks all the message sends that are fragmented.
FragmentedReceiveManager fragmentedReceives
 Tracks all the receives of fragmented messages and helps reconstruct the original messages from fragments.
LockFreePoolAllocator
< NetworkMessage
messagePool
 Allocations of NetworkMessage structures go through a pool to avoid dynamic new/delete calls when sending messages.
PolledTimer pingTimer
 Tracks when it is time to send the next PingRequest to the peer.
PolledTimer statsRefreshTimer
 Tracks when it is time to update the statistics structure.
IMessageHandlerinboundMessageHandler
 The object that receives notifications of all received data.
Socketsocket
 The underlying socket on top of which this connection operates.
ConnectionState connectionState
 Specifies the current connection state.
bool bOutboundSendsPaused
 If true, all sends to the socket are on hold, until ResumeOutboundSends() is called.
Event eventMsgsOutAvailable
 Posted when the application has pushed us some messages to handle.
float rtt
 The currently estimated round-trip time, in milliseconds. [main and worker thread].
tick_t lastHeardTime
 The tick since last successful receive from the socket. [main and worker thread].
float packetsInPerSec
 The average number of datagrams we are receiving/second. [main and worker thread].
float packetsOutPerSec
 The average number of datagrams we are sending/second. [main and worker thread].
float msgsInPerSec
 The average number of kNet messages we are receiving/second. [main and worker thread].
float msgsOutPerSec
 The average number of kNet messages we are sending/second. [main and worker thread].
float bytesInPerSec
 The average number of bytes we are receiving/second. This includes kNet headers. [main and worker thread].
float bytesOutPerSec
 The average number of bytes we are sending/second. This includes kNet headers. [main and worker thread].
unsigned long outboundMessageNumberCounter
 A running number attached to each outbound message (not present in network stream) to break ties when deducing which message should come before which.
unsigned long outboundReliableMessageNumberCounter
 A running number that is assigned to each outbound reliable message.
ContentIDReceiveTrack inboundContentIDStamps
 Each (messageID, contentID) pair has a packetID "stamp" associated to them to track and decimate out-of-order received obsoleted messages.

Detailed Description

Represents a single established network connection.

MessageConnection maintains its own worker thread that manages connection control, the scheduling and prioritization of outbound messages, and receiving inbound messages.


Member Enumeration Documentation

Specifies the return value for the functions that send out network packets.

Enumerator:
PacketSendOK 

The operating system signalled the packet was successfully sent.

PacketSendSocketClosed 

The packet could not be sent, since the socket was closed.

PacketSendSocketFull 

The packet could not be sent, since the OS outbound buffer was full.

PacketSendNoMessages 

A packet could not be sent, since there was nothing to send.

PacketSendThrottled 

The packet could not be sent right now, since a throttle timer is in effect.

Specifies the result of a Socket read activity.

Enumerator:
SocketReadOK 

All data was read from the socket and it is empty for now.

SocketReadError 

An error occurred - probably the connection is dead.

SocketReadThrottled 

There was so much data to read that we need to pause and make room for sends as well.


Member Function Documentation

bool kNet::MessageConnection::IsPending (  )  const

Returns true if the connection is in the ConnectionPending state and waiting for the other end to resolve/establish the connection.

When this function returns false, the connection may be half-open, bidirectionally open, timed out on ConnectionPending, or closed.

References GetConnectionState(), and socket.

Referenced by WaitToEstablishConnection().

void kNet::MessageConnection::RunModalClient (  ) 

Runs a modal processing loop and produces events for all inbound received data.

Returns when the connection is closed. This is an example function mostly useful only for very simple demo applications. In most cases, you do not want to call this.

Todo:
WSACreateEvent/WSAWaitForMultipleEvents for improved responsiveness and performance.

References kNet::ConnectionClosed, GetConnectionState(), Process(), and kNet::Clock::Sleep().

bool kNet::MessageConnection::WaitToEstablishConnection ( int  maxMSecsToWait = 500  ) 

Blocks for the given amount of time until the connection has transitioned away from ConnectionPending state.

Parameters:
maxMSecstoWait A positive value that indicates the maximum time to wait until returning.
Returns:
If the connection was successfully opened, this function returns true. Otherwise returns false, and either timeout was encountered and the other end has not acknowledged the connection, or the connection is in ConnectionClosed state.

Todo:
Instead of waiting multiple 1msec slices, should wait for proper event.

References Connected(), kNet::ConnectionPending, kNet::ConnectionStateToString(), GetConnectionState(), IsPending(), LOG, and kNet::Clock::Sleep().

void kNet::MessageConnection::Disconnect ( int  maxMSecsToWait = 500  ) 

Starts a benign disconnect procedure.

Transitions ConnectionState to ConnectionDisconnecting. This function will block until the given period expires or the other end acknowledges and also closes down the connection. Currently no guarantee is given for whether previous reliable messages will safely reach the destination. To ensure this, do a manual wait to flush the outbound message queue before disconnecting.

Parameters:
maxMSecsToWait A positive number that indicates the maximum time to wait for a disconnect acknowledgement message until returning. If 0 is passed, the function will send the Disconnect message and return immediately. When this function returns, the connection may either be in ConnectionClosing or ConnectionClosed state, depending on whether the other end has already acknowledged the disconnection.
Note:
You may not call this function in middle of StartNewMessage() - EndAndQueueMessage() function calls.

Todo:
Instead of waiting multiple 1msec slices, should wait for proper event.

References Close(), kNet::ConnectionClosed, kNet::ConnectionDisconnecting, connectionState, kNet::ConnectionStateToString(), GetConnectionState(), kNet::Socket::IsReadOpen(), kNet::Socket::IsWriteOpen(), LOG, PerformDisconnection(), kNet::Clock::Sleep(), and socket.

Referenced by Close().

void kNet::MessageConnection::Close ( int  maxMSecsToWait = 500  ) 

Starts a forceful disconnect procedure.

Parameters:
maxMSecsToWait If a positive number, Disconnect message will be sent to the peer and if no response is received in the given time period, the connection is forcefully closed. If 0, no Disconnect message will be sent at all, but the connection is torn down and the function returns immediately. The other end will remain hanging and will timeout. When this function returns, the connection is in ConnectionClosed state.
Note:
You may not call this function in middle of StartNewMessage() - EndAndQueueMessage() function calls.

References kNet::Socket::Close(), connectionState, kNet::ConnectionStateToString(), Disconnect(), fragmentedReceives, fragmentedSends, inboundMessageQueue, kNet::Socket::IsReadOpen(), kNet::Socket::IsWriteOpen(), LOG, outboundAcceptQueue, outboundQueue, owner, ownerServer, kNet::WaitFreeQueue< T >::Size(), socket, ToString(), and kNet::Lockable< T >::UnsafeGetValue().

Referenced by Disconnect(), Process(), ReceiveMessage(), and WaitForMessage().

NetworkMessage * kNet::MessageConnection::StartNewMessage ( unsigned long  id,
size_t  numBytes = 0 
)

Start building a new message with the given ID.

Parameters:
id The ID for the message you will be sending.
numBytes The number of bytes the body of this message will be. This function will pre-allocate the NetworkMessage::data field to hold at least that many bytes (Capacity() can also return a larger value). This number only needs to be an estimate, since you can later on call NetworkMessage::Reserve() to reallocate the message memory. If you pass in the default value 0, no pre-allocation will be performed.
Returns:
The NetworkMessage object that represents the new message to be built. This message is dynamically allocated from an internal pool of NetworkMessage blocks. For each NetworkMessage pointer obtained, call EndAndQueueMessage when you have finished building the message to commit the network send and to release the memory. Alternatively, if after calling StartNewMessage, you decide to abort the network send, free up the NetworkMessage by calling this->FreeMessage().

References AllocateNewMessage(), kNet::NetworkMessage::contentID, kNet::NetworkMessage::id, LOG, kNet::NetworkMessage::obsolete, kNet::NetworkMessage::priority, kNet::NetworkMessage::reliable, and kNet::NetworkMessage::Resize().

Referenced by kNet::NetworkServer::BroadcastMessage(), Send(), kNet::NetworkServer::SendMessage(), SendMessage(), SendStruct(), and SplitAndQueueMessage().

void kNet::MessageConnection::EndAndQueueMessage ( NetworkMessage msg,
size_t  numBytes = (size_t)(-1),
bool  internalQueue = false 
)

Finishes building the message and submits it to the outbound send queue.

Parameters:
msg The message to send. After calling this function, this pointer should be considered freed and may not be dereferenced or passed to any other member function of this MessageConnection. Only pass in here NetworkMessage pointers obtained by a call to StartNewMessage() of the same MessageConnection instance.
numBytes Specify here the number of actual bytes you filled in into the msg.data field. A size of 0 is valid, and can be used in cases the message ID itself is the whole message. Passing in the default value of this parameter will use the size value that was specified in the call to StartNewMessage().
internalQueue If true, specifies that this message was submitted from the network worker thread and not the application thread. Pass in the value 'false' here in the client application, or there is a chance of a race condition.

Todo:
We can optimize here by doing the splitting at datagram creation time to create optimally sized datagrams, but it is quite more complicated, so left for later.
Todo:
Check this is ok.
Todo:
Convert to atomic increment, or this is a race condition.
Todo:
Convert to atomic increment, or this is a race condition.
Todo:
Is it possible to check beforehand if this criteria is avoided, or if we are doomed?

References bOutboundSendsPaused, kNet::ConnectionClosed, kNet::ConnectionStateToString(), eventMsgsOutAvailable, FreeMessage(), GetConnectionState(), kNet::NetworkMessage::id, kNet::WaitFreeQueue< T >::Insert(), kNet::WaitFreeQueue< T >::InsertWithResize(), IsWriteOpen(), kNet::Socket::IsWriteOpen(), LOG, kNet::Socket::MaxSendSize(), kNet::NetworkMessage::obsolete, outboundAcceptQueue, outboundMessageNumberCounter, outboundQueue, outboundReliableMessageNumberCounter, kNet::NetworkMessage::reliable, kNet::Event::Set(), socket, and SplitAndQueueMessage().

Referenced by kNet::NetworkServer::BroadcastMessage(), Send(), kNet::NetworkServer::SendMessage(), SendMessage(), and SendStruct().

void kNet::MessageConnection::SendMessage ( unsigned long  id,
bool  reliable,
bool  inOrder,
unsigned long  priority,
unsigned long  contentID,
const char *  data,
size_t  numBytes 
)

This is a conveniency function to access the above StartNewMessage/EndAndQueueMessage pair.

The performance of this function call is not as good, since a memcpy of the message will need to be made. For performance-critical messages, it is better to craft the message directly into the buffer area provided by StartNewMessage.

References kNet::NetworkMessage::contentID, kNet::NetworkMessage::data, EndAndQueueMessage(), kNet::NetworkMessage::inOrder, LOG, kNet::NetworkMessage::priority, kNet::NetworkMessage::reliable, and StartNewMessage().

void kNet::MessageConnection::PauseOutboundSends (  ) 

Stops all outbound sends until ResumeOutboundSends is called.

Use if you need to guarantee that some messages be sent in the same datagram. Do not stop outbound sends for long periods, or the other end may time out the connection.

References bOutboundSendsPaused, eventMsgsOutAvailable, and kNet::Event::Reset().

void kNet::MessageConnection::SetMaximumDataSendRate ( int  numBytesPerSec,
int  numDatagramsPerSec 
)

Sets an upper limit to the data send rate for this connection.

The default is not to have an upper limit at all.

Parameters:
numBytesPerSec The upper limit for the number of bytes to send per second. This limit includes the message header bytes as well and not just the payload. Set to 0 to force no limit.
numDatagramsPerSec The maximum number of datagrams (UDP packets) to send per second. Set to 0 to force no limit. If the connection is operating on top of TCP, this field has no effect.
Todo:
Implement.
void kNet::MessageConnection::Process ( int  maxMessagesToProcess = 100  ) 

Fetches all newly received messages waiting in the inbound queue, and passes each of these to the message handler registered using RegisterInboundMessageHandler.

Called from the main thread to fetch & handle all new inbound messages.

Call this function periodically to receive new data from the network if you are using the Observer pattern. Alternatively, use the immediate-mode ReceiveMessage function to receive messages directly one at a time.

Parameters:
maxMessageToProcess If the inbound queue contains more than this amount of new messages, the processing loop will return to give processing time to other parts of the application. If 0 is passed, messages are processed until the queue is empty.
Note:
It is important to have a non-zero limit in maxMessagesToProcess (unless you're sure what you are doing), since otherwise an attacker might affect the performance of the application main loop by sending messages so fast that the queue never has time to exhaust, thus giving an infinite loop in practice.

Todo:
This will block, since it is called with the default time period.

References Close(), kNet::Socket::Connected(), kNet::ConnectionClosed, connectionState, kNet::NetworkMessage::data, FreeMessage(), kNet::WaitFreeQueue< T >::Front(), kNet::IMessageHandler::HandleMessage(), kNet::NetworkMessage::id, inboundMessageHandler, inboundMessageQueue, LOG, kNet::WaitFreeQueue< T >::PopFront(), kNet::WaitFreeQueue< T >::Size(), socket, and ToString().

Referenced by RunModalClient().

void kNet::MessageConnection::WaitForMessage ( int  maxMSecsToWait  ) 

Waits for at most the given amount of time until a new message is received for processing.

Parameters:
maxMSecsToWait If 0, the call will wait indefinitely until a message is received or the connection transitions to closing state. If a positive value is passed, at most that many milliseconds is waited for a new message to be received.

Todo:
Log out warning if this takes AGES. Or rather, perhaps remove support for this altogether to avoid deadlocks.
Todo:
Instead of waiting multiple 1msec slices, should wait for proper event.
Todo:
Instead of waiting multiple 1msec slices, should wait for proper event.

References Close(), kNet::ConnectionClosed, kNet::ConnectionOK, connectionState, kNet::ConnectionStateToString(), GetConnectionState(), inboundMessageQueue, LOG, kNet::WaitFreeQueue< T >::Size(), kNet::Clock::Sleep(), and socket.

Referenced by ReceiveMessage().

NetworkMessage * kNet::MessageConnection::ReceiveMessage ( int  maxMSecsToWait = -1  ) 

Returns the next message in the inbound queue.

This is an alternative API to RegisterInboundMessageHandler/Process.

Note:
When using this function to receive messages, remember to call FreeMessage for each NetworkMessage returned, or you will have a major size memory leak, fast.
Parameters:
maxMSecsToWait If a negative number, the call will not wait at all if there are no new messages to process, but returns 0 immediately. If 0, the call will wait indefinitely until a message is received or the connection transitions to closing state. If a positive value is passed, at most that many milliseconds is waited for a new message to be received.
Returns:
A newly allocated object to the received message, or 0 if the queue was empty and no messages were received during the wait period, or if the connection transitioned to closing state. When you are finished reading the message, call FreeMessage for the returned pointer.

References Close(), kNet::ConnectionClosed, connectionState, kNet::WaitFreeQueue< T >::Front(), inboundMessageQueue, kNet::WaitFreeQueue< T >::PopFront(), kNet::WaitFreeQueue< T >::Size(), socket, and WaitForMessage().

void kNet::MessageConnection::FreeMessage ( NetworkMessage msg  ) 

Frees up a NetworkMessage struct when it is no longer needed.

You need to call this for each message that you received from a call to ReceiveMessage.

References LOG, and messagePool.

Referenced by EndAndQueueMessage(), HandleInboundMessage(), Process(), and SplitAndQueueMessage().

virtual SocketReadResult kNet::MessageConnection::ReadSocket ( size_t &  bytesRead  )  [protected, pure virtual]

Reads all the new bytes available in the socket.

This data will be read into the connection's internal data queue, where it will be parsed to messages.

Parameters:
bytesRead [out] This field will get the number of bytes successfully read.
Returns:
The return code of the operation.
void kNet::MessageConnection::HandleInboundMessage ( packet_id_t  packetID,
const char *  data,
size_t  numBytes 
) [protected]
void kNet::MessageConnection::ClearOutboundMessageWithContentID ( NetworkMessage msg  )  [protected]

Bug:
Possible race condition here. Accessed by both main and worker thread through a call from FreeMessage.

References kNet::NetworkMessage::contentID, and kNet::NetworkMessage::id.

bool kNet::MessageConnection::CheckAndSaveContentIDStamp ( u32  messageID,
u32  contentID,
packet_id_t  packetID 
) [protected]

Checks whether the given (messageID, contentID)-pair is already out-of-date and obsoleted by a newer packet and should not be processed.

Returns:
True if the packet should be processed (there was no superceding record), and false if the packet is old and should be discarded.

References inboundContentIDStamps, kNet::PacketIDIsNewerThan(), and kNet::Clock::Tick().

void kNet::MessageConnection::SplitAndQueueMessage ( NetworkMessage message,
bool  internalQueue,
size_t  maxFragmentSize 
) [protected]

Todo:
Would like to do this: FragmentedSendManager::FragmentedTransfer *transfer; { Lock<FragmentedSendManager> sends = fragmentedSends.Acquire(); transfer = sends->AllocateNewFragmentedTransfer(); }
Todo:
Convert to atomic increment, or this is a race condition.
Todo:
Is it possible to check beforehand if this criteria is avoided, or if we are doomed?

References bOutboundSendsPaused, kNet::NetworkMessage::contentID, kNet::NetworkMessage::data, eventMsgsOutAvailable, fragmentedSends, FreeMessage(), kNet::NetworkMessage::id, kNet::NetworkMessage::inOrder, kNet::WaitFreeQueue< T >::Insert(), kNet::WaitFreeQueue< T >::InsertWithResize(), LOG, kNet::NetworkMessage::obsolete, outboundAcceptQueue, outboundMessageNumberCounter, outboundQueue, kNet::NetworkMessage::priority, kNet::NetworkMessage::reliable, kNet::Event::Set(), and StartNewMessage().

Referenced by EndAndQueueMessage().


Member Data Documentation

Stores all the statistics about the current connection.

This data is periodically recomputed by the network worker thread and shared to the client through a lock.

Referenced by AddInboundStats(), AddOutboundStats(), and ComputeStats().

NetworkWorkerThread* kNet::MessageConnection::workerThread [protected]

Stores the thread that manages the background processing of this connection.

The same thread can manage multiple connections and servers, and not just this one.

Referenced by SetWorkerThread().

A priority queue that maintains in order all the messages that are going out the pipe.

Todo:
Make the choice of which of the following structures to use a runtime option.

Referenced by AcceptOutboundMessages(), Close(), EndAndQueueMessage(), NumOutboundMessagesPending(), and SplitAndQueueMessage().

Allocations of NetworkMessage structures go through a pool to avoid dynamic new/delete calls when sending messages.

This structure is shared between the main and worker thread through a lockfree construct.

Referenced by AllocateNewMessage(), and FreeMessage().

A running number attached to each outbound message (not present in network stream) to break ties when deducing which message should come before which.

Referenced by EndAndQueueMessage(), and SplitAndQueueMessage().

A running number that is assigned to each outbound reliable message.

This is used to enforce proper ordering of ordered messages.

Referenced by EndAndQueueMessage().

ContentIDReceiveTrack kNet::MessageConnection::inboundContentIDStamps [protected]

Each (messageID, contentID) pair has a packetID "stamp" associated to them to track and decimate out-of-order received obsoleted messages.

Referenced by CheckAndSaveContentIDStamp().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines