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 IYISocket::Result Connect (std::chrono::milliseconds timeout=std::chrono::minutes(1)) override
 
virtual IYISocket::Result Disconnect () override
 
virtual bool IsConnected () const override
 
virtual IYISocket::Result Send (const char *pBuffer, size_t bufferSize, std::chrono::milliseconds timeout=std::chrono::minutes(1)) override
 
virtual IYISocket::Result Send (const char *pBuffer, size_t bufferSize, size_t &sent, std::chrono::milliseconds timeout=std::chrono::minutes(1)) override
 
virtual IYISocket::Result Receive (char *pBuffer, size_t length, size_t &received, std::chrono::milliseconds timeout=std::chrono::minutes(1)) override
 
virtual uint64_t GetTotalBytesSent () const override
 
virtual uint64_t GetTotalBytesReceived () const override
 
IYISocket::Result SetSocketOptions (int32_t level, int32_t name, void *pOption, uint32_t size)
 
IYISocket::Result Bind ()
 
bool IsBound () const
 
IYISocket::Result Listen (int32_t backlog) const
 
std::pair< IYISocket::Result, std::unique_ptr< CYITCPSocket > > Accept (std::chrono::milliseconds timeout=std::chrono::minutes(1)) const
 
IYISocket::Result PollForRead (std::chrono::milliseconds timeout)
 
IYISocket::Result PollForWrite (std::chrono::milliseconds timeout)
 
- Public Member Functions inherited from IYISocket
virtual ~IYISocket ()
 

Static Public Member Functions

static std::unique_ptr< CYITCPSocketCreate (const CYIString &host, uint16_t port)
 
static std::unique_ptr< CYITCPSocketCreate (int32_t socketDescriptor, const CYIString &host, uint16_t port)
 

Protected Member Functions

 CYITCPSocket (const CYIString &host, uint16_t port)
 
 CYITCPSocket (int32_t socketDescriptor, const CYIString &host, uint16_t port)
 

Friends

class CYINetworkLogSink
 

Additional Inherited Members

- Public Types inherited from IYISocket
enum  Result {
  Result::Success = 0,
  Result::Error,
  Result::NotConnected,
  Result::Close,
  Result::TimedOut
}
 Possible return values from socket operations. More...
 

Constructor & Destructor Documentation

virtual CYITCPSocket::~CYITCPSocket ( )
virtual
CYITCPSocket::CYITCPSocket ( const CYIString host,
uint16_t  port 
)
protected
CYITCPSocket::CYITCPSocket ( int32_t  socketDescriptor,
const CYIString host,
uint16_t  port 
)
protected

Member Function Documentation

std::pair<IYISocket::Result, std::unique_ptr<CYITCPSocket> > CYITCPSocket::Accept ( std::chrono::milliseconds  timeout = std::chrono::minutes(1)) 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 pair representing a pointer to the accepted socket if there is a connection in the backlog queue, nullptr otherwise and Result to indicate socket operation result.

IYISocket::Result 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 Result to indicate socket operation result.

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 IYISocket::Result CYITCPSocket::Connect ( std::chrono::milliseconds  timeout = std::chrono::minutes(1))
overridevirtual

Initiates a connection based on the socket's address and configuration. Returns Result to indicate socket operation result. timeout is the length of time in milliseconds that the socket will wait for a connection before aborting the Connect() operation. The default timeout is set to 1 minute.

Note
Setting timeout to NO_TIMEOUT will cause the operation to never timeout.

Implements IYISocket.

static std::unique_ptr<CYITCPSocket> CYITCPSocket::Create ( const CYIString host,
uint16_t  port 
)
static

Factory method to create a TCP socket based on a host and port. Returns The created CYITCPSocket or nullptr if there was an error.

static std::unique_ptr<CYITCPSocket> CYITCPSocket::Create ( int32_t  socketDescriptor,
const CYIString host,
uint16_t  port 
)
static

Factory method to create a TCP socket based on a socketDescriptor, host and port. Returns The created CYITCPSocket or nullptr if there was an error.

virtual IYISocket::Result CYITCPSocket::Disconnect ( )
overridevirtual

Closes the connection on the socket. Returns Result to indicate socket operation result.

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.

IYISocket::Result CYITCPSocket::Listen ( int32_t  backlog) 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 backlog. Used for a socket based server. Returns Result to indicate socket operation result.

IYISocket::Result CYITCPSocket::PollForRead ( std::chrono::milliseconds  timeout)

Polls the socket to see if it is ready for I/O or if certain events have occurred on it for the specified amount of time timeout. Returns Result to indicate socket operation result.

Note
Setting timeout to NO_TIMEOUT will cause the operation to never timeout.
IYISocket::Result CYITCPSocket::PollForWrite ( std::chrono::milliseconds  timeout)
virtual IYISocket::Result CYITCPSocket::Receive ( char *  pBuffer,
size_t  length,
size_t received,
std::chrono::milliseconds  timeout = std::chrono::minutes(1) 
)
overridevirtual

Receives a character buffer, pBuffer from a socket, passing in the length,length, of the buffer. received is an output parameter representing the number of bytes successfully received. Returns Result to indicate socket operation result. timeout is the length of time in milliseconds that the socket will wait for until reporting an error. The default timeout is set to 1 minute.

Note
Setting timeout to NO_TIMEOUT will cause the operation to never timeout.

Implements IYISocket.

virtual IYISocket::Result CYITCPSocket::Send ( const char *  pBuffer,
size_t  bufferSize,
std::chrono::milliseconds  timeout = std::chrono::minutes(1) 
)
overridevirtual

Sends the entire contents of the specified buffer to the socket. timeout is the length of time in milliseconds that the socket will wait for until reporting an error. The default timeout is set to 1 minute.

Note
Setting timeout to NO_TIMEOUT will cause the operation to never timeout.

Returns Result to indicate socket operation result.

Implements IYISocket.

virtual IYISocket::Result CYITCPSocket::Send ( const char *  pBuffer,
size_t  bufferSize,
size_t sent,
std::chrono::milliseconds  timeout = std::chrono::minutes(1) 
)
overridevirtual

Tries to send the specified buffer to the socket. sent is an output parameter representing the number of bytes that were successfully sent (the operation may be partial and so the remainder of the buffer needs to be sent separately in such a case). timeout is the length of time in milliseconds that the socket will wait for until reporting an error. The default timeout is set to 1 minute.

Note
Setting timeout to NO_TIMEOUT will cause the operation to never timeout. Returns Result to indicate socket operation result.

Implements IYISocket.

IYISocket::Result CYITCPSocket::SetSocketOptions ( int32_t  level,
int32_t  name,
void *  pOption,
uint32_t  size 
)

Manipulates options for the socket. Options may exist at multiple protocol levels. When manipulating socket options, the level at which the option resides and the name 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 Result to indicate socket operation result.

Friends And Related Function Documentation

friend class CYINetworkLogSink
friend

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