Namespaces | Classes | Typedefs | Enumerations | Functions

kNet Namespace Reference

Namespaces

namespace  sort
 

A range of comparison sort algorithms.


Classes

class  ArrayIterator
 Sequential iterator for Array. More...
class  Array
 std::vector -equivalent. More...
struct  SerializedDataTypeTraits
 A trait class used to match basic data types to their associated enum values. More...
class  LSBT
 Template-evaluated enum that gives a mask with the Bits LSB bits set. More...
class  BitMaskT
 A template-computed enum to create a mask of given amount of bits at given position of a u32 variable. More...
class  Clock
 High-resolution timing and system time. More...
class  DataDeserializer
 DataDeserializer is an utility class that walks through and deserializes data in a stream of raw bytes. More...
class  DataSerializer
 DataSerializer is a helper class that can be used to serialize data types to a stream of raw bits suitable for disk storage or network transfer. More...
struct  EndPoint
 EndPoint represents a (ip, port) source or destination of a socket. More...
class  Event
 Event is an inter-thread synchronization primitive that can be in one of two states: Set or Cleared. More...
class  EventArray
 EventArray stores a list of events and allows the application to simultaneously wait for any of them to become set. More...
class  IMessageHandler
 IMessageHandler is a callback object used by the MessageConnection to invoke the main application whenever a message has been received. More...
class  INetworkServerListener
 An interface implementable by the owner of a network server to receive notifications about connection-related events. More...
class  Lockable
 Stores an object of type T behind a mutex-locked shield. More...
class  LockFreePoolAllocator
 T must implement PoolAllocatable. More...
class  EmptyLookupNotify
 Used as a no-functionality structure to pass as the default template parameter to MaxHeap when no index update notifications are needed. More...
class  MaxHeap
 Implements a max heap data structure, see http://en.wikipedia.org/wiki/Binary_heap. More...
struct  ConnectionStatistics
 Stores information about an established MessageConnection. More...
class  NetworkMessagePriorityCmp
 Comparison object that sorts the two messages by their priority (higher priority/smaller number first). More...
class  MessageConnection
 Represents a single established network connection. More...
struct  SerializedElementDesc
 Represents a single element of data in the stream. More...
struct  SerializedMessageDesc
 Describes a whole serialized message. More...
class  SerializedMessageList
 Stores a whole list of message templates. More...
class  Network
 Provides the application an interface for both client and server networking. More...
class  NetworkMessage
 NetworkMessage stores the serialized byte data of a single outbound network message, along with fields that specify how itreated by the network connection. More...
class  NetworkServer
 Manages all low-level networking required in maintaining a network server and keeps track of all currently established connections. More...
class  RingBuffer
 Implements a byte-based ring buffer (of sorts) of raw bytes. More...
class  SerializationStructCompiler
 Generates .h files out of XML description files for serializable structs and network messages. More...
class  RefCountable
 Objects that require reference count tracking derive publicly from this. More...
class  SharedPtr
 SharedPtr is an intrusive refcount-tracked single-object lifetime-manager. More...
class  Socket
 Represents a low-level network socket. More...
class  StdCAlloc
 Allocates raw memory using the std C malloc and free. More...
class  VLEType2
 VLEPacker performs variable-length encoding of unsigned integer values by omitting leading zeroes from big numbers. More...
class  VLEType3
 VLEPacker performs variable-length encoding of unsigned integer values by omitting leading zeroes from big numbers. More...
class  WaitFreeQueue
 A wait-free queue for communication unidirectionally between two threads. More...

Typedefs

typedef bool bit
 A single 0|1 value that is serialized as just one bit, *without padding*.
typedef unsigned long long tick_t
 A tick is the basic unit of the high-resolution timer.
typedef unsigned int LogChannel
 A bitfield type that describes single or multiple log channels (each bit represents a channel).
typedef unsigned long packet_id_t
 Contains 22 actual bits of data.

Enumerations

enum  { AFAllocLow = 0x1, AFAllocHigh = 0x2 }
enum  BasicSerializedDataType {
  SerialInvalid = 0, SerialBit, SerialU8, SerialS8,
  SerialU16, SerialS16, SerialU32, SerialS32,
  SerialU64, SerialS64, SerialFloat, SerialDouble,
  SerialString, SerialStruct, SerialDynamicCount, NumSerialTypes
}
 

Defines the basic data types that are the building blocks of every other serializable data type.

More...
enum  EventWaitType { EventWaitDummy, EventWaitSignal, EventWaitRead, EventWaitWrite }
enum  ConnectionState {
  ConnectionPending, ConnectionOK, ConnectionDisconnecting, ConnectionPeerClosed,
  ConnectionClosed
}
 

Represents the current state of the connection.

More...
enum  SocketTransportLayer { InvalidTransportLayer = 0 }
 

Identifiers for the possible bottom-level tranport layers.

More...
enum  SocketType { InvalidSocketType = 0, ServerListenSocket, ServerClientSocket, ClientSocket }

Functions

std::string ConnectionStateToString (ConnectionState state)
 Returns a textual representation of a ConnectionState.
BasicSerializedDataType StringToSerialType (const char *type)
 Tries to parse a BasicSerializedDataType out of a string, or returns SerialInvalid if no match.
const char * SerialTypeToString (BasicSerializedDataType type)
 Converts a give BasicSerializedDataType to a readable string representation.
size_t SerialTypeSize (BasicSerializedDataType type)
 Returns the number of bytes the passed BasicSerializedDataType requires for serialization.
std::string FormatBytes (size_t numBytes)
 Outputs the given number of bytes formatted to KB or MB suffix for readability.
void PrintLocalIP ()
void TimeOutputDebugStringVariadic (LogChannel logChannel, const char *filename, int lineNumber, const char *msg,...)
 Prints a variadic line to log.
void TimeOutputDebugString (LogChannel logChannel, const char *filename, int lineNumber, const char *msg)
 Prints a message to the log. Same as kNet::TimeOutputDebugStringVariadic, but does not use printf formatting.
void SetLogChannels (LogChannel logChannel)
 Sets the currently enabled log channels.
LogChannel GetLogChannels ()
 Returns the currently active log channels.
void SetLogFile (const char *filename)
 Sets the output for log messages.
void EnableMemoryLeakLoggingAtExit ()
 When called, sets the runtime to print out all memory leaks at program exit time.
Event CreateNewEvent (EventWaitType type)
 Creates and returns a new event.
bool IsPow2Aligned (uintptr_t pointer, u32 alignment)
 Is the given pointer aligned to the pow2-boundary specified by alignment?
uintptr_t AlignUpPow2 (uintptr_t pointer, u32 alignment)
uintptr_t AlignDownPow2 (uintptr_t pointer, u32 alignment)
template<typename Object , typename Allocator >
Object * New (Allocator *allocator, size_t alignment, const char *nameTag=0, AllocFlags flags=AFAllocLow)
 The global memory/object allocation function.
template<typename Object , typename Allocator >
Object * NewArray (size_t numObjects, Allocator *allocator, size_t alignment, const char *nameTag=0, AllocFlags flags=AFAllocLow)
 Allocates an array of objects.
template<typename Object , typename Allocator >
void Delete (Object *ptr, Allocator *allocator)
 Object deletion function.
template<typename Object , typename Allocator >
void DeleteArray (Object *ptr, Allocator *allocator)
 Array of objects deletion function.
u32 BinaryStringToValue (const char *str)
 Returns the u32 representation of the given string that consists only of characters '0' and '1'.
int CountBitsSet (u32 value)
 Returns the number of bits that are set (ones) in the given value.
u32 LSB (u32 bits)
u32 BitMask (u32 pos, u32 bits)
template<typename ResultType , typename InputType , int APos, int ABits, int RPos, int RBits, int GPos, int GBits, int BPos, int BBits>
ResultType PackBits (InputType a, InputType r, InputType g, InputType b)
template<typename ResultType , typename InputType >
ResultType PackBits (int APos, int ABits, int RPos, int RBits, int GPos, int GBits, int BPos, int BBits, InputType a, InputType r, InputType g, InputType b)
template<typename ResultType , typename InputType , int Pos, int Bits>
void ExtractBits (ResultType &out, const InputType &in)
 Extracts the given adjacent bits from a larger bitfield.
template<typename ResultType , typename InputType >
void ExtractBits (int pos, int bits, ResultType &out, const InputType &in)
 Extracts the given adjacent bits from a larger bitfield.
template<typename T >
size_t SumArray (const T &data, size_t numElems)
 Sums up the sizes of each element of an array.
bool PacketIDIsNewerThan (packet_id_t newID, packet_id_t oldID)
 Performs modular arithmetic comparison to see if newID refers to a PacketID newer than oldID.
packet_id_t AddPacketID (packet_id_t id, int increment)
 Computes the PacketID for the packet (id + increment).
packet_id_t SubPacketID (packet_id_t id, int sub)
 Computes the PacketID for the packet (id - sub).
template<typename T >
bool operator== (const SharedPtr< T > &a, const SharedPtr< T > &b)
 Equality comparison for two SharedPtr.

Detailed Description

Todo:
Omit this.
Todo:
Investigate the inclusion chain of these two files. Is this include necessary?

Enumeration Type Documentation

anonymous enum
Enumerator:
AFAllocLow 

Allocate from the low end of the memory space (if applicable for the given Allocator). Default.

AFAllocHigh 

Allocate from the high end of the memory space (if supported).

Defines the basic data types that are the building blocks of every other serializable data type.

Note:
See MessageListParser.cpp:44: It depends on the order of the items specified here.
Enumerator:
SerialInvalid 

Denotes an invalid value of type BasicSerializedDataType.

SerialBit 

Associated with the type 'bit'.

SerialU8 

Associated with the type 'u8'.

SerialS8 

Associated with the type 's8'.

SerialU16 

Associated with the type 'u16'.

SerialS16 

Associated with the type 's16'.

SerialU32 

Associated with the type 'u32'.

SerialS32 

Associated with the type 's32'.

SerialU64 

Associated with the type 'u64'.

SerialS64 

Associated with the type 's64'.

SerialFloat 

Associated with the type 'float'.

SerialDouble 

Associated with the type 'double'.

SerialString 

An ASCII string.

SerialStruct 

Not associated with a basic type, but defines that the given node contains an aggregate of multiple other types.

SerialDynamicCount 

Not a data type, but an identifier for the SerializedMessageIterator to return when a dynamic count of a block is the next field to fill.

NumSerialTypes 

The maximum number of different values for BasicSerializedDataType.

Enumerator:
EventWaitDummy 

The event to be waited on is a dummy event. Used to keep the index numbers straight, to avoid a O(n) pass through the whole event wait list.

EventWaitSignal 

The event to be waited on is not a socket-based event, but an application-triggered signal event.

EventWaitRead 

The event to be waited on is a socket read event.

EventWaitWrite 

The event to be waited on is a socket write event.

Represents the current state of the connection.

Enumerator:
ConnectionPending 

Waiting for the other end to send an acknowledgement packet to form the connection. No messages may yet be sent or received at this state.

ConnectionOK 

The connection is bidirectionally open, for both reading and writing. (readOpen=true, writeOpen=true).

ConnectionDisconnecting 

We are closing the connection down. Cannot send any more messages, but can still receive. (readOpen=true, writeOpen=false).

ConnectionPeerClosed 

The other end has closed the connection. No new messages will be received, but can still send messages. (readOpen=false, writeOpen=true).

ConnectionClosed 

The socket is no longer open. A MessageConnection object in this state cannot be reused to open a new connection, but a new connection object must be created.

Identifiers for the possible bottom-level tranport layers.

Enumerator:
InvalidTransportLayer 

A default invalid value for uninitialized sockets.

Enumerator:
InvalidSocketType 

A default invalid value for uninitialized sockets.

ServerListenSocket 

For TCP: a listen socket. For UDP: the single master socket handle that is used to send & receive all data.

ServerClientSocket 

For TCP: a client data socket. For UDP: a slave-mode Socket object that shares the underlying socket handle with the UDP master Socket.

ClientSocket 

A client-side socket.


Function Documentation

void kNet::PrintLocalIP (  ) 

Todo:
inet_ntoa is deprecated! doesn't handle IPv6!

References LOG.

void kNet::TimeOutputDebugStringVariadic ( LogChannel  logChannel,
const char *  filename,
int  lineNumber,
const char *  msg,
  ... 
)

Prints a variadic line to log.

Parameters:
logChannel The log channel to print to. This variable must have exactly one bit set, and is ANDed against the currently active channels that can be set with a call to kNet::SetLogChannels.
filename The C++ file from which the log message occurs, pass in __FILE__.
lineNumber Pass in __LINE__.
msg The printf-style message format specifier for the text to print.
void kNet::SetLogChannels ( LogChannel  logChannel  ) 

Sets the currently enabled log channels.

Pass in a bitwise OR of the log channels you want to enable. If you pass in 0, all logging is disabled. By default, only the channel LogChannelUser is enabled.

void kNet::SetLogFile ( const char *  filename  ) 

Sets the output for log messages.

By default all logging is output to std::cout. Setting a log file redirects all logging to that file. Calling this function with a null filename pointer restores logging to target std::cout.

void kNet::EnableMemoryLeakLoggingAtExit (  ) 

When called, sets the runtime to print out all memory leaks at program exit time.

Win32-only. On linux, this is a no-op.

uintptr_t kNet::AlignUpPow2 ( uintptr_t  pointer,
u32  alignment 
) [inline]
Returns:
The given pointer aligned up to the next pow2-boundary specified by alignment. (Alignment must be a pow2)

References IS_POW2.

uintptr_t kNet::AlignDownPow2 ( uintptr_t  pointer,
u32  alignment 
) [inline]
Returns:
The given pointer aligned down to the previous pow2-boundary specified by alignment. (Alignment must be a pow2)

References IS_POW2.

template<typename Object , typename Allocator >
Object* kNet::New ( Allocator *  allocator,
size_t  alignment,
const char *  nameTag = 0,
AllocFlags  flags = AFAllocLow 
) [inline]

The global memory/object allocation function.

Allocates sizeof(Object) bytes of memory using the allocator and uses placement new to construct an object of type Object to that memory area. (calls the ctor of Object).

Parameters:
allocator The allocator object to allocate data from. Null may be passed in if the Allocator type is a class-based allocator.
Returns:
A pointer to the allocated object or 0 if failed.
Todo:
Currently bad_alloc exceptions are not meant to be supported (although they can occur). Define this behavior more precisely?
template<typename Object , typename Allocator >
Object* kNet::NewArray ( size_t  numObjects,
Allocator *  allocator,
size_t  alignment,
const char *  nameTag = 0,
AllocFlags  flags = AFAllocLow 
) [inline]

Allocates an array of objects.

Calls default ctors for each.

Parameters:
allocator The allocator object to allocate data from. Null may be passed in if the Allocator type is a class-based allocator.
Todo:
The 4 bytes of size data are unnecessary for PODs!

Todo:
Proper alignment.

template<typename Object , typename Allocator >
void kNet::Delete ( Object *  ptr,
Allocator *  allocator 
) [inline]

Object deletion function.

Destroys the given object (calls dtor) and returns the used memory back to the allocator.

Parameters:
allocator The allocator object to allocate data from. Null may be passed in if the Allocator type is a class-based allocator.
template<typename Object , typename Allocator >
void kNet::DeleteArray ( Object *  ptr,
Allocator *  allocator 
) [inline]

Array of objects deletion function.

Destroys all objects (calls dtors for each) and returns the used memory back to the allocator.

Parameters:
allocator The allocator object to allocate data from. Null may be passed in if the Allocator type is a class-based allocator.

Referenced by kNet::Array< NetworkMessage * >::reserve().

u32 kNet::LSB ( u32  bits  )  [inline]
Returns:
A mask with the given amount of LSB bits set. This is the runtime-equivalent of LSBT. LSB(0)==0, LSB(1)==1, LSB(8)=11111111, etc. LSB(32) and above are undefined.

Referenced by kNet::DataSerializer::AppendBits(), and BitMask().

u32 kNet::BitMask ( u32  pos,
u32  bits 
) [inline]
Returns:
A mask with the given number of bits set at the given position of a u32 variable. This is the runtime-equivalent of BitMaskT. For example, BitMask(4,4)==11110000.

References LSB().

Referenced by ExtractBits(), and PackBits().

template<typename ResultType , typename InputType , int APos, int ABits, int RPos, int RBits, int GPos, int GBits, int BPos, int BBits>
ResultType kNet::PackBits ( InputType  a,
InputType  r,
InputType  g,
InputType  b 
)
Returns:
The given 4 bit fields packed into a single larger bitfield. Aggressively templatized version.
template<typename ResultType , typename InputType >
ResultType kNet::PackBits ( int  APos,
int  ABits,
int  RPos,
int  RBits,
int  GPos,
int  GBits,
int  BPos,
int  BBits,
InputType  a,
InputType  r,
InputType  g,
InputType  b 
)
Returns:
The given 4 bit fields packed into a single larger bitfield.

References BitMask().

template<typename ResultType , typename InputType , int Pos, int Bits>
void kNet::ExtractBits ( ResultType &  out,
const InputType &  in 
)

Extracts the given adjacent bits from a larger bitfield.

Aggressively templatized version. For example, ExtractBits<u8, u8, 4, 2> gets the bits 00110000 from a byte, shifts them right 4 places and returns the two bits.

template<typename ResultType , typename InputType >
void kNet::ExtractBits ( int  pos,
int  bits,
ResultType &  out,
const InputType &  in 
)

Extracts the given adjacent bits from a larger bitfield.

For example, ExtractBits<u8, u8>(3, 4) gets the bits 01111000 from a byte, shifts them right 3 places and returns the four bits.

References BitMask().

bool kNet::PacketIDIsNewerThan ( packet_id_t  newID,
packet_id_t  oldID 
) [inline]

Performs modular arithmetic comparison to see if newID refers to a PacketID newer than oldID.

Returns:
True if newID is newer than oldID, false otherwise.

Referenced by kNet::MessageConnection::CheckAndSaveContentIDStamp().

template<typename T >
bool kNet::operator== ( const SharedPtr< T > &  a,
const SharedPtr< T > &  b 
)

Equality comparison for two SharedPtr.

Note that the types must match.

Parameters:
a First operand
b Second operand
Returns:
true if the objects point to the same object, false otherwise.

References kNet::SharedPtr< T >::ptr().

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines