Cogs.Foundation
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | Static Private Attributes | List of all members
Cogs::Network::ConnectionTCP Class Reference

#include <Connection.h>

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

Public Member Functions

 ConnectionTCP ()
 
 ConnectionTCP (Socket socket, const SockaddrIn &addr)
 Constructs a connection that is attached to the specified socket.
 
virtual ~ConnectionTCP ()
 Destroys this connection.
 
SocketType type () const override
 
IPProto proto () const override
 
void enableAutoReconnect ()
 
void disableAutoReconnect ()
 
virtual bool isAutoConnectEnabled () const override
 
virtual bool isConnected () const override
 
void setConnectTimeout (int64_t milliseconds)
 
void setNoDelay (bool val=true)
 Set the TCP_NODELAY flag (Enable / Disables Nagles algorithm).
 
void shutdown ()
 Shutdown this connection.
 
virtual bool connect (const SockaddrIn &addr)
 Sets up this connection ready to connect to the specified remote address and port.
 
virtual bool reconnect () override
 Reconnects this connection to the remote host previously specified through a call to connect.
 
virtual bool disconnect () override
 Disconnects this connection.
 
bool listen (uint16_t port)
 
bool listen (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.
 
virtual bool processIncoming () override
 Manages accepting incoming connections when this connection is a listener.
 
virtual ConnectionTCPaccept (Socket, const SockaddrIn &)
 
- Public Member Functions inherited from Cogs::Network::ConnectionBase
 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 ()
 

Private Attributes

int64_t connectTimeout = 0
 

Static Private Attributes

static constexpr uint32_t cListening = 0x00010000
 
static constexpr uint32_t cAutoReconnect = 0x00020000
 
static constexpr uint32_t cNoDelay = 0x00040000
 
static constexpr uint32_t cConnected = 0x00080000
 

Additional Inherited Members

- Protected Member Functions inherited from Cogs::Network::ConnectionBase
void create ()
 Internal wrapper for the socket() call.
 
void close ()
 Internal wrapper for closing the socket.
 
- Protected Attributes inherited from Cogs::Network::ConnectionBase
Cogs::Atomic< uint32_t > flags = 0
 
int64_t reconnectTime = 0
 
Socket socket = InvalidSocket
 
SockaddrIn sockAddr = {}
 
- Static Protected Attributes inherited from Cogs::Network::ConnectionBase
static constexpr uint32_t cRemove = 0x00000001
 
static constexpr uint32_t cDelete = 0x00000002
 
static constexpr uint32_t cDoNotProcess = 0x00000004
 

Constructor & Destructor Documentation

◆ ConnectionTCP() [1/2]

Cogs::Network::ConnectionTCP::ConnectionTCP ( )
inline

◆ ConnectionTCP() [2/2]

Cogs::Network::ConnectionTCP::ConnectionTCP ( Socket  s,
const SockaddrIn addr 
)

Constructs a connection that is attached to the specified socket.

This constructor overload will be called in response to an incoming connection request being accepted.

References Cogs::Network::addConnection().

◆ ~ConnectionTCP()

Cogs::Network::ConnectionTCP::~ConnectionTCP ( )
virtual

Destroys this connection.

References Cogs::Network::removeConnection().

Member Function Documentation

◆ accept()

virtual ConnectionTCP * Cogs::Network::ConnectionTCP::accept ( Socket  ,
const SockaddrIn  
)
inlinevirtual

◆ connect()

bool Cogs::Network::ConnectionTCP::connect ( const SockaddrIn addr)
virtual

Sets up this connection ready to connect to the specified remote address and port.

The actual connecting will be performed by reconnect if necessary.

◆ disableAutoReconnect()

void Cogs::Network::ConnectionTCP::disableAutoReconnect ( )
inline

◆ disconnect()

bool Cogs::Network::ConnectionTCP::disconnect ( )
overridevirtual

Disconnects this connection.

This function is usually called in response to send or receive failing. The connection can be reestablished automatically if required.

Implements Cogs::Network::ConnectionBase.

Reimplemented in Cogs::Network::ConnectionHub.

References InvalidSocket, LOG_INFO, and Cogs::logger.

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

◆ enableAutoReconnect()

void Cogs::Network::ConnectionTCP::enableAutoReconnect ( )
inline

◆ isAutoConnectEnabled()

virtual bool Cogs::Network::ConnectionTCP::isAutoConnectEnabled ( ) const
inlineoverridevirtual

Reimplemented from Cogs::Network::ConnectionBase.

◆ isConnected()

virtual bool Cogs::Network::ConnectionTCP::isConnected ( ) const
inlineoverridevirtual

◆ listen() [1/2]

bool Cogs::Network::ConnectionTCP::listen ( 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.

References Cogs::Network::addConnection(), check_net_error, InvalidSocket, LOG_INFO, and Cogs::logger.

◆ listen() [2/2]

bool Cogs::Network::ConnectionTCP::listen ( uint16_t  port)
inline

References listen().

Referenced by listen().

◆ processIncoming()

bool Cogs::Network::ConnectionTCP::processIncoming ( )
overridevirtual

Manages accepting incoming connections when this connection is a listener.

Reimplemented from Cogs::Network::ConnectionBase.

Reimplemented in Cogs::Network::ConnectionHub.

References InvalidSocket, and setNoDelay().

◆ proto()

IPProto Cogs::Network::ConnectionTCP::proto ( ) const
inlineoverridevirtual

◆ reconnect()

bool Cogs::Network::ConnectionTCP::reconnect ( )
overridevirtual

Reconnects this connection to the remote host previously specified through a call to connect.

Reimplemented from Cogs::Network::ConnectionBase.

References Cogs::Network::addConnection(), check_net_error, InvalidSocket, LOG_INFO, and Cogs::logger.

◆ setConnectTimeout()

void Cogs::Network::ConnectionTCP::setConnectTimeout ( int64_t  milliseconds)
inline

◆ setNoDelay()

void Cogs::Network::ConnectionTCP::setNoDelay ( bool  val = true)

Set the TCP_NODELAY flag (Enable / Disables Nagles algorithm).

References InvalidSocket.

Referenced by processIncoming().

◆ shutdown()

void Cogs::Network::ConnectionTCP::shutdown ( )

Shutdown this connection.

◆ type()

SocketType Cogs::Network::ConnectionTCP::type ( ) const
inlineoverridevirtual

Member Data Documentation

◆ cAutoReconnect

constexpr uint32_t Cogs::Network::ConnectionTCP::cAutoReconnect = 0x00020000
staticconstexprprivate

◆ cConnected

constexpr uint32_t Cogs::Network::ConnectionTCP::cConnected = 0x00080000
staticconstexprprivate

◆ cListening

constexpr uint32_t Cogs::Network::ConnectionTCP::cListening = 0x00010000
staticconstexprprivate

◆ cNoDelay

constexpr uint32_t Cogs::Network::ConnectionTCP::cNoDelay = 0x00040000
staticconstexprprivate

◆ connectTimeout

int64_t Cogs::Network::ConnectionTCP::connectTimeout = 0
private

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