Cogs.Foundation
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
Cogs::Network::ConnectionBase Class Referenceabstract

#include <Connection.h>

Inheritance diagram for Cogs::Network::ConnectionBase:
Cogs::Network::ConnectionTCP Cogs::Network::ConnectionUDP Cogs::Network::ConnectionHub

Public Member Functions

 ConnectionBase ()
 
virtual ~ConnectionBase ()
 
Family family () const
 
virtual SocketType type () const =0
 
virtual IPProto proto () const =0
 
Socket getSocket () const
 
void remove ()
 
void removeAndDelete ()
 
const SockaddrIngetAddress () const
 
int64_t getReconnectTime () const
 
virtual bool isAutoConnectEnabled () const
 
virtual bool isConnected () const
 
bool shouldRemove () const
 
bool shouldDelete () const
 
void setNonblocking (bool val=true)
 Sets socket non-blocking mode to val.
 
void setDoNotProcess ()
 
virtual bool reconnect ()
 
virtual bool disconnect ()=0
 
bool bind (uint16_t port)
 
virtual bool bind (AddrIn ip, uint16_t port)
 Sets this connection up as a listener that will listen for and respond to incoming connection requests on the specified port.
 
bool send (const void *data, uint64_t byteCount, uint64_t &bytesSent)
 Attempts to send as much of the specified data as possible.
 
bool receive (void *buffer, uint64_t byteCount, uint64_t &bytesReceived)
 Attempts to read the specified number of bytes from the network socket this connection represents.
 
bool sendTo (const void *data, uint64_t byteCount, uint64_t &bytesSent, const SockaddrIn &addr)
 Attempts to send as much of the specified data as possible.
 
bool recvFrom (void *buffer, uint64_t byteCount, uint64_t &bytesReceived, SockaddrIn &addr)
 Attempts to read the specified number of bytes from the network socket this connection represents.
 
virtual bool processOutgoing ()
 
virtual bool processIncoming ()
 

Protected Member Functions

void create ()
 Internal wrapper for the socket() call.
 
void close ()
 Internal wrapper for closing the socket.
 

Protected Attributes

Cogs::Atomic< uint32_t > flags = 0
 
int64_t reconnectTime = 0
 
Socket socket = InvalidSocket
 
SockaddrIn sockAddr = {}
 

Static Protected Attributes

static constexpr uint32_t cRemove = 0x00000001
 
static constexpr uint32_t cDelete = 0x00000002
 
static constexpr uint32_t cDoNotProcess = 0x00000004
 

Constructor & Destructor Documentation

◆ ConnectionBase()

Cogs::Network::ConnectionBase::ConnectionBase ( )
inline

◆ ~ConnectionBase()

virtual Cogs::Network::ConnectionBase::~ConnectionBase ( )
inlinevirtual

Member Function Documentation

◆ bind() [1/2]

bool Cogs::Network::ConnectionBase::bind ( AddrIn  ip,
uint16_t  port 
)
virtual

Sets this connection up as a listener that will listen for and respond to incoming connection requests on the specified port.

Reimplemented in Cogs::Network::ConnectionUDP.

References Cogs::Network::addConnection(), check_net_error, InvalidSocket, LOG_ERROR, Cogs::logger, and Cogs::Network::AddrIn::string().

◆ bind() [2/2]

bool Cogs::Network::ConnectionBase::bind ( uint16_t  port)
inline

References bind().

Referenced by bind().

◆ close()

void Cogs::Network::ConnectionBase::close ( )
protected

Internal wrapper for closing the socket.

References InvalidSocket, LOG_INFO, and Cogs::logger.

◆ create()

void Cogs::Network::ConnectionBase::create ( )
protected

Internal wrapper for the socket() call.

References InvalidSocket, LOG_ERROR, and Cogs::logger.

◆ disconnect()

virtual bool Cogs::Network::ConnectionBase::disconnect ( )
pure virtual

◆ family()

Family Cogs::Network::ConnectionBase::family ( ) const
inline

◆ getAddress()

const SockaddrIn & Cogs::Network::ConnectionBase::getAddress ( ) const
inline

◆ getReconnectTime()

int64_t Cogs::Network::ConnectionBase::getReconnectTime ( ) const
inline

Referenced by Cogs::Network::ThreadFn().

◆ getSocket()

Socket Cogs::Network::ConnectionBase::getSocket ( ) const
inline

Referenced by Cogs::Network::ThreadFn().

◆ isAutoConnectEnabled()

virtual bool Cogs::Network::ConnectionBase::isAutoConnectEnabled ( ) const
inlinevirtual

Reimplemented in Cogs::Network::ConnectionTCP.

Referenced by Cogs::Network::ThreadFn().

◆ isConnected()

virtual bool Cogs::Network::ConnectionBase::isConnected ( ) const
inlinevirtual

Reimplemented in Cogs::Network::ConnectionTCP.

References InvalidSocket.

Referenced by Cogs::Network::ThreadFn().

◆ processIncoming()

virtual bool Cogs::Network::ConnectionBase::processIncoming ( )
inlinevirtual

◆ processOutgoing()

virtual bool Cogs::Network::ConnectionBase::processOutgoing ( )
inlinevirtual

Reimplemented in Cogs::Network::ConnectionHub.

◆ proto()

virtual IPProto Cogs::Network::ConnectionBase::proto ( ) const
pure virtual

◆ receive()

bool Cogs::Network::ConnectionBase::receive ( void *  buffer,
uint64_t  byteCount,
uint64_t &  bytesReceived 
)

Attempts to read the specified number of bytes from the network socket this connection represents.

If, when returning true, bytesReceived is less than the specified byteCount, this function should be recalled to receive the remaining data.

References check_net_error.

Referenced by Cogs::Network::ConnectionHub::processIncoming().

◆ reconnect()

virtual bool Cogs::Network::ConnectionBase::reconnect ( )
inlinevirtual

Reimplemented in Cogs::Network::ConnectionTCP.

Referenced by Cogs::Network::ThreadFn().

◆ recvFrom()

bool Cogs::Network::ConnectionBase::recvFrom ( void *  buffer,
uint64_t  byteCount,
uint64_t &  bytesReceived,
SockaddrIn addr 
)

Attempts to read the specified number of bytes from the network socket this connection represents.

If, when returning true, bytesReceived is less than the specified byteCount, this function should be recalled to receive the remaining data.

References check_net_error, Cogs::Network::SockaddrIn::getPtr(), and Cogs::Network::SockaddrIn::size().

◆ remove()

void Cogs::Network::ConnectionBase::remove ( )
inline

◆ removeAndDelete()

void Cogs::Network::ConnectionBase::removeAndDelete ( )
inline

◆ send()

bool Cogs::Network::ConnectionBase::send ( const void *  data,
uint64_t  byteCount,
uint64_t &  bytesSent 
)

Attempts to send as much of the specified data as possible.

If, when returning true, bytesSent is less than byteCount, this function should be recalled to send the remaining data.

References check_net_error.

Referenced by Cogs::Network::ConnectionHub::processOutgoing().

◆ sendTo()

bool Cogs::Network::ConnectionBase::sendTo ( const void *  data,
uint64_t  byteCount,
uint64_t &  bytesSent,
const SockaddrIn addr 
)

Attempts to send as much of the specified data as possible.

If, when returning true, bytesSent is less than byteCount, this function should be recalled to send the remaining data.

References check_net_error, Cogs::Network::SockaddrIn::getPtr(), and Cogs::Network::SockaddrIn::size().

◆ setDoNotProcess()

void Cogs::Network::ConnectionBase::setDoNotProcess ( )
inline

◆ setNonblocking()

void Cogs::Network::ConnectionBase::setNonblocking ( bool  val = true)

Sets socket non-blocking mode to val.

References socket.

◆ shouldDelete()

bool Cogs::Network::ConnectionBase::shouldDelete ( ) const
inline

Referenced by Cogs::Network::ThreadFn().

◆ shouldRemove()

bool Cogs::Network::ConnectionBase::shouldRemove ( ) const
inline

Referenced by Cogs::Network::ThreadFn().

◆ type()

virtual SocketType Cogs::Network::ConnectionBase::type ( ) const
pure virtual

Member Data Documentation

◆ cDelete

constexpr uint32_t Cogs::Network::ConnectionBase::cDelete = 0x00000002
staticconstexprprotected

◆ cDoNotProcess

constexpr uint32_t Cogs::Network::ConnectionBase::cDoNotProcess = 0x00000004
staticconstexprprotected

◆ cRemove

constexpr uint32_t Cogs::Network::ConnectionBase::cRemove = 0x00000001
staticconstexprprotected

◆ flags

Cogs::Atomic< uint32_t > Cogs::Network::ConnectionBase::flags = 0
protected

◆ reconnectTime

int64_t Cogs::Network::ConnectionBase::reconnectTime = 0
protected

◆ sockAddr

SockaddrIn Cogs::Network::ConnectionBase::sockAddr = {}
protected

◆ socket

Socket Cogs::Network::ConnectionBase::socket = InvalidSocket
protected

Referenced by setNonblocking().


The documentation for this class was generated from the following files: