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

Public Member Functions

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

Detailed Description

Definition at line 111 of file Connection.h.

Constructor & Destructor Documentation

◆ ConnectionTCP() [1/2]

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

Definition at line 113 of file Connection.h.

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

Definition at line 376 of file Connection.cpp.

◆ ~ConnectionTCP()

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

Destroys this connection.

Definition at line 388 of file Connection.cpp.

Member Function Documentation

◆ accept()

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

Definition at line 138 of file Connection.h.

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

Definition at line 399 of file Connection.cpp.

◆ disableAutoReconnect()

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

Definition at line 121 of file Connection.h.

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

Definition at line 488 of file Connection.cpp.

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

◆ enableAutoReconnect()

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

Definition at line 120 of file Connection.h.

◆ isAutoConnectEnabled()

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

Reimplemented from Cogs::Network::ConnectionBase.

Definition at line 122 of file Connection.h.

◆ isConnected()

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

Reimplemented from Cogs::Network::ConnectionBase.

Definition at line 123 of file Connection.h.

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

Definition at line 508 of file Connection.cpp.

◆ listen() [2/2]

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

Definition at line 133 of file Connection.h.

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

Definition at line 538 of file Connection.cpp.

References setNoDelay().

◆ proto()

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

Implements Cogs::Network::ConnectionBase.

Definition at line 118 of file Connection.h.

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

Definition at line 408 of file Connection.cpp.

◆ setConnectTimeout()

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

Definition at line 125 of file Connection.h.

◆ setNoDelay()

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

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

Definition at line 361 of file Connection.cpp.

Referenced by processIncoming().

◆ shutdown()

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

Shutdown this connection.

Definition at line 349 of file Connection.cpp.

◆ type()

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

Implements Cogs::Network::ConnectionBase.

Definition at line 117 of file Connection.h.

Member Data Documentation

◆ cAutoReconnect

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

Definition at line 143 of file Connection.h.

◆ cConnected

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

Definition at line 145 of file Connection.h.

◆ cListening

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

Definition at line 142 of file Connection.h.

◆ cNoDelay

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

Definition at line 144 of file Connection.h.

◆ connectTimeout

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

Definition at line 147 of file Connection.h.


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