1
10
13
14
20
21
22
23
24
25
26
27
28
29
30
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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
143
150
156
157
158
159
160
161
162
163
165
172
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
195
196
197
198
199
200
201
202
203
204
205
211
217
218
220
227
228
229
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
261
262
263
264
265
266
267
268
269
270
271
272
273
274
...
...
...
#define NX_SOURCE_CODE
#include "nx_api.h"
#include "nx_ip.h"
#include "nx_packet.h"
#include "nx_tcp.h"
#include "tx_thread.h"
5 includes
...
...
UINT _nx_tcp_socket_receive(NX_TCP_SOCKET *socket_ptr, NX_PACKET **packet_ptr, ULONG wait_option)
{
NX_IP *ip_ptr;
NX_TCP_HEADER *header_ptr;
NX_PACKET *head_packet_ptr;
ULONG header_length;
#ifdef TX_ENABLE_EVENT_TRACE
TX_TRACE_BUFFER_ENTRY *trace_event;
ULONG trace_timestamp;/* ... */
#endif
ip_ptr = socket_ptr -> nx_tcp_socket_ip_ptr;
*packet_ptr = NX_NULL;
NX_TRACE_IN_LINE_INSERT(NX_TRACE_TCP_SOCKET_RECEIVE, socket_ptr, 0, 0, 0, NX_TRACE_TCP_EVENTS, &trace_event, &trace_timestamp);
tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
if (!socket_ptr -> nx_tcp_socket_bound_next)
{
tx_mutex_put(&(ip_ptr -> nx_ip_protection));
return(NX_NOT_BOUND);
}if (!socket_ptr -> nx_tcp_socket_bound_next) { ... }
if (!socket_ptr -> nx_tcp_socket_receive_queue_head)
{
/* ... */
if ((socket_ptr -> nx_tcp_socket_state < NX_TCP_SYN_SENT) ||
(socket_ptr -> nx_tcp_socket_state == NX_TCP_CLOSE_WAIT) ||
(socket_ptr -> nx_tcp_socket_state >= NX_TCP_CLOSING))
{
tx_mutex_put(&(ip_ptr -> nx_ip_protection));
return(NX_NOT_CONNECTED);
}if ((socket_ptr -> nx_tcp_socket_state < NX_TCP_SYN_SENT) || (socket_ptr -> nx_tcp_socket_state == NX_TCP_CLOSE_WAIT) || (socket_ptr -> nx_tcp_socket_state >= NX_TCP_CLOSING)) { ... }
}if (!socket_ptr -> nx_tcp_socket_receive_queue_head) { ... }
/* ... */
if (socket_ptr -> nx_tcp_socket_receive_queue_head)
{
/* ... */
head_packet_ptr = socket_ptr -> nx_tcp_socket_receive_queue_head;
}if (socket_ptr -> nx_tcp_socket_receive_queue_head) { ... }
else
{
head_packet_ptr = NX_NULL;
}else { ... }
if ((head_packet_ptr) && (head_packet_ptr -> nx_packet_queue_next == ((NX_PACKET *)NX_PACKET_READY)))
{
/* ... */
if (head_packet_ptr == socket_ptr -> nx_tcp_socket_receive_queue_tail)
{
socket_ptr -> nx_tcp_socket_receive_queue_head = NX_NULL;
socket_ptr -> nx_tcp_socket_receive_queue_tail = NX_NULL;
}if (head_packet_ptr == socket_ptr -> nx_tcp_socket_receive_queue_tail) { ... }
else
{
/* ... */
socket_ptr -> nx_tcp_socket_receive_queue_head = head_packet_ptr -> nx_packet_union_next.nx_packet_tcp_queue_next;
}else { ... }
socket_ptr -> nx_tcp_socket_receive_queue_count--;
header_ptr = (NX_TCP_HEADER *)head_packet_ptr -> nx_packet_prepend_ptr;
header_length = (header_ptr -> nx_tcp_header_word_3 >> NX_TCP_HEADER_SHIFT) * (ULONG)sizeof(ULONG);
head_packet_ptr -> nx_packet_prepend_ptr = head_packet_ptr -> nx_packet_prepend_ptr + header_length;
head_packet_ptr -> nx_packet_length = head_packet_ptr -> nx_packet_length - header_length;
/* ... */
head_packet_ptr -> nx_packet_union_next.nx_packet_tcp_queue_next = (NX_PACKET *)NX_PACKET_ALLOCATED;
head_packet_ptr -> nx_packet_queue_next = NX_NULL;
*packet_ptr = head_packet_ptr;
if (socket_ptr -> nx_tcp_socket_receive_queue_count == 0)
{
socket_ptr -> nx_tcp_socket_rx_window_current = socket_ptr -> nx_tcp_socket_rx_window_default;
}if (socket_ptr -> nx_tcp_socket_receive_queue_count == 0) { ... }
else
{
socket_ptr -> nx_tcp_socket_rx_window_current += (*packet_ptr) -> nx_packet_length;
}else { ... }
/* ... */
if (((socket_ptr -> nx_tcp_socket_rx_window_current - socket_ptr -> nx_tcp_socket_rx_window_last_sent) >= (socket_ptr -> nx_tcp_socket_rx_window_default / 2)) &&
((socket_ptr -> nx_tcp_socket_state == NX_TCP_ESTABLISHED) || (socket_ptr -> nx_tcp_socket_state == NX_TCP_FIN_WAIT_1) || (socket_ptr -> nx_tcp_socket_state == NX_TCP_FIN_WAIT_2)))
{
_nx_tcp_packet_send_ack(socket_ptr, socket_ptr -> nx_tcp_socket_tx_sequence);
}if (((socket_ptr -> nx_tcp_socket_rx_window_current - socket_ptr -> nx_tcp_socket_rx_window_last_sent) >= (socket_ptr -> nx_tcp_socket_rx_window_default / 2)) && ((socket_ptr -> nx_tcp_socket_state == NX_TCP_ESTABLISHED) || (socket_ptr -> nx_tcp_socket_state == NX_TCP_FIN_WAIT_1) || (socket_ptr -> nx_tcp_socket_state == NX_TCP_FIN_WAIT_2))) { ... }
#ifdef TX_ENABLE_EVENT_TRACE
NX_TRACE_EVENT_UPDATE(trace_event, trace_timestamp, NX_TRACE_TCP_SOCKET_RECEIVE, 0, *packet_ptr, (*packet_ptr) -> nx_packet_length, socket_ptr -> nx_tcp_socket_rx_sequence);/* ... */
#endif
tx_mutex_put(&(ip_ptr -> nx_ip_protection));
return(NX_SUCCESS);
}if ((head_packet_ptr) && (head_packet_ptr -> nx_packet_queue_next == ((NX_PACKET *)NX_PACKET_READY))) { ... }
else if ((wait_option) && (_tx_thread_current_ptr != &(ip_ptr -> nx_ip_thread)))
{
_tx_thread_current_ptr -> tx_thread_additional_suspend_info = (void *)packet_ptr;
socket_ptr -> nx_tcp_socket_receive_suspended_count++;
_nx_tcp_socket_thread_suspend(&(socket_ptr -> nx_tcp_socket_receive_suspension_list), _nx_tcp_receive_cleanup, socket_ptr, &(ip_ptr -> nx_ip_protection), wait_option);
#ifdef TX_ENABLE_EVENT_TRACE
if (*packet_ptr)
{
NX_TRACE_EVENT_UPDATE(trace_event, trace_timestamp, NX_TRACE_TCP_SOCKET_RECEIVE, 0, *packet_ptr, (*packet_ptr) -> nx_packet_length, socket_ptr -> nx_tcp_socket_rx_sequence);
}if (*packet_ptr) { ... }
/* ... */#endif
return(_tx_thread_current_ptr -> tx_thread_suspend_status);
}else if ((wait_option) && (_tx_thread_current_ptr != &(ip_ptr -> nx_ip_thread))) { ... }
else
{
tx_mutex_put(&(ip_ptr -> nx_ip_protection));
return(NX_NO_PACKET);
}else { ... }
}{ ... }