Cogs.Core
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
Cogs::Network::ConnectionBase Class Referenceabstract
Inheritance diagram for Cogs::Network::ConnectionBase:
Cogs::Network::ConnectionTCP Cogs::Network::ConnectionUDP Cogs::Network::ConnectionHub

Public Member Functions

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
 

Detailed Description

Definition at line 32 of file Connection.h.

Constructor & Destructor Documentation

◆ ConnectionBase()

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

Definition at line 34 of file Connection.h.

◆ ~ConnectionBase()

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

Definition at line 35 of file Connection.h.

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.

Definition at line 75 of file Connection.cpp.

◆ bind() [2/2]

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

Definition at line 60 of file Connection.h.

◆ close()

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

Internal wrapper for closing the socket.

Definition at line 272 of file Connection.cpp.

◆ create()

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

Internal wrapper for the socket() call.

Definition at line 257 of file Connection.cpp.

◆ disconnect()

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

◆ family()

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

Definition at line 37 of file Connection.h.

◆ getAddress()

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

Definition at line 46 of file Connection.h.

◆ getReconnectTime()

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

Definition at line 47 of file Connection.h.

◆ getSocket()

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

Definition at line 41 of file Connection.h.

◆ isAutoConnectEnabled()

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

Definition at line 49 of file Connection.h.

◆ isConnected()

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

Definition at line 50 of file Connection.h.

◆ processIncoming()

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

Reimplemented in Cogs::Network::ConnectionTCP, and Cogs::Network::ConnectionHub.

Definition at line 70 of file Connection.h.

◆ processOutgoing()

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

Definition at line 69 of file Connection.h.

◆ 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.

Definition at line 141 of file Connection.cpp.

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

◆ reconnect()

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

Reimplemented in Cogs::Network::ConnectionTCP.

Definition at line 57 of file Connection.h.

◆ 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.

Definition at line 217 of file Connection.cpp.

◆ remove()

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

Definition at line 43 of file Connection.h.

◆ removeAndDelete()

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

Definition at line 44 of file Connection.h.

◆ 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.

Definition at line 105 of file Connection.cpp.

◆ 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.

Definition at line 181 of file Connection.cpp.

◆ setDoNotProcess()

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

Definition at line 55 of file Connection.h.

◆ setNonblocking()

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

Sets socket non-blocking mode to val.

Definition at line 60 of file Connection.cpp.

◆ shouldDelete()

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

Definition at line 52 of file Connection.h.

◆ shouldRemove()

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

Definition at line 51 of file Connection.h.

Member Data Documentation

◆ cDelete

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

Definition at line 80 of file Connection.h.

◆ cDoNotProcess

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

Definition at line 81 of file Connection.h.

◆ cRemove

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

Definition at line 79 of file Connection.h.

◆ flags

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

Definition at line 76 of file Connection.h.

◆ reconnectTime

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

Definition at line 77 of file Connection.h.

◆ sockAddr

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

Definition at line 85 of file Connection.h.

◆ socket

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

Definition at line 84 of file Connection.h.


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