You.i Engine
CYITCPSocket Class Reference

Detailed Description

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.

Note
The user of the class can get details of any errors that occured during method calls by using the available system calls to get last error.

#include <network/YiTCPSocket.h>

Inheritance diagram for CYITCPSocket:

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< CYITCPSocketAccept () const
 
std::unique_ptr< CYITCPSocketTryAccept () const
 
- Public Member Functions inherited from IYISocket
virtual ~IYISocket ()
 

Static Public Member Functions

static std::unique_ptr< CYITCPSocketCreate (const CYIString &host, uint16_t uPort)
 
static std::unique_ptr< CYITCPSocketCreate (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...
 

Constructor & Destructor Documentation

virtual CYITCPSocket::~CYITCPSocket ( )
virtual
CYITCPSocket::CYITCPSocket ( const CYIString host,
uint16_t  uPort 
)
protected
CYITCPSocket::CYITCPSocket ( int32_t  nSocketDescriptor,
const CYIString host,
uint16_t  uPort 
)
protected

Member Function Documentation

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.

Note
On the PlayStation 4 platform there are limitations around which ports can be bound depending on the application category. The bind operation may succeed when debugging but fail in a packaged build. See Sony documentation around the application category for further information regarding port limitations.
virtual bool CYITCPSocket::Connect ( )
overridevirtual

Initiates a connection based on the socket's address and configuration. Returns true if successful.

Implements IYISocket.

static std::unique_ptr<CYITCPSocket> CYITCPSocket::Create ( const CYIString host,
uint16_t  uPort 
)
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 std::unique_ptr<CYITCPSocket> CYITCPSocket::Create ( int32_t  nSocketDescriptor,
const CYIString host,
uint16_t  uPort 
)
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.

virtual bool CYITCPSocket::Disconnect ( )
overridevirtual

Closes the connection on the socket. Returns true if successful.

Implements IYISocket.

virtual uint32_t CYITCPSocket::GetConnectionTimeoutMs ( ) const
overridevirtual

Returns the timeout length in milliseconds.

Implements IYISocket.

virtual uint64_t CYITCPSocket::GetTotalBytesReceived ( ) const
overridevirtual

Returns the total number of bytes received during the lifetime of the socket.

Implements IYISocket.

virtual uint64_t CYITCPSocket::GetTotalBytesSent ( ) const
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.

virtual bool CYITCPSocket::IsConnected ( ) const
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.

virtual IYISocket::SOCKET_RESULT CYITCPSocket::Receive ( char *  pBuffer,
size_t  uLength,
size_t uReceived 
)
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.

virtual IYISocket::SOCKET_RESULT CYITCPSocket::Send ( const char *  pBuffer,
size_t  uLength 
)
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.

virtual IYISocket::SOCKET_RESULT CYITCPSocket::Send ( const char *  pBuffer,
size_t  uLength,
size_t uSent 
)
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.

virtual void CYITCPSocket::SetConnectionTimeoutMs ( uint32_t  uTimeoutMs)
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).

Note
Socket timeouts are not supported on Tizen-NaCl. The timeout will not be applied on this platform.

Implements IYISocket.

bool CYITCPSocket::SetSocketBlockingEnabled ( bool  bBlocking)
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 IYISocket::SOCKET_RESULT CYITCPSocket::TryReceive ( char *  pBuffer,
size_t  uLength,
size_t uReceived 
)
virtual
virtual IYISocket::SOCKET_RESULT CYITCPSocket::TryReceive ( char *  pBuffer,
size_t  uLength,
size_t uReceived,
int16_t  uTimeout 
)
virtual

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