Amazon Kinesis Webrtc C SDK
 
Loading...
Searching...
No Matches
SocketConnection.h
Go to the documentation of this file.
1/*******************************************
2Socket Connection internal include file
3*******************************************/
4#ifndef __KINESIS_VIDEO_WEBRTC_SOCKET_CONNECTION__
5#define __KINESIS_VIDEO_WEBRTC_SOCKET_CONNECTION__
6
7#pragma once
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
13#define SOCKET_SEND_RETRY_TIMEOUT_MILLI_SECOND 500
14#define MAX_SOCKET_WRITE_RETRY 3
15
16#define CLOSE_SOCKET_IF_CANT_RETRY(e, ps) \
17 if ((e) != EAGAIN && (e) != EWOULDBLOCK && (e) != EINTR && (e) != EINPROGRESS && (e) != EPERM && (e) != EALREADY && (e) != ENETUNREACH) { \
18 DLOGD("Close socket %d", (ps)->localSocket); \
19 ATOMIC_STORE_BOOL(&(ps)->connectionClosed, TRUE); \
20 }
21
22typedef STATUS (*ConnectionDataAvailableFunc)(UINT64, struct __SocketConnection*, PBYTE, UINT32, PKvsIpAddress, PKvsIpAddress);
23
26 /* Indicate whether this socket is marked for cleanup */
27 volatile ATOMIC_BOOL connectionClosed;
28 /* Process incoming bits */
29 volatile ATOMIC_BOOL receiveData;
30
31 /* Socket is in use and can't be freed */
32 volatile ATOMIC_BOOL inUse;
33
38
42
43 MUTEX lock;
44
48
49 /* Hostname for TLS verification */
50 PCHAR hostname;
51};
53
72
81
92STATUS socketConnectionInitSecureConnection(PSocketConnection, BOOL, TIMER_QUEUE_HANDLE);
93
108
120STATUS socketConnectionReadData(PSocketConnection, PBYTE, UINT32, PUINT32);
121
130
139
148
158
159// internal functions
160STATUS socketSendDataWithRetry(PSocketConnection, PBYTE, UINT32, PKvsIpAddress, PUINT32);
161
162// TLS and DTLS session callbacks used by SocketConnection to forward encrypted records and react to handshake state
163// changes. These are internal hooks for the secure transport path, not part of the public SocketConnection API.
164STATUS socketConnectionTlsSessionOutBoundPacket(UINT64, PBYTE, UINT32);
167VOID socketConnectionDtlsSessionOutBoundPacket(UINT64, PBYTE, UINT32);
168
169#ifdef __cplusplus
170}
171#endif
172#endif /* __KINESIS_VIDEO_WEBRTC_SOCKET_CONNECTION__ */
RTC_DTLS_TRANSPORT_STATE
Definition Dtls.h:40
KVS_IP_FAMILY_TYPE
Definition Include_i.h:99
struct KvsIpAddress * PKvsIpAddress
KVS_SOCKET_PROTOCOL
Definition Network.h:51
STATUS socketSendDataWithRetry(PSocketConnection, PBYTE, UINT32, PKvsIpAddress, PUINT32)
Definition SocketConnection.c:493
BOOL socketConnectionIsConnected(PSocketConnection)
Definition SocketConnection.c:443
VOID socketConnectionDtlsSessionOutBoundPacket(UINT64, PBYTE, UINT32)
Definition SocketConnection.c:217
STATUS createSocketConnection(KVS_IP_FAMILY_TYPE, KVS_SOCKET_PROTOCOL, PKvsIpAddress, PKvsIpAddress, UINT64, ConnectionDataAvailableFunc, UINT32, PSocketConnection *)
Definition SocketConnection.c:7
STATUS socketConnectionInitSecureConnection(PSocketConnection, BOOL, TIMER_QUEUE_HANDLE)
Definition SocketConnection.c:231
STATUS socketConnectionSendData(PSocketConnection, PBYTE, UINT32, PKvsIpAddress)
Definition SocketConnection.c:294
VOID socketConnectionTlsSessionOnStateChange(UINT64, TLS_SESSION_STATE)
Definition SocketConnection.c:155
STATUS(* ConnectionDataAvailableFunc)(UINT64, struct __SocketConnection *, PBYTE, UINT32, PKvsIpAddress, PKvsIpAddress)
Definition SocketConnection.h:22
STATUS socketConnectionReadData(PSocketConnection, PBYTE, UINT32, PUINT32)
Definition SocketConnection.c:334
STATUS socketConnectionShutdownSecureSession(PSocketConnection)
Definition SocketConnection.c:372
STATUS socketConnectionTlsSessionOutBoundPacket(UINT64, PBYTE, UINT32)
Definition SocketConnection.c:142
STATUS socketConnectionClosed(PSocketConnection)
Definition SocketConnection.c:410
BOOL socketConnectionIsClosed(PSocketConnection)
Definition SocketConnection.c:434
struct __SocketConnection * PSocketConnection
Definition SocketConnection.h:52
STATUS freeSocketConnection(PSocketConnection *)
Definition SocketConnection.c:76
VOID socketConnectionDtlsSessionOnStateChange(UINT64, RTC_DTLS_TRANSPORT_STATE)
Definition SocketConnection.c:186
TLS_SESSION_STATE
Definition Tls.h:10
Definition Include_i.h:105
Definition Dtls.h:108
Definition SocketConnection.h:25
INT32 localSocket
Definition SocketConnection.h:34
ConnectionDataAvailableFunc dataAvailableCallbackFn
Definition SocketConnection.h:45
PDtlsSession pDtlsSession
Definition SocketConnection.h:41
volatile ATOMIC_BOOL connectionClosed
Definition SocketConnection.h:27
volatile ATOMIC_BOOL receiveData
Definition SocketConnection.h:29
MUTEX lock
Definition SocketConnection.h:43
UINT64 tlsHandshakeStartTime
Definition SocketConnection.h:47
KVS_SOCKET_PROTOCOL protocol
Definition SocketConnection.h:35
PCHAR hostname
Definition SocketConnection.h:50
UINT64 dataAvailableCallbackCustomData
Definition SocketConnection.h:46
volatile ATOMIC_BOOL inUse
Definition SocketConnection.h:32
KvsIpAddress peerIpAddr
Definition SocketConnection.h:36
KvsIpAddress hostIpAddr
Definition SocketConnection.h:37
BOOL secureConnection
Definition SocketConnection.h:39
PTlsSession pTlsSession
Definition SocketConnection.h:40
Definition Tls.h:33