Twitch SDK (Internal)
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
ttv::OpenSslSocket Class Reference

#include <standardopensslsocket.h>

Inheritance diagram for ttv::OpenSslSocket:
ttv::ISocket

Public Member Functions

 OpenSslSocket ()
 
 ~OpenSslSocket ()
 
TTV_ErrorCode Initialize (const std::string &host, const std::string &port)
 
virtual TTV_ErrorCode Connect ()
 
virtual TTV_ErrorCode Disconnect ()
 
virtual TTV_ErrorCode Send (const uint8_t *buffer, size_t length, size_t &sent)
 
virtual TTV_ErrorCode Recv (uint8_t *buffer, size_t length, size_t &received)
 
virtual uint64_t TotalSent ()
 
virtual uint64_t TotalReceived ()
 
virtual bool Connected ()
 
TTV_ErrorCode SetCertificateData (const std::string &data)
 
virtual TTV_ErrorCode Send (const uint8_t *buffer, size_t length)
 

Static Public Member Functions

static TTV_ErrorCode InitializeOpenSslSockets ()
 
static TTV_ErrorCode ShutdownOpenSslSockets ()
 
static void SetTrustedHosts (const std::vector< std::string > &trustedHosts)
 

Private Member Functions

TTV_ErrorCode PrepareConnection ()
 
TTV_ErrorCode Handshake ()
 
TTV_ErrorCode Flush ()
 
TTV_ErrorCode FlushOutgoing ()
 
TTV_ErrorCode FlushIncoming ()
 

Private Attributes

std::string mHost
 
std::string mPort
 
std::shared_ptr< ISocketmBaseSocket
 
std::unique_ptr< SocketData > mSocketData
 
std::string mCertificateData
 
bool mConnected
 

Static Private Attributes

static std::vector< std::string > sTrustedHosts
 

Detailed Description

This secure socket implements platform-independent TLS communication. Note that it only supports non-blocking IO.

Constructor & Destructor Documentation

◆ OpenSslSocket()

ttv::OpenSslSocket::OpenSslSocket ( )

◆ ~OpenSslSocket()

ttv::OpenSslSocket::~OpenSslSocket ( )

Member Function Documentation

◆ Connect()

virtual TTV_ErrorCode ttv::OpenSslSocket::Connect ( )
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.

Implements ttv::ISocket.

◆ Connected()

virtual bool ttv::OpenSslSocket::Connected ( )
virtual

Determines if the socket is currently connected.

Returns
Whether or not currently connected.

Implements ttv::ISocket.

◆ Disconnect()

virtual TTV_ErrorCode ttv::OpenSslSocket::Disconnect ( )
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.

Implements ttv::ISocket.

◆ Flush()

TTV_ErrorCode ttv::OpenSslSocket::Flush ( )
private

◆ FlushIncoming()

TTV_ErrorCode ttv::OpenSslSocket::FlushIncoming ( )
private

◆ FlushOutgoing()

TTV_ErrorCode ttv::OpenSslSocket::FlushOutgoing ( )
private

◆ Handshake()

TTV_ErrorCode ttv::OpenSslSocket::Handshake ( )
private

◆ Initialize()

TTV_ErrorCode ttv::OpenSslSocket::Initialize ( const std::string &  host,
const std::string &  port 
)

◆ InitializeOpenSslSockets()

static TTV_ErrorCode ttv::OpenSslSocket::InitializeOpenSslSockets ( )
static

◆ PrepareConnection()

TTV_ErrorCode ttv::OpenSslSocket::PrepareConnection ( )
private

◆ Recv()

virtual TTV_ErrorCode ttv::OpenSslSocket::Recv ( uint8_t *  buffer,
size_t  length,
size_t &  received 
)
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.

Implements ttv::ISocket.

◆ Send() [1/2]

virtual TTV_ErrorCode ttv::OpenSslSocket::Send ( const uint8_t *  buffer,
size_t  length,
size_t &  sent 
)
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.

Implements ttv::ISocket.

◆ Send() [2/2]

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

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.

◆ SetCertificateData()

TTV_ErrorCode ttv::OpenSslSocket::SetCertificateData ( const std::string &  data)

◆ SetTrustedHosts()

static void ttv::OpenSslSocket::SetTrustedHosts ( const std::vector< std::string > &  trustedHosts)
static

Pass in trusted hosts that we allow SSL connections to.

Parameters
[in]Listof strings of hosts that we can trust and verify against.

◆ ShutdownOpenSslSockets()

static TTV_ErrorCode ttv::OpenSslSocket::ShutdownOpenSslSockets ( )
static

◆ TotalReceived()

virtual uint64_t ttv::OpenSslSocket::TotalReceived ( )
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.

Implements ttv::ISocket.

◆ TotalSent()

virtual uint64_t ttv::OpenSslSocket::TotalSent ( )
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.

Implements ttv::ISocket.

Member Data Documentation

◆ mBaseSocket

std::shared_ptr<ISocket> ttv::OpenSslSocket::mBaseSocket
private

◆ mCertificateData

std::string ttv::OpenSslSocket::mCertificateData
private

◆ mConnected

bool ttv::OpenSslSocket::mConnected
private

◆ mHost

std::string ttv::OpenSslSocket::mHost
private

◆ mPort

std::string ttv::OpenSslSocket::mPort
private

◆ mSocketData

std::unique_ptr<SocketData> ttv::OpenSslSocket::mSocketData
private

◆ sTrustedHosts

std::vector<std::string> ttv::OpenSslSocket::sTrustedHosts
staticprivate

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