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
96
97
98
99
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
149
150
151
152
153
154
155
156
157
158
159
161
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
191
197
198
199
200
201
202
203
204
205
207
208
209
210
211
212
213
214
215
216
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
246
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
...
...
...
#define NX_SOURCE_CODE
#include "nx_api.h"
#include "nx_tcp.h"
#include "nx_ipv6.h"
...
...
UINT _nx_tcp_client_socket_unbind(NX_TCP_SOCKET *socket_ptr)
{
TX_INTERRUPT_SAVE_AREA
UINT index;
UINT port;
NX_IP *ip_ptr;
NX_TCP_SOCKET *new_socket_ptr;
ip_ptr = socket_ptr -> nx_tcp_socket_ip_ptr;
NX_TRACE_IN_LINE_INSERT(NX_TRACE_TCP_CLIENT_SOCKET_UNBIND, ip_ptr, socket_ptr, 0, 0, NX_TRACE_TCP_EVENTS, 0, 0);
/* ... */
tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
if (socket_ptr -> nx_tcp_socket_state == NX_TCP_TIMED_WAIT)
{
_nx_tcp_socket_block_cleanup(socket_ptr);
}if (socket_ptr -> nx_tcp_socket_state == NX_TCP_TIMED_WAIT) { ... }
if (socket_ptr -> nx_tcp_socket_state != NX_TCP_CLOSED)
{
tx_mutex_put(&(ip_ptr -> nx_ip_protection));
return(NX_NOT_CLOSED);
}if (socket_ptr -> nx_tcp_socket_state != NX_TCP_CLOSED) { ... }
if (!socket_ptr -> nx_tcp_socket_bound_next)
{
/* ... */
if (socket_ptr -> nx_tcp_socket_bind_in_progress)
{
_nx_tcp_client_bind_cleanup(socket_ptr -> nx_tcp_socket_bind_in_progress NX_CLEANUP_ARGUMENT);
tx_mutex_put(&(ip_ptr -> nx_ip_protection));
return(NX_SUCCESS);
}if (socket_ptr -> nx_tcp_socket_bind_in_progress) { ... }
else
{
tx_mutex_put(&(ip_ptr -> nx_ip_protection));
return(NX_NOT_BOUND);
}else { ... }
}if (!socket_ptr -> nx_tcp_socket_bound_next) { ... }
/* ... */
port = socket_ptr -> nx_tcp_socket_port;
index = (UINT)((port + (port >> 8)) & NX_TCP_PORT_TABLE_MASK);
TX_DISABLE
/* ... */
if (socket_ptr -> nx_tcp_socket_receive_queue_count)
{
_nx_tcp_socket_receive_queue_flush(socket_ptr);
}if (socket_ptr -> nx_tcp_socket_receive_queue_count) { ... }
if (socket_ptr -> nx_tcp_socket_bound_next == socket_ptr)
{
ip_ptr -> nx_ip_tcp_port_table[index] = NX_NULL;
socket_ptr -> nx_tcp_socket_bound_next = NX_NULL;
}if (socket_ptr -> nx_tcp_socket_bound_next == socket_ptr) { ... }
else
{
(socket_ptr -> nx_tcp_socket_bound_next) -> nx_tcp_socket_bound_previous =
socket_ptr -> nx_tcp_socket_bound_previous;
(socket_ptr -> nx_tcp_socket_bound_previous) -> nx_tcp_socket_bound_next =
socket_ptr -> nx_tcp_socket_bound_next;
/* ... */
if (ip_ptr -> nx_ip_tcp_port_table[index] == socket_ptr)
{
ip_ptr -> nx_ip_tcp_port_table[index] = socket_ptr -> nx_tcp_socket_bound_next;
}if (ip_ptr -> nx_ip_tcp_port_table[index] == socket_ptr) { ... }
socket_ptr -> nx_tcp_socket_bound_next = NX_NULL;
}else { ... }
TX_RESTORE
/* ... */
if (socket_ptr -> nx_tcp_socket_bind_suspension_list)
{
new_socket_ptr = (NX_TCP_SOCKET *)(socket_ptr -> nx_tcp_socket_bind_suspension_list) -> tx_thread_suspend_control_block;
new_socket_ptr -> nx_tcp_socket_bind_in_progress = NX_NULL;
/* ... */
new_socket_ptr -> nx_tcp_socket_bind_suspension_list =
socket_ptr -> nx_tcp_socket_bind_suspension_list;
new_socket_ptr -> nx_tcp_socket_bind_suspended_count = socket_ptr -> nx_tcp_socket_bind_suspended_count - 1;
socket_ptr -> nx_tcp_socket_bind_suspension_list = NX_NULL;
socket_ptr -> nx_tcp_socket_bind_suspended_count = 0;
TX_DISABLE
if (ip_ptr -> nx_ip_tcp_port_table[index])
{
/* ... */
new_socket_ptr -> nx_tcp_socket_bound_next =
ip_ptr -> nx_ip_tcp_port_table[index];
new_socket_ptr -> nx_tcp_socket_bound_previous =
(ip_ptr -> nx_ip_tcp_port_table[index]) -> nx_tcp_socket_bound_previous;
((ip_ptr -> nx_ip_tcp_port_table[index]) -> nx_tcp_socket_bound_previous) -> nx_tcp_socket_bound_next =
new_socket_ptr;
(ip_ptr -> nx_ip_tcp_port_table[index]) -> nx_tcp_socket_bound_previous = new_socket_ptr;
}if (ip_ptr -> nx_ip_tcp_port_table[index]) { ... }
else
{
/* ... */
new_socket_ptr -> nx_tcp_socket_bound_next = new_socket_ptr;
new_socket_ptr -> nx_tcp_socket_bound_previous = new_socket_ptr;
ip_ptr -> nx_ip_tcp_port_table[index] = new_socket_ptr;
}else { ... }
TX_RESTORE
_nx_tcp_socket_thread_resume(&(new_socket_ptr -> nx_tcp_socket_bind_suspension_list), NX_SUCCESS);
}if (socket_ptr -> nx_tcp_socket_bind_suspension_list) { ... }
tx_mutex_put(&(ip_ptr -> nx_ip_protection));
return(NX_SUCCESS);
}{ ... }