Twitch SDK (Internal)
Public Member Functions | List of all members
ttv::ISocket Class Referenceabstract

#include <socket.h>

Inheritance diagram for ttv::ISocket:
ttv::binding::java::JavaSocket ttv::CFSocket ttv::OpenSslSocket ttv::StandardFileSocket ttv::StandardSocket ttv::WinAppSocket ttv::WinSocket

Public Member Functions

virtual ~ISocket ()=default
 
virtual TTV_ErrorCode Connect ()=0
 
virtual TTV_ErrorCode Disconnect ()=0
 
virtual TTV_ErrorCode Send (const uint8_t *buffer, size_t length)
 
virtual TTV_ErrorCode Send (const uint8_t *buffer, size_t length, size_t &sent)=0
 
virtual TTV_ErrorCode Recv (uint8_t *buffer, size_t length, size_t &received)=0
 
virtual uint64_t TotalSent ()=0
 
virtual uint64_t TotalReceived ()=0
 
virtual bool Connected ()=0
 

Detailed Description

This interface provides generic, synchronous access to a socket. It can wrap any low-level bidirectional byte stream. An instance of ISocket is generally bound to a single endpoint. The connection can be opened and closed as many times as desired but it can't be changed to point to another peer.

Constructor & Destructor Documentation

◆ ~ISocket()

virtual ttv::ISocket::~ISocket ( )
virtualdefault

Destructor.

Member Function Documentation

◆ Connect()

virtual TTV_ErrorCode ttv::ISocket::Connect ( )
pure virtual

Synchronously connects to the endpoint.

See also
Disconnect
Returns
  • TTV_EC_SUCCESS: The socket has successfully connected and is ready to exchange data.
  • TTV_EC_SOCKET_EALREADY: Already connected.
  • TTV_EC_SOCKET_ETIMEDOUT: The connection timed out.
  • TTV_EC_SOCKET_ERR: A generic error occurred.

Implemented in ttv::binding::java::JavaSocket, ttv::WinSocket, ttv::WinAppSocket, ttv::OpenSslSocket, ttv::CFSocket, ttv::StandardFileSocket, and ttv::StandardSocket.

◆ Connected()

virtual bool ttv::ISocket::Connected ( )
pure virtual

Determines if the socket is currently connected.

Returns
Whether or not currently connected.

Implemented in ttv::binding::java::JavaSocket, ttv::WinSocket, ttv::WinAppSocket, ttv::OpenSslSocket, ttv::CFSocket, ttv::StandardFileSocket, and ttv::StandardSocket.

◆ Disconnect()

virtual TTV_ErrorCode ttv::ISocket::Disconnect ( )
pure virtual

Synchronously disconnects from the endpoint. It is safe to call Disconnect() if not connected.

See also
Connect
Returns
  • TTV_EC_SUCCESS: The socket has successfully disconnected.
  • TTV_EC_SOCKET_ERR: A generic error occurred.

Implemented in ttv::binding::java::JavaSocket, ttv::WinSocket, ttv::WinAppSocket, ttv::OpenSslSocket, ttv::CFSocket, ttv::StandardFileSocket, and ttv::StandardSocket.

◆ Recv()

virtual TTV_ErrorCode ttv::ISocket::Recv ( uint8_t *  buffer,
size_t  length,
size_t &  received 
)
pure virtual

Attempts to receive some bytes from the socket.

Parameters
[in]bufferThe buffer to store the received bytes in.
[in]lengthThe largest number of bytes to receive.
[out]receivedThe number of bytes actually received.
Returns
  • TTV_EC_SUCCESS: Some bytes have been received.
  • TTV_EC_SOCKET_EWOULDBLOCK: The socket is connected but there aren't any bytes available to be read.
  • TTV_EC_SOCKET_ENOTCONN: The socket is not connected.
  • TTV_EC_SOCKET_ECONNABORTED: The connected was dropped.
  • TTV_EC_SOCKET_ETIMEDOUT: The connection timed out.
  • TTV_EC_SOCKET_ECONNRESET: The connection was closed by the remote host.
  • TTV_EC_SOCKET_ERR: A generic error occurred.

Implemented in ttv::binding::java::JavaSocket, ttv::WinSocket, ttv::WinAppSocket, ttv::OpenSslSocket, ttv::CFSocket, ttv::StandardFileSocket, and ttv::StandardSocket.

◆ Send() [1/2]

virtual TTV_ErrorCode ttv::ISocket::Send ( const uint8_t *  buffer,
size_t  length 
)
virtual

Attempts to send some bytes over the socket. This flavor of Send() is a helper which guarantees that all bytes are sent or where is an error on the socket.

Parameters
[in]bufferThe buffer to store the received bytes in.
[in]lengthThe number of bytes to send.
Returns
  • TTV_EC_SUCCESS: The bytes have been sent.
  • TTV_EC_SOCKET_ENOTCONN: The socket is not connected.
  • TTV_EC_SOCKET_ECONNABORTED: The connected was dropped.
  • TTV_EC_SOCKET_ETIMEDOUT: The connection timed out.
  • TTV_EC_SOCKET_ECONNRESET: The connection was closed by the remote host.
  • TTV_EC_SOCKET_ERR: A generic error occurred.

Reimplemented in ttv::WinAppSocket.

◆ Send() [2/2]

virtual TTV_ErrorCode ttv::ISocket::Send ( const uint8_t *  buffer,
size_t  length,
size_t &  sent 
)
pure virtual

Attempts to send some bytes over the socket. It's possible that the socket is unable to send able to send any more bytes right now but will be in the near future. Thus, the number actually sent may be less than the size of the passed in buffer.

Parameters
[in]bufferThe buffer to store the received bytes in.
[in]lengthThe number of bytes to send.
[out]sentThe number of bytes actually sent.
Returns
  • TTV_EC_SUCCESS: Some bytes have been sent.
  • TTV_EC_SOCKET_EWOULDBLOCK: The socket is connected but wasn't able to send any bytes right now.
  • TTV_EC_SOCKET_ENOTCONN: The socket is not connected.
  • TTV_EC_SOCKET_ECONNABORTED: The connected was dropped.
  • TTV_EC_SOCKET_ETIMEDOUT: The connection timed out.
  • TTV_EC_SOCKET_ECONNRESET: The connection was closed by the remote host.
  • TTV_EC_SOCKET_ERR: A generic error occurred.

Implemented in ttv::binding::java::JavaSocket, ttv::WinSocket, ttv::OpenSslSocket, ttv::CFSocket, ttv::StandardFileSocket, and ttv::StandardSocket.

◆ TotalReceived()

virtual uint64_t ttv::ISocket::TotalReceived ( )
pure virtual

Returns the total number of bytes that have been received from the socket during the current connection.

Returns
The number of bytes received during the current connection.

Implemented in ttv::binding::java::JavaSocket, ttv::WinSocket, ttv::OpenSslSocket, ttv::CFSocket, ttv::StandardFileSocket, and ttv::StandardSocket.

◆ TotalSent()

virtual uint64_t ttv::ISocket::TotalSent ( )
pure virtual

Returns the total number of bytes that have been sent over the socket during the current connection.

Returns
The number of bytes sent during the current connection.

Implemented in ttv::binding::java::JavaSocket, ttv::WinSocket, ttv::OpenSslSocket, ttv::CFSocket, ttv::StandardFileSocket, and ttv::StandardSocket.


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