Cogs.Foundation
Loading...
Searching...
No Matches
Classes | Typedefs | Enumerations | Functions | Variables
Cogs::Network Namespace Reference

Classes

class  Addr
 
class  AddrIn
 
class  AddrIn6
 
class  ConnectionBase
 
class  ConnectionHub
 A ConnectionHub combines a TCP connection with a MessageHub to enable the forwarding and receiving of messages over a network connection. More...
 
class  ConnectionTCP
 
class  ConnectionUDP
 
class  Message
 
class  MessageHub
 A MessageHub connects to other hubs to form a simple peer-to-peer application-internal networking system for sending and receiving messages. More...
 
struct  NetworkAdapter
 
class  SendOnlyMessageHub
 A MessageHub that only supports sending messages. More...
 
class  Sockaddr
 
class  SockaddrIn
 
class  SockaddrIn6
 

Typedefs

typedef sa_family_t Family
 
typedef int Socket
 
typedef int SocketType
 
typedef int IPProto
 

Enumerations

enum  AdapterFlags : uint32_t { None = 0x00 , IncludeAny = 0x01 , IncludeLocalhost = 0x02 }
 

Functions

void UpdateAdapters (AdapterFlags adapter_flags)
 
void PrintAdapters ()
 
NetworkAdapter GetAdapter (size_t i)
 
size_t GetAdapterCount ()
 
int FindAdapter (const AddrIn &address)
 
MessageHub::HubListallHubs ()
 Retrieves the singleton instance of the global message hub list.
 
MutexallHubsMutex ()
 Retrieves the singleton instance of the mutex that protects the global message hub list.
 
MessageHubfind (uint32_t hubid)
 Searches for and returns the hub with the specified ID.
 
void ThreadFn ()
 Network thread function.
 
COGSFOUNDATION_API void addConnection (ConnectionBase *connection)
 Adds the specified connection to the list of managed connections.
 
COGSFOUNDATION_API void removeConnection (ConnectionBase *connection)
 Flags the specified connection for removal from the list of managed connections.
 
COGSFOUNDATION_API void closedown ()
 Flags the network thread to terminate, and waits until it has done so.
 

Variables

constexpr uint32_t cApplicationHubID = 0x7FFF0000
 
constexpr uint32_t cFirstWindowHubID = 0x7FFF1000
 
ThreadgThread = nullptr
 
bool gExit = false
 
std::mutex gMutex
 
std::vector< ConnectionBase * > gNewConnections
 
std::vector< ConnectionBase * > gConnections
 
std::condition_variable gAddCV
 
std::condition_variable gRemoveCV
 

Typedef Documentation

◆ Family

typedef sa_family_t Cogs::Network::Family

◆ IPProto

◆ Socket

typedef int Cogs::Network::Socket

◆ SocketType

Enumeration Type Documentation

◆ AdapterFlags

enum Cogs::Network::AdapterFlags : uint32_t
Enumerator
None 
IncludeAny 
IncludeLocalhost 

Function Documentation

◆ addConnection()

void Cogs::Network::addConnection ( ConnectionBase connection)

Adds the specified connection to the list of managed connections.

Managed connections will be processed for outgoing and incoming data until they are closed, or removed.

References gAddCV, gConnections, gMutex, gNewConnections, gThread, and ThreadFn().

Referenced by Cogs::Network::ConnectionBase::bind(), Cogs::Network::ConnectionUDP::bind(), Cogs::Network::ConnectionTCP::ConnectionTCP(), Cogs::Network::ConnectionTCP::listen(), and Cogs::Network::ConnectionTCP::reconnect().

◆ allHubs()

MessageHub::HubList & Cogs::Network::allHubs ( )

Retrieves the singleton instance of the global message hub list.

This will be used when broadcasting global messages through the broadcastMessage function. *============================================================================================

Referenced by Cogs::Network::MessageHub::broadcastMessage(), find(), Cogs::Network::MessageHub::MessageHub(), and Cogs::Network::MessageHub::~MessageHub().

◆ allHubsMutex()

Mutex & Cogs::Network::allHubsMutex ( )

Retrieves the singleton instance of the mutex that protects the global message hub list.

*============================================================================================

Referenced by Cogs::Network::MessageHub::broadcastMessage(), find(), Cogs::Network::MessageHub::MessageHub(), and Cogs::Network::MessageHub::~MessageHub().

◆ closedown()

void Cogs::Network::closedown ( )

Flags the network thread to terminate, and waits until it has done so.

References gAddCV, gExit, and gThread.

◆ find()

MessageHub * Cogs::Network::find ( uint32_t  hubid)

Searches for and returns the hub with the specified ID.

Nullptr will be returned if no hub with a matching ID can be found. *============================================================================================

References allHubs(), and allHubsMutex().

Referenced by Cogs::Network::MessageHub::addListener(), Cogs::Network::MessageHub::listenTo(), and Cogs::Network::MessageHub::removeListener().

◆ FindAdapter()

COGSFOUNDATION_API int Cogs::Network::FindAdapter ( const AddrIn address)

◆ GetAdapter()

COGSFOUNDATION_API NetworkAdapter Cogs::Network::GetAdapter ( size_t  i)

◆ GetAdapterCount()

COGSFOUNDATION_API size_t Cogs::Network::GetAdapterCount ( )

◆ PrintAdapters()

COGSFOUNDATION_API void Cogs::Network::PrintAdapters ( )

References LOG_INFO, and Cogs::logger.

◆ removeConnection()

void Cogs::Network::removeConnection ( ConnectionBase connection)

Flags the specified connection for removal from the list of managed connections.

This function will stall until the connection has been removed by the network thread.

Calling this function from the network thread will flag the connection for removal, but it won't be removed right away. (And this function will return immediately.)

References gConnections, gMutex, gNewConnections, gRemoveCV, gThread, and Cogs::Network::ConnectionBase::remove().

Referenced by Cogs::Network::ConnectionTCP::~ConnectionTCP(), and Cogs::Network::ConnectionUDP::~ConnectionUDP().

◆ ThreadFn()

void Cogs::Network::ThreadFn ( )

◆ UpdateAdapters()

COGSFOUNDATION_API void Cogs::Network::UpdateAdapters ( AdapterFlags  adapter_flags)

Variable Documentation

◆ cApplicationHubID

constexpr uint32_t Cogs::Network::cApplicationHubID = 0x7FFF0000
constexpr

◆ cFirstWindowHubID

constexpr uint32_t Cogs::Network::cFirstWindowHubID = 0x7FFF1000
constexpr

◆ gAddCV

std::condition_variable Cogs::Network::gAddCV

Referenced by addConnection(), closedown(), and ThreadFn().

◆ gConnections

std::vector< ConnectionBase* > Cogs::Network::gConnections

◆ gExit

bool Cogs::Network::gExit = false

Referenced by closedown(), and ThreadFn().

◆ gMutex

std::mutex Cogs::Network::gMutex

◆ gNewConnections

std::vector< ConnectionBase* > Cogs::Network::gNewConnections

◆ gRemoveCV

std::condition_variable Cogs::Network::gRemoveCV

Referenced by removeConnection(), and ThreadFn().

◆ gThread

Thread* Cogs::Network::gThread = nullptr