Skip to content

Class ConnectionManager

ClassList > ConnectionManager

More...

  • #include <connection_manager.h>

Public Functions

Type Name
ConnectionManager ()
void Log (const char * fmt, ...)
virtual int RecvFrom (char * buffer, int len, int flags, int * connection_id) = 0
virtual int ResetManager ()
virtual int SendTo (const char * buffer, int len, int flags, int connection_id) = 0
virtual std::string ToString (int connection_id)
virtual ~ConnectionManager ()

Protected Attributes

Type Name
std::map< int, std::shared_ptr< ConnectionInfo > > _connection_map
A map of connection IDs and smart pointers to their respective info objects.
int _id_to_issue
The current ID value to be issued to the next connection added.

Protected Functions

Type Name
int AddConnection (std::shared_ptr< ConnectionInfo > info)

Detailed Description

Abstract class to define a connection manager interface

This is a class whos purpose is to provide an abstraction from underlying network system calls. It must provide a non-blocking upd style send recv interface. When adding a connection it should return a unique int ID for the connection to be referred to by in future interactions with the manager.

Public Functions Documentation

function ConnectionManager

inline ConnectionManager::ConnectionManager () 

function Log

void ConnectionManager::Log (
    const char * fmt,
    ...
) 

function RecvFrom

virtual int ConnectionManager::RecvFrom (
    char * buffer,
    int len,
    int flags,
    int * connection_id
) = 0

RecvFrom is a recvfrom upd style interface

This function is expected to function similar to a standard upd socket style recvfrom. Return values are as follows: greater than 0 values indicate data length. 0 indicates a disconnect. -1 indicates no data or some other error.


function ResetManager

inline virtual int ConnectionManager::ResetManager () 

ResetManager is a reset function to clear the connection_map

This should be called if there is a need to clear all existing connections without creating a new connection manager.


function SendTo

virtual int ConnectionManager::SendTo (
    const char * buffer,
    int len,
    int flags,
    int connection_id
) = 0

SendTo is a sendto upd style interface

This function is expected to function similar to a standard upd socket style send.


function ToString

virtual std::string ConnectionManager::ToString (
    int connection_id
) 

ToString converts relevant information to a string

This function should convert relevant information from the connection info object identified by connection_id to a string. The default implementation should be valid for most use cases. Overload the ToString function in the derived ConnectionInfo definition.


function ~ConnectionManager

virtual ConnectionManager::~ConnectionManager () 

Protected Attributes Documentation

variable _connection_map

A map of connection IDs and smart pointers to their respective info objects.

std::map<int, std::shared_ptr<ConnectionInfo> > ConnectionManager::_connection_map;


variable _id_to_issue

The current ID value to be issued to the next connection added.

int ConnectionManager::_id_to_issue;


Protected Functions Documentation

function AddConnection

inline int ConnectionManager::AddConnection (
    std::shared_ptr< ConnectionInfo > info
) 

AddConnection adds a connection to the manager and returns the ID.

This function takes in a ConnectionInfo smartpointer to an object that implicitly must be a defined type that inheriteds from ConnectionInfo. Derived ConnectionManagers should define their own AddConnection functions with args that provide the relevant information for the specific connection desired. This function should then be called to add a derived ConnectionInfo object to the _connection_map and it will return the connection id. Having monotonically increasing IDs is fine for this use case. It is up to the user to correctly manage IDs to ensure they are only used with the ConnectionManager that issued them as the same IDs will likely be valid in multiple ConnectionManagers on the same process.



The documentation for this class was generated from the following file C:/Users/wistf/Unreal Projects/NightSkyEngine/Plugins/NightSkyEngine/Source/GGPOUE4/Public/include/connection_manager.h