Amazon Kinesis Webrtc C SDK
SocketConnection.h
Go to the documentation of this file.
1 /*******************************************
2 Socket 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
10 extern "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 
22 typedef 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 
34  INT32 localSocket;
38 
41 
42  MUTEX lock;
43 
47 };
49 
68 
77 
87 
102 
114 STATUS socketConnectionReadData(PSocketConnection, PBYTE, UINT32, PUINT32);
115 
124 
133 
143 
144 // internal functions
145 STATUS socketSendDataWithRetry(PSocketConnection, PBYTE, UINT32, PKvsIpAddress, PUINT32);
146 STATUS socketConnectionTlsSessionOutBoundPacket(UINT64, PBYTE, UINT32);
148 
149 #ifdef __cplusplus
150 }
151 #endif
152 #endif /* __KINESIS_VIDEO_WEBRTC_SOCKET_CONNECTION__ */
KVS_IP_FAMILY_TYPE
Definition: Include_i.h:94
struct KvsIpAddress * PKvsIpAddress
KVS_SOCKET_PROTOCOL
Definition: Network.h:48
STATUS socketSendDataWithRetry(PSocketConnection, PBYTE, UINT32, PKvsIpAddress, PUINT32)
Definition: SocketConnection.c:353
BOOL socketConnectionIsConnected(PSocketConnection)
Definition: SocketConnection.c:303
STATUS createSocketConnection(KVS_IP_FAMILY_TYPE, KVS_SOCKET_PROTOCOL, PKvsIpAddress, PKvsIpAddress, UINT64, ConnectionDataAvailableFunc, UINT32, PSocketConnection *)
Definition: SocketConnection.c:7
STATUS socketConnectionSendData(PSocketConnection, PBYTE, UINT32, PKvsIpAddress)
Definition: SocketConnection.c:205
VOID socketConnectionTlsSessionOnStateChange(UINT64, TLS_SESSION_STATE)
Definition: SocketConnection.c:143
STATUS(* ConnectionDataAvailableFunc)(UINT64, struct __SocketConnection *, PBYTE, UINT32, PKvsIpAddress, PKvsIpAddress)
Definition: SocketConnection.h:22
STATUS socketConnectionReadData(PSocketConnection, PBYTE, UINT32, PUINT32)
Definition: SocketConnection.c:243
STATUS socketConnectionTlsSessionOutBoundPacket(UINT64, PBYTE, UINT32)
Definition: SocketConnection.c:130
STATUS socketConnectionClosed(PSocketConnection)
Definition: SocketConnection.c:273
BOOL socketConnectionIsClosed(PSocketConnection)
Definition: SocketConnection.c:294
struct __SocketConnection * PSocketConnection
Definition: SocketConnection.h:48
STATUS socketConnectionInitSecureConnection(PSocketConnection, BOOL)
Definition: SocketConnection.c:170
STATUS freeSocketConnection(PSocketConnection *)
Definition: SocketConnection.c:72
TLS_SESSION_STATE
Definition: Tls.h:10
Definition: Include_i.h:99
Definition: SocketConnection.h:25
INT32 localSocket
Definition: SocketConnection.h:34
ConnectionDataAvailableFunc dataAvailableCallbackFn
Definition: SocketConnection.h:44
volatile ATOMIC_BOOL connectionClosed
Definition: SocketConnection.h:27
volatile ATOMIC_BOOL receiveData
Definition: SocketConnection.h:29
MUTEX lock
Definition: SocketConnection.h:42
UINT64 tlsHandshakeStartTime
Definition: SocketConnection.h:46
KVS_SOCKET_PROTOCOL protocol
Definition: SocketConnection.h:35
UINT64 dataAvailableCallbackCustomData
Definition: SocketConnection.h:45
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