Cogs.Foundation
|
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::HubList & | allHubs () |
Retrieves the singleton instance of the global message hub list. | |
Mutex & | allHubsMutex () |
Retrieves the singleton instance of the mutex that protects the global message hub list. | |
MessageHub * | find (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 |
Thread * | gThread = nullptr |
bool | gExit = false |
std::mutex | gMutex |
std::vector< ConnectionBase * > | gNewConnections |
std::vector< ConnectionBase * > | gConnections |
std::condition_variable | gAddCV |
std::condition_variable | gRemoveCV |
typedef sa_family_t Cogs::Network::Family |
typedef int Cogs::Network::IPProto |
typedef int Cogs::Network::Socket |
typedef int Cogs::Network::SocketType |
enum Cogs::Network::AdapterFlags : uint32_t |
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().
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().
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().
void Cogs::Network::closedown | ( | ) |
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().
COGSFOUNDATION_API int Cogs::Network::FindAdapter | ( | const AddrIn & | address | ) |
COGSFOUNDATION_API NetworkAdapter Cogs::Network::GetAdapter | ( | size_t | i | ) |
COGSFOUNDATION_API size_t Cogs::Network::GetAdapterCount | ( | ) |
COGSFOUNDATION_API void Cogs::Network::PrintAdapters | ( | ) |
References LOG_INFO, and Cogs::logger.
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().
void Cogs::Network::ThreadFn | ( | ) |
Network thread function.
This thread will process all added connections until it is told otherwise.
References Cogs::Network::ConnectionBase::disconnect(), gAddCV, gConnections, Cogs::Network::ConnectionBase::getReconnectTime(), Cogs::Network::ConnectionBase::getSocket(), gExit, gMutex, gNewConnections, gRemoveCV, Cogs::Network::ConnectionBase::isAutoConnectEnabled(), Cogs::Network::ConnectionBase::isConnected(), Cogs::Network::ConnectionBase::reconnect(), Cogs::Network::ConnectionBase::shouldDelete(), and Cogs::Network::ConnectionBase::shouldRemove().
Referenced by addConnection().
COGSFOUNDATION_API void Cogs::Network::UpdateAdapters | ( | AdapterFlags | adapter_flags | ) |
|
constexpr |
|
constexpr |
std::condition_variable Cogs::Network::gAddCV |
Referenced by addConnection(), closedown(), and ThreadFn().
std::vector< ConnectionBase* > Cogs::Network::gConnections |
Referenced by addConnection(), removeConnection(), and ThreadFn().
bool Cogs::Network::gExit = false |
Referenced by closedown(), and ThreadFn().
std::mutex Cogs::Network::gMutex |
Referenced by addConnection(), removeConnection(), and ThreadFn().
std::vector< ConnectionBase* > Cogs::Network::gNewConnections |
Referenced by addConnection(), removeConnection(), and ThreadFn().
std::condition_variable Cogs::Network::gRemoveCV |
Referenced by removeConnection(), and ThreadFn().
Thread* Cogs::Network::gThread = nullptr |
Referenced by addConnection(), closedown(), and removeConnection().