Amazon Kinesis Webrtc C SDK
Loading...
Searching...
No Matches
SocketConnection.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  __SocketConnection

Macros

#define SOCKET_SEND_RETRY_TIMEOUT_MILLI_SECOND   500
#define MAX_SOCKET_WRITE_RETRY   3
#define CLOSE_SOCKET_IF_CANT_RETRY(e, ps)

Typedefs

typedef STATUS(* ConnectionDataAvailableFunc) (UINT64, struct __SocketConnection *, PBYTE, UINT32, PKvsIpAddress, PKvsIpAddress)
typedef struct __SocketConnection SocketConnection
typedef struct __SocketConnection * PSocketConnection

Functions

STATUS createSocketConnection (KVS_IP_FAMILY_TYPE, KVS_SOCKET_PROTOCOL, PKvsIpAddress, PKvsIpAddress, UINT64, ConnectionDataAvailableFunc, UINT32, PSocketConnection *)
STATUS freeSocketConnection (PSocketConnection *)
STATUS socketConnectionInitSecureConnection (PSocketConnection, BOOL, TIMER_QUEUE_HANDLE)
STATUS socketConnectionSendData (PSocketConnection, PBYTE, UINT32, PKvsIpAddress)
STATUS socketConnectionReadData (PSocketConnection, PBYTE, UINT32, PUINT32)
STATUS socketConnectionShutdownSecureSession (PSocketConnection)
STATUS socketConnectionClosed (PSocketConnection)
BOOL socketConnectionIsClosed (PSocketConnection)
BOOL socketConnectionIsConnected (PSocketConnection)
STATUS socketSendDataWithRetry (PSocketConnection, PBYTE, UINT32, PKvsIpAddress, PUINT32)
STATUS socketConnectionTlsSessionOutBoundPacket (UINT64, PBYTE, UINT32)
VOID socketConnectionTlsSessionOnStateChange (UINT64, TLS_SESSION_STATE)
VOID socketConnectionDtlsSessionOnStateChange (UINT64, RTC_DTLS_TRANSPORT_STATE)
VOID socketConnectionDtlsSessionOutBoundPacket (UINT64, PBYTE, UINT32)

Macro Definition Documentation

◆ CLOSE_SOCKET_IF_CANT_RETRY

#define CLOSE_SOCKET_IF_CANT_RETRY ( e,
ps )
Value:
if ((e) != EAGAIN && (e) != EWOULDBLOCK && (e) != EINTR && (e) != EINPROGRESS && (e) != EPERM && (e) != EALREADY && (e) != ENETUNREACH) { \
DLOGD("Close socket %d", (ps)->localSocket); \
ATOMIC_STORE_BOOL(&(ps)->connectionClosed, TRUE); \
}

◆ MAX_SOCKET_WRITE_RETRY

#define MAX_SOCKET_WRITE_RETRY   3

◆ SOCKET_SEND_RETRY_TIMEOUT_MILLI_SECOND

#define SOCKET_SEND_RETRY_TIMEOUT_MILLI_SECOND   500

Typedef Documentation

◆ ConnectionDataAvailableFunc

typedef STATUS(* ConnectionDataAvailableFunc) (UINT64, struct __SocketConnection *, PBYTE, UINT32, PKvsIpAddress, PKvsIpAddress)

◆ PSocketConnection

◆ SocketConnection

Function Documentation

◆ createSocketConnection()

STATUS createSocketConnection ( KVS_IP_FAMILY_TYPE familyType,
KVS_SOCKET_PROTOCOL protocol,
PKvsIpAddress pBindAddr,
PKvsIpAddress pPeerIpAddr,
UINT64 customData,
ConnectionDataAvailableFunc dataAvailableFn,
UINT32 sendBufSize,
PSocketConnection * ppSocketConnection )

Create a SocketConnection object and store it in PSocketConnection. creates a socket based on KVS_SOCKET_PROTOCOL specified, and bind it to the host IP address. If the protocol is tcp, then peer IP address is required and it will try to establish the tcp connection.

Parameters
-KVS_IP_FAMILY_TYPE - IN - Family for the socket. Must be one of KVS_IP_FAMILY_TYPE
-KVS_SOCKET_PROTOCOL - IN - socket protocol. TCP or UDP
-PKvsIpAddress - IN - host IP address to bind to (OPTIONAL)
-PKvsIpAddress - IN - peer IP address to connect in case of TCP (OPTIONAL)
-UINT64 - IN - data available callback custom data
-ConnectionDataAvailableFunc - IN - data available callback (OPTIONAL)
-UINT32 - IN - send buffer size in bytes
-PSocketConnection* - OUT - the resulting SocketConnection struct
Returns
- STATUS - status of execution
Here is the call graph for this function:
Here is the caller graph for this function:

◆ freeSocketConnection()

STATUS freeSocketConnection ( PSocketConnection * ppSocketConnection)

Free the SocketConnection struct

Parameters
-PSocketConnection* - IN - SocketConnection to be freed
Returns
- STATUS - status of execution
Here is the call graph for this function:
Here is the caller graph for this function:

◆ socketConnectionClosed()

STATUS socketConnectionClosed ( PSocketConnection pSocketConnection)

Mark PSocketConnection as closed

Parameters
-PSocketConnection - IN - the SocketConnection struct
Returns
- STATUS - status of execution
Here is the call graph for this function:
Here is the caller graph for this function:

◆ socketConnectionDtlsSessionOnStateChange()

VOID socketConnectionDtlsSessionOnStateChange ( UINT64 customData,
RTC_DTLS_TRANSPORT_STATE state )

Track DTLS state transitions so handshake timing can be profiled and the socket connection can react to DTLS close and failure events.

Here is the caller graph for this function:

◆ socketConnectionDtlsSessionOutBoundPacket()

VOID socketConnectionDtlsSessionOutBoundPacket ( UINT64 customData,
PBYTE pBuffer,
UINT32 bufferLen )

Send DTLS records produced by the DTLS session to the UDP peer associated with this socket connection.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ socketConnectionInitSecureConnection()

STATUS socketConnectionInitSecureConnection ( PSocketConnection pSocketConnection,
BOOL isServer,
TIMER_QUEUE_HANDLE timerQueueHandle )

Given a created SocketConnection, initialize TLS or DTLS handshake depending on the socket protocol

Parameters
-PSocketConnection - IN - the SocketConnection struct
-BOOL - IN - will SocketConnection act as server during the TLS or DTLS handshake
-TIMER_QUEUE_HANDLE - IN - timer queue used by DTLS to schedule handshake retransmissions. Ignored for TCP/TLS sockets.
Returns
- STATUS - status of execution
Here is the call graph for this function:
Here is the caller graph for this function:

◆ socketConnectionIsClosed()

BOOL socketConnectionIsClosed ( PSocketConnection pSocketConnection)

Check if PSocketConnection is closed

Parameters
-PSocketConnection - IN - the SocketConnection struct
Returns
- BOOL - whether connection is closed
Here is the caller graph for this function:

◆ socketConnectionIsConnected()

BOOL socketConnectionIsConnected ( PSocketConnection pSocketConnection)

Return whether socket has been connected. Return TRUE for UDP sockets. Return TRUE for TCP sockets once the connection has been established, otherwise return FALSE.

Parameters
-PSocketConnection - IN - the SocketConnection struct
Returns
- STATUS - status of execution
Here is the call graph for this function:
Here is the caller graph for this function:

◆ socketConnectionReadData()

STATUS socketConnectionReadData ( PSocketConnection pSocketConnection,
PBYTE pBuf,
UINT32 bufferLen,
PUINT32 pDataLen )

If PSocketConnection is not secure then nothing happens, otherwise assuming the bytes passed in are encrypted, and the encryted data will be replaced with unencrypted data at function return.

Parameters
-PSocketConnection - IN - the SocketConnection struct
-PBYTE - IN/OUT - buffer containing encrypted data. Will contain unencrypted on successful return
-UINT32 - IN - available length of buffer
-PUINT32 - IN/OUT - length of encrypted data. Will contain length of decrypted data on successful return
Returns
- STATUS - status of execution
Here is the call graph for this function:
Here is the caller graph for this function:

◆ socketConnectionSendData()

STATUS socketConnectionSendData ( PSocketConnection pSocketConnection,
PBYTE pBuf,
UINT32 bufLen,
PKvsIpAddress pDestIp )

Given a created SocketConnection, send data through the underlying socket. If socket type is UDP, then destination address is required. If socket type is tcp, destination address is ignored and data is send to the peer address provided at SocketConnection creation. If socketConnectionInitSecureConnection has been called then data will be encrypted, otherwise data will be sent as is.

Parameters
-PSocketConnection - IN - the SocketConnection struct
-PBYTE - IN - buffer containing unencrypted data
-UINT32 - IN - length of buffer
-PKvsIpAddress - IN - destination address. Required only if socket type is UDP.
Returns
- STATUS - status of execution
Here is the call graph for this function:
Here is the caller graph for this function:

◆ socketConnectionShutdownSecureSession()

STATUS socketConnectionShutdownSecureSession ( PSocketConnection pSocketConnection)

Tear down any active TLS/DTLS session while keeping the underlying socket open.

Parameters
-PSocketConnection - IN - the SocketConnection struct
Returns
- STATUS - status of execution
Here is the call graph for this function:
Here is the caller graph for this function:

◆ socketConnectionTlsSessionOnStateChange()

VOID socketConnectionTlsSessionOnStateChange ( UINT64 customData,
TLS_SESSION_STATE state )
Here is the caller graph for this function:

◆ socketConnectionTlsSessionOutBoundPacket()

STATUS socketConnectionTlsSessionOutBoundPacket ( UINT64 customData,
PBYTE pBuffer,
UINT32 bufferLen )

Send TLS records produced by the TLS session over the connected TCP socket.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ socketSendDataWithRetry()

STATUS socketSendDataWithRetry ( PSocketConnection pSocketConnection,
PBYTE buf,
UINT32 bufLen,
PKvsIpAddress pDestIp,
PUINT32 pBytesWritten )
Here is the call graph for this function:
Here is the caller graph for this function: