1
10
13
14
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
95
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
...
...
...
...
#ifndef NX_TCPSERVER_H
#define NX_TCPSERVER_H
#include "tx_api.h"
#include "nx_api.h"
#ifdef NX_WEB_HTTPS_ENABLE
#ifndef NX_TCPSERVER_ENABLE_TLS
#define NX_TCPSERVER_ENABLE_TLS
#endif
#include "nx_secure_tls_api.h"
/* ... */#endif
#ifndef NX_TCPSERVER_ACCEPT_WAIT
#define NX_TCPSERVER_ACCEPT_WAIT 1
#endif
#ifndef NX_TCPSERVER_DISCONNECT_WAIT
#define NX_TCPSERVER_DISCONNECT_WAIT 1
#endif
#ifndef NX_TCPSERVER_PRIORITY
#define NX_TCPSERVER_PRIORITY 4
#endif
#ifndef NX_TCPSERVER_TIMEOUT_PERIOD
#define NX_TCPSERVER_TIMEOUT_PERIOD 1
#endif
#define NX_TCPSERVER_CONNECT 0x00000001
#define NX_TCPSERVER_DATA 0x00000002
#define NX_TCPSERVER_DISCONNECT 0x00000004
#define NX_TCPSERVER_TIMEOUT 0x00000008
#define NX_TCPSERVER_ANY_EVENT 0xFFFFFFFF
#define NX_TCPSERVER_FAIL 0x01
6 defines
/* ... */
typedef struct NX_TCP_SESSION_STRUCT
{
NX_TCP_SOCKET nx_tcp_session_socket;
ULONG nx_tcp_session_expiration;
UINT nx_tcp_session_connected;
ULONG nx_tcp_session_reserved;
#ifdef NX_TCPSERVER_ENABLE_TLS
UINT nx_tcp_session_using_tls;
NX_SECURE_TLS_SESSION nx_tcp_session_tls_session;/* ... */
#endif
...} NX_TCP_SESSION;
typedef struct NX_TCPSERVER_STRUCT
{
NX_IP *nx_tcpserver_ip;
NX_TCP_SESSION *nx_tcpserver_sessions;
UINT nx_tcpserver_sessions_count;
UINT nx_tcpserver_listen_port;
NX_TCP_SESSION *nx_tcpserver_listen_session;
TX_THREAD nx_tcpserver_thread;
TX_TIMER nx_tcpserver_timer;
TX_EVENT_FLAGS_GROUP nx_tcpserver_event_flags;
ULONG nx_tcpserver_timeout;
ULONG nx_tcpserver_accept_wait_option;
VOID (*nx_tcpserver_new_connection)(struct NX_TCPSERVER_STRUCT *server_ptr, NX_TCP_SESSION *session_ptr);
VOID (*nx_tcpserver_receive_data)(struct NX_TCPSERVER_STRUCT *server_ptr, NX_TCP_SESSION *session_ptr);
VOID (*nx_tcpserver_connection_end)(struct NX_TCPSERVER_STRUCT *server_ptr, NX_TCP_SESSION *session_ptr);
VOID (*nx_tcpserver_connection_timeout)(struct NX_TCPSERVER_STRUCT *server_ptr, NX_TCP_SESSION *session_ptr);
ULONG nx_tcpserver_reserved;
...} NX_TCPSERVER;
#ifndef NX_TCPSERVER_SOURCE_CODE
#define nx_tcpserver_create _nx_tcpserver_create
#define nx_tcpserver_start _nx_tcpserver_start
#define nx_tcpserver_stop _nx_tcpserver_stop
#define nx_tcpserver_delete _nx_tcpserver_delete
#ifdef NX_TCPSERVER_ENABLE_TLS
#define nx_tcpserver_tls_setup _nx_tcpserver_tls_setup
#endif
#ifdef NX_TCPSERVER_ENABLE_TLS
UINT nx_tcpserver_tls_setup(NX_TCPSERVER *server_ptr, const NX_SECURE_TLS_CRYPTO *crypto_table,
VOID *metadata_buffer, ULONG metadata_size, UCHAR* packet_buffer, UINT packet_buffer_size, NX_SECURE_X509_CERT *identity_certificate,
NX_SECURE_X509_CERT *trusted_certificates[], UINT trusted_certs_num, NX_SECURE_X509_CERT *remote_certificates[], UINT remote_certs_num,
UCHAR *remote_certificate_buffer, UINT remote_cert_buffer_size);/* ... */
#endif
UINT nx_tcpserver_create(NX_IP *ip_ptr, NX_TCPSERVER *server_ptr, CHAR *name,
ULONG type_of_service, ULONG fragment, UINT time_to_live, ULONG window_size,
VOID (*new_connection)(NX_TCPSERVER *server_ptr, NX_TCP_SESSION *session_ptr),
VOID (*receive_data)(NX_TCPSERVER *server_ptr, NX_TCP_SESSION *session_ptr),
VOID (*connection_end)(NX_TCPSERVER *server_ptr, NX_TCP_SESSION *session_ptr),
VOID (*connection_timeout)(NX_TCPSERVER *server_ptr, NX_TCP_SESSION *session_ptr),
ULONG timeout, VOID *stack_ptr, UINT stack_size,
VOID *sessions_buffer, UINT buffer_size, UINT thread_priority, ULONG accept_wait_option);
UINT nx_tcpserver_start(NX_TCPSERVER *server_ptr, UINT port, UINT listen_queue_size);
UINT nx_tcpserver_stop(NX_TCPSERVER *server_ptr);
UINT nx_tcpserver_delete(NX_TCPSERVER *server_ptr);
/* ... */
#else
#ifdef NX_TCPSERVER_ENABLE_TLS
UINT _nx_tcpserver_tls_setup(NX_TCPSERVER *server_ptr, const NX_SECURE_TLS_CRYPTO *crypto_table,
VOID *metadata_buffer, ULONG metadata_size, UCHAR* packet_buffer, UINT packet_buffer_size, NX_SECURE_X509_CERT *identity_certificate,
NX_SECURE_X509_CERT *trusted_certificates[], UINT trusted_certs_num, NX_SECURE_X509_CERT *remote_certificates[], UINT remote_certs_num,
UCHAR *remote_certificate_buffer, UINT remote_cert_buffer_size);/* ... */
#endif
UINT _nx_tcpserver_create(NX_IP *ip_ptr, NX_TCPSERVER *server_ptr, CHAR *name,
ULONG type_of_service, ULONG fragment, UINT time_to_live, ULONG window_size,
VOID (*new_connection)(NX_TCPSERVER *server_ptr, NX_TCP_SESSION *session_ptr),
VOID (*receive_data)(NX_TCPSERVER *server_ptr, NX_TCP_SESSION *session_ptr),
VOID (*connection_end)(NX_TCPSERVER *server_ptr, NX_TCP_SESSION *session_ptr),
VOID (*connection_timeout)(NX_TCPSERVER *server_ptr, NX_TCP_SESSION *session_ptr),
ULONG timeout, VOID *stack_ptr, UINT stack_size,
VOID *sessions_buffer, UINT buffer_size, UINT thread_priority, ULONG accept_wait_option);
UINT _nx_tcpserver_start(NX_TCPSERVER *server_ptr, UINT port, UINT listen_queue_size);
UINT _nx_tcpserver_stop(NX_TCPSERVER *server_ptr);
UINT _nx_tcpserver_delete(NX_TCPSERVER *server_ptr);
/* ... */
#endif
/* ... */
...#endif