Amazon Kinesis Webrtc C SDK
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 __SocketConnectionPSocketConnection
 

Functions

STATUS createSocketConnection (KVS_IP_FAMILY_TYPE, KVS_SOCKET_PROTOCOL, PKvsIpAddress, PKvsIpAddress, UINT64, ConnectionDataAvailableFunc, UINT32, PSocketConnection *)
 
STATUS freeSocketConnection (PSocketConnection *)
 
STATUS socketConnectionInitSecureConnection (PSocketConnection, BOOL)
 
STATUS socketConnectionSendData (PSocketConnection, PBYTE, UINT32, PKvsIpAddress)
 
STATUS socketConnectionReadData (PSocketConnection, PBYTE, UINT32, PUINT32)
 
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)
 

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:

◆ socketConnectionInitSecureConnection()

STATUS socketConnectionInitSecureConnection ( PSocketConnection  pSocketConnection,
BOOL  isServer 
)

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
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:

◆ 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 
)
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: