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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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
145
146
147
148
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
235
236
237
238
239
240
241
242
243
244
245
...
...
...
#define NX_SOURCE_CODE
#include "nx_api.h"
#include "nx_ip.h"
#include "nx_tcp.h"
...
...
UINT _nx_tcp_socket_create(NX_IP *ip_ptr, NX_TCP_SOCKET *socket_ptr, CHAR *name,
ULONG type_of_service, ULONG fragment, UINT time_to_live, ULONG window_size,
VOID (*tcp_urgent_data_callback)(NX_TCP_SOCKET *socket_ptr),
VOID (*tcp_disconnect_callback)(NX_TCP_SOCKET *socket_ptr))
{
TX_INTERRUPT_SAVE_AREA
NX_TCP_SOCKET *tail_ptr;
memset((void *)socket_ptr, 0, sizeof(NX_TCP_SOCKET));
socket_ptr -> nx_tcp_socket_ip_ptr = ip_ptr;
socket_ptr -> nx_tcp_socket_client_type = NX_TRUE;
socket_ptr -> nx_tcp_socket_name = name;
socket_ptr -> nx_tcp_socket_duplicated_ack_received = 0;
socket_ptr -> nx_tcp_socket_mss = 0;
socket_ptr -> nx_tcp_socket_connect_mss = NX_TCP_MSS_SIZE;
socket_ptr -> nx_tcp_socket_type_of_service = type_of_service;
socket_ptr -> nx_tcp_socket_fragment_enable = fragment & NX_DONT_FRAGMENT;
socket_ptr -> nx_tcp_socket_time_to_live = time_to_live;
socket_ptr -> nx_tcp_socket_bind_in_progress = NX_FALSE;
socket_ptr -> nx_tcp_socket_delayed_ack_timeout = _nx_tcp_ack_timer_rate;
socket_ptr -> nx_tcp_socket_timeout_rate = _nx_tcp_transmit_timer_rate;
socket_ptr -> nx_tcp_socket_timeout_max_retries = NX_TCP_MAXIMUM_RETRIES;
socket_ptr -> nx_tcp_socket_timeout_shift = NX_TCP_RETRY_SHIFT;
socket_ptr -> nx_tcp_socket_transmit_queue_maximum_default = NX_TCP_MAXIMUM_TX_QUEUE;
socket_ptr -> nx_tcp_socket_transmit_queue_maximum = NX_TCP_MAXIMUM_TX_QUEUE;
#ifdef NX_ENABLE_LOW_WATERMARK
socket_ptr -> nx_tcp_socket_receive_queue_maximum = NX_TCP_MAXIMUM_RX_QUEUE;/* ... */
#endif
#ifdef NX_ENABLE_TCP_WINDOW_SCALING
socket_ptr -> nx_tcp_socket_rx_window_maximum = window_size;/* ... */
#endif
socket_ptr -> nx_tcp_socket_rx_window_default = window_size;
socket_ptr -> nx_tcp_socket_rx_window_current = window_size;
socket_ptr -> nx_tcp_socket_tx_outstanding_bytes = 0;
socket_ptr -> nx_tcp_socket_tx_window_advertised = 0;
socket_ptr -> nx_tcp_socket_tx_window_congestion = 0;
socket_ptr -> nx_tcp_socket_ack_n_packet_counter = 1;
socket_ptr -> nx_tcp_urgent_data_callback = tcp_urgent_data_callback;
socket_ptr -> nx_tcp_disconnect_callback = tcp_disconnect_callback;
socket_ptr -> nx_tcp_receive_callback = NX_NULL;
#ifdef NX_ENABLE_TCP_KEEPALIVE
/* ... */
socket_ptr -> nx_tcp_socket_keepalive_enabled = NX_TRUE;
/* ... */
#endif
NX_TRACE_IN_LINE_INSERT(NX_TRACE_INTERNAL_TCP_STATE_CHANGE, ip_ptr, socket_ptr, socket_ptr -> nx_tcp_socket_state, NX_TCP_CLOSED, NX_TRACE_INTERNAL_EVENTS, 0, 0);
socket_ptr -> nx_tcp_socket_state = NX_TCP_CLOSED;
NX_TRACE_OBJECT_REGISTER(NX_TRACE_OBJECT_TYPE_TCP_SOCKET, socket_ptr, name, type_of_service, window_size);
NX_TRACE_IN_LINE_INSERT(NX_TRACE_TCP_SOCKET_CREATE, ip_ptr, socket_ptr, type_of_service, window_size, NX_TRACE_TCP_EVENTS, 0, 0);
tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
TX_DISABLE
socket_ptr -> nx_tcp_socket_id = NX_TCP_ID;
/* ... */
if (ip_ptr -> nx_ip_tcp_created_sockets_ptr)
{
tail_ptr = (ip_ptr -> nx_ip_tcp_created_sockets_ptr) -> nx_tcp_socket_created_previous;
(ip_ptr -> nx_ip_tcp_created_sockets_ptr) -> nx_tcp_socket_created_previous = socket_ptr;
tail_ptr -> nx_tcp_socket_created_next = socket_ptr;
socket_ptr -> nx_tcp_socket_created_previous = tail_ptr;
socket_ptr -> nx_tcp_socket_created_next = ip_ptr -> nx_ip_tcp_created_sockets_ptr;
}if (ip_ptr -> nx_ip_tcp_created_sockets_ptr) { ... }
else
{
ip_ptr -> nx_ip_tcp_created_sockets_ptr = socket_ptr;
socket_ptr -> nx_tcp_socket_created_previous = socket_ptr;
socket_ptr -> nx_tcp_socket_created_next = socket_ptr;
}else { ... }
ip_ptr -> nx_ip_tcp_created_sockets_count++;
#ifdef FEATURE_NX_IPV6
socket_ptr -> nx_tcp_socket_ipv6_addr = NX_NULL;
#endif
#ifdef NX_IPSEC_ENABLE
socket_ptr -> nx_tcp_socket_egress_sa = NX_NULL;
socket_ptr -> nx_tcp_socket_egress_sa_data_offset = 0;/* ... */
#endif
TX_RESTORE
tx_mutex_put(&(ip_ptr -> nx_ip_protection));
return(NX_SUCCESS);
}{ ... }