Implements a basic TCP socket.
The CYITCPSocket class provides methods to send and receive data over a TCP/IP connection as well as some utilities to configure and monitor the socket.
#include <network/YiTCPSocket.h>

Public Member Functions | |
| virtual | ~CYITCPSocket () |
| virtual bool | Connect () override |
| virtual bool | Disconnect () override |
| virtual bool | IsConnected () const override |
| virtual IYISocket::SOCKET_RESULT | Send (const char *pBuffer, size_t uLength) override |
| virtual IYISocket::SOCKET_RESULT | Send (const char *pBuffer, size_t uLength, size_t &uSent) override |
| virtual IYISocket::SOCKET_RESULT | Receive (char *pBuffer, size_t uLength, size_t &uReceived) override |
| virtual IYISocket::SOCKET_RESULT | TryReceive (char *pBuffer, size_t uLength, size_t &uReceived) |
| virtual IYISocket::SOCKET_RESULT | TryReceive (char *pBuffer, size_t uLength, size_t &uReceived, int16_t uTimeout) |
| virtual uint64_t | GetTotalBytesSent () const override |
| virtual uint64_t | GetTotalBytesReceived () const override |
| virtual void | SetConnectionTimeoutMs (uint32_t uTimeoutMs) override |
| virtual uint32_t | GetConnectionTimeoutMs () const override |
| bool | SetSocketOptions (int32_t nLevel, int32_t nName, void *pOption, uint32_t uSize) |
| bool | SetSocketBlockingEnabled (bool bBlocking) override |
| bool | Bind () |
| bool | IsBound () const |
| bool | Listen (int32_t bBacklog) const |
| std::unique_ptr< CYITCPSocket > | Accept () const |
| std::unique_ptr< CYITCPSocket > | TryAccept () const |
Public Member Functions inherited from IYISocket | |
| virtual | ~IYISocket () |
Static Public Member Functions | |
| static std::unique_ptr< CYITCPSocket > | Create (const CYIString &host, uint16_t uPort) |
| static std::unique_ptr< CYITCPSocket > | Create (int32_t nSocketDescriptor, const CYIString &host, uint16_t uPort) |
Static Public Member Functions inherited from IYISocket | |
| static bool | SOCKET_OPERATION_SUCCEEDED (SOCKET_RESULT eResult) |
Protected Member Functions | |
| CYITCPSocket (const CYIString &host, uint16_t uPort) | |
| CYITCPSocket (int32_t nSocketDescriptor, const CYIString &host, uint16_t uPort) | |
Additional Inherited Members | |
Public Types inherited from IYISocket | |
| enum | SOCKET_RESULT { YI_SOCKET_SUCCESS, YI_SOCKET_ERROR, YI_SOCKET_NOT_CONNECTED, YI_SOCKET_CLOSE, YI_SOCKET_WOULD_BLOCK } |
| Possible return values from socket operations. More... | |
|
virtual |
|
protected |
|
protected |
| std::unique_ptr<CYITCPSocket> CYITCPSocket::Accept | ( | ) | const |
Extracts the first connection request on the queue of pending connections for the listening socket, and creates a new connected socket. Used for a socket based server. Returns a pointer to the accepted socket if there is a connection in the backlog queue, nullptr otherwise.
| bool CYITCPSocket::Bind | ( | ) |
Establishes the local association of the socket by assigning a local name to an unnamed socket. The bind function is required on an unconnected socket before subsequent calls to Listen(). Used for a socket based server. Returns true if the call succeeded.
|
overridevirtual |
Initiates a connection based on the socket's address and configuration. Returns true if successful.
Implements IYISocket.
|
static |
Factory method to create a TCP socket based on a host and uPort. Returns The created CYITCPSocket or nullptr if there was an error.
|
static |
Factory method to create a TCP socket based on a nSocketDescriptor, host and uPort. Returns The created CYITCPSocket or nullptr if there was an error.
|
overridevirtual |
Closes the connection on the socket. Returns true if successful.
Implements IYISocket.
|
overridevirtual |
Returns the timeout length in milliseconds.
Implements IYISocket.
|
overridevirtual |
Returns the total number of bytes received during the lifetime of the socket.
Implements IYISocket.
|
overridevirtual |
Returns the total number of bytes sent during the lifetime of the socket.
Implements IYISocket.
| bool CYITCPSocket::IsBound | ( | ) | const |
Returns true if the socket is bound.
|
overridevirtual |
Returns true if the socket is connected.
Implements IYISocket.
| bool CYITCPSocket::Listen | ( | int32_t | bBacklog | ) | const |
Places a socket in a state in which it is listening for an incoming connection while setting the maximum number of connections that can be queued on the socket with bBacklog. Used for a socket based server. Returns true if the call succeeded.
|
overridevirtual |
Receives a character buffer, pBuffer from a socket, passing in the length,nLength, of the buffer. nReceived is an output parameter representing the number of bytes successfully received. Returns SOCKET_RESULT to indicate socket operation result.
Implements IYISocket.
|
overridevirtual |
Sends a character buffer, pBuffer along with the buffer length, nLength, to the socket. Returns SOCKET_RESULT to indicate socket operation result.
Implements IYISocket.
|
overridevirtual |
Sends a character buffer, pBuffer along with the buffer length, nLength, to the socket. nSent is an output parameter representing the number of bytes that were successfully sent. Returns SOCKET_RESULT to indicate socket operation result.
Implements IYISocket.
|
overridevirtual |
Sets the length of time in milliseconds uTimeoutMs that the socket will wait for a connection before aborting the Connect() operation. The default timeout is set to 10 seconds (10000 ms).
Implements IYISocket.
|
overridevirtual |
Utility method modifying the socket's internal flags base on bBlocking. When bBlocking is true, further calls to Send(), Receive(), Connect() and Accept() on the socket will block until a response is received. The default state when a socket is created is blocking. Returns true if the call succeeded.
Implements IYISocket.
| bool CYITCPSocket::SetSocketOptions | ( | int32_t | nLevel, |
| int32_t | nName, | ||
| void * | pOption, | ||
| uint32_t | uSize | ||
| ) |
Manipulates options for the socket. Options may exist at multiple protocol levels. When manipulating socket options, the nLevel at which the option resides and the nName of the option must be specified. To manipulate options at the sockets API level, level is specified as SOL_SOCKET. To manipulate options at any other level the protocol number of the appropriate protocol controlling the option is supplied. The argument pOption is the value of the option to be set. Returns true if the call succeeded.
| std::unique_ptr<CYITCPSocket> CYITCPSocket::TryAccept | ( | ) | const |
|
virtual |
|
virtual |