Cogs.Foundation
|
#include <Connection.h>
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 ConnectionTCP * | accept (Socket, const SockaddrIn &) |
![]() | |
ConnectionBase () | |
virtual | ~ConnectionBase () |
Family | family () const |
virtual SocketType | type () const =0 |
virtual IPProto | proto () const =0 |
Socket | getSocket () const |
void | remove () |
void | removeAndDelete () |
const SockaddrIn & | getAddress () 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 | |
![]() | |
void | create () |
Internal wrapper for the socket() call. | |
void | close () |
Internal wrapper for closing the socket. | |
![]() | |
Cogs::Atomic< uint32_t > | flags = 0 |
int64_t | reconnectTime = 0 |
Socket | socket = InvalidSocket |
SockaddrIn | sockAddr = {} |
![]() | |
static constexpr uint32_t | cRemove = 0x00000001 |
static constexpr uint32_t | cDelete = 0x00000002 |
static constexpr uint32_t | cDoNotProcess = 0x00000004 |
|
inline |
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().
|
virtual |
Destroys this connection.
References Cogs::Network::removeConnection().
|
inlinevirtual |
|
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.
|
inline |
|
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().
|
inline |
|
inlineoverridevirtual |
Reimplemented from Cogs::Network::ConnectionBase.
|
inlineoverridevirtual |
Reimplemented from Cogs::Network::ConnectionBase.
Referenced by Cogs::Network::ConnectionHub::processOutgoing().
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.
|
inline |
|
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().
|
inlineoverridevirtual |
Implements Cogs::Network::ConnectionBase.
|
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.
|
inline |
void Cogs::Network::ConnectionTCP::setNoDelay | ( | bool | val = true | ) |
Set the TCP_NODELAY flag (Enable / Disables Nagles algorithm).
References InvalidSocket.
Referenced by processIncoming().
void Cogs::Network::ConnectionTCP::shutdown | ( | ) |
Shutdown this connection.
|
inlineoverridevirtual |
Implements Cogs::Network::ConnectionBase.
|
staticconstexprprivate |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
private |