Select one of the symbols to view example projects that use it.
 
Outline
...
...
...
...
#define NX_SOURCE_CODE
#include "nx_api.h"
#include "nx_tcp.h"
#include "nx_packet.h"
...
...
...
_nx_tcp_server_socket_unlisten(NX_IP *, UINT)
Files
loading...
CodeScopeSTM32 Libraries and Samplesnetxduocommon/src/nx_tcp_server_socket_unlisten.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* Copyright (c) Microsoft Corporation. All rights reserved. */ /* */ /* This software is licensed under the Microsoft Software License */ /* Terms for Microsoft Azure RTOS. Full text of the license can be */ /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ /* and in the root directory of this software. */ /* */... /**************************************************************************/ ... /**************************************************************************/ /**************************************************************************/ /** */ /** NetX Component */ /** */ /** Transmission Control Protocol (TCP) */ /** */... /**************************************************************************/ /**************************************************************************/ #define NX_SOURCE_CODE /* Include necessary system files. */ #include "nx_api.h" #include "nx_tcp.h" #include "nx_packet.h" #ifdef NX_ENABLE_TCPIP_OFFLOAD... /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _nx_tcp_server_socket_driver_unlisten PORTABLE C */ /* 6.1.8 */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function handles the TCP server unlisten for TCP/IP offload */ /* interface. */ /* */ /* INPUT */ /* */ /* ip_ptr Pointer to IP instance */ /* socket_ptr Pointer to TCP socket */ /* port TCP port number */ /* */ /* OUTPUT */ /* */ /* status Completion status */ /* */ /* CALLS */ /* */ /* tx_mutex_get Obtain protection */ /* tx_mutex_put Release protection */ /* */ /* CALLED BY */ /* */ /* _nx_tcp_server_socket_unlisten */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 08-02-2021 Yuxin Zhou Initial Version 6.1.8 */ /* */... /**************************************************************************/ static UINT _nx_tcp_server_socket_driver_unlisten(NX_IP *ip_ptr, NX_TCP_SOCKET *socket_ptr, UINT port) { UINT i; NX_INTERFACE *interface_ptr; /* Loop all interfaces to unlisten to ones support TCP/IP offload. */ for (i = 0; i < NX_MAX_IP_INTERFACES; i++) { /* Use a local variable for convenience. */ interface_ptr = &(ip_ptr -> nx_ip_interface[i]); /* Check for valid interfaces. */ if (interface_ptr -> nx_interface_valid == NX_FALSE) { /* Skip interface not valid. */ continue; }if (interface_ptr -> nx_interface_valid == NX_FALSE) { ... } /* Check for TCP/IP offload feature. */ if (((interface_ptr -> nx_interface_capability_flag & NX_INTERFACE_CAPABILITY_TCPIP_OFFLOAD) == 0) || (interface_ptr -> nx_interface_tcpip_offload_handler == NX_NULL)) { /* Skip interface not support TCP/IP offload. */ continue; }if (((interface_ptr -> nx_interface_capability_flag & NX_INTERFACE_CAPABILITY_TCPIP_OFFLOAD) == 0) || (interface_ptr -> nx_interface_tcpip_offload_handler == NX_NULL)) { ... } /* Let TCP/IP offload interface unlisten to port. */ interface_ptr -> nx_interface_tcpip_offload_handler(ip_ptr, interface_ptr, socket_ptr, NX_TCPIP_OFFLOAD_TCP_SERVER_SOCKET_UNLISTEN, NX_NULL, NX_NULL, NX_NULL, port, NX_NULL, NX_NO_WAIT); }for (i = 0; i < NX_MAX_IP_INTERFACES; i++) { ... } return(NX_SUCCESS); }_nx_tcp_server_socket_driver_unlisten (NX_IP *ip_ptr, NX_TCP_SOCKET *socket_ptr, UINT port) { ... } /* ... */#endif /* NX_ENABLE_TCPIP_OFFLOAD */ /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _nx_tcp_server_socket_unlisten PORTABLE C */ /* 6.1.8 */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function removes a previous listen request for the specified */ /* TCP port. */ /* */ /* INPUT */ /* */ /* ip_ptr Pointer to IP instance */ /* port TCP port number */ /* */ /* OUTPUT */ /* */ /* status Completion status */ /* */ /* CALLS */ /* */ /* _nx_packet_release Release queued connection */ /* tx_mutex_get Obtain protection mutex */ /* tx_mutex_put Release protection mutex */ /* */ /* CALLED BY */ /* */ /* Application Code */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ /* 08-02-2021 Yuxin Zhou Modified comment(s), and */ /* supported TCP/IP offload, */ /* resulting in version 6.1.8 */ /* */... /**************************************************************************/ UINT _nx_tcp_server_socket_unlisten(NX_IP *ip_ptr, UINT port) { NX_TCP_SOCKET *socket_ptr; NX_PACKET *packet_ptr; NX_PACKET *next_packet_ptr; ULONG queue_count; struct NX_TCP_LISTEN_STRUCT *listen_ptr; /* If trace is enabled, insert this event into the trace buffer. */ NX_TRACE_IN_LINE_INSERT(NX_TRACE_TCP_SERVER_SOCKET_UNLISTEN, ip_ptr, port, 0, 0, NX_TRACE_TCP_EVENTS, 0, 0); /* Obtain the IP protection. */ tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER); /* Search through the active listen requests to see if we can find one for this port. *//* ... */ listen_ptr = ip_ptr -> nx_ip_tcp_active_listen_requests; if (listen_ptr) { /* Search the active listen requests for this port. */ do { /* Determine if there is a listen request for the specified port. */ if (listen_ptr -> nx_tcp_listen_port == port) { /* Pickup the socket for the listen request. */ socket_ptr = listen_ptr -> nx_tcp_listen_socket_ptr; /* Determine if there was a socket dedicated for listening. */ if (socket_ptr) { /* If trace is enabled, insert this event into the trace buffer. */ 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); /* Yes, clear any connection suspension on this socket. */ if (socket_ptr -> nx_tcp_socket_state != NX_TCP_LISTEN_STATE) { /* Release protection. */ tx_mutex_put(&(ip_ptr -> nx_ip_protection)); /* Return error code. */ return(NX_NOT_LISTEN_STATE); }if (socket_ptr -> nx_tcp_socket_state != NX_TCP_LISTEN_STATE) { ... } /* Change the state of the socket back to closed. */ socket_ptr -> nx_tcp_socket_state = NX_TCP_CLOSED; /* Clear the socket pointer in the listen structure. */ listen_ptr -> nx_tcp_listen_socket_ptr = NX_NULL; }if (socket_ptr) { ... } else { /* Check for queued connection requests, if found, release them all. *//* ... */ queue_count = listen_ptr -> nx_tcp_listen_queue_current; packet_ptr = listen_ptr -> nx_tcp_listen_queue_head; /* Clear the listen connection queue pointers. */ listen_ptr -> nx_tcp_listen_queue_head = NX_NULL; listen_ptr -> nx_tcp_listen_queue_tail = NX_NULL; /* Clear the listen connection count as well. */ listen_ptr -> nx_tcp_listen_queue_current = 0; /* Loop through and release the packets representing queued connections. *//* ... */ while (queue_count--) { /* Save the next pointer. */ next_packet_ptr = packet_ptr -> nx_packet_queue_next; /* Release the packet. */ _nx_packet_release(packet_ptr); /* Move to the next packet. */ packet_ptr = next_packet_ptr; }while (queue_count--) { ... } }else { ... } /* Unlink the listen structure from the active listen requests. */ /* See if the listen structure is the only one on the list. */ if (listen_ptr == listen_ptr -> nx_tcp_listen_next) { /* Only active listen, just set the active list to NULL. */ ip_ptr -> nx_ip_tcp_active_listen_requests = NX_NULL; }if (listen_ptr == listen_ptr -> nx_tcp_listen_next) { ... } else { /* Link-up the neighbors. */ (listen_ptr -> nx_tcp_listen_next) -> nx_tcp_listen_previous = listen_ptr -> nx_tcp_listen_previous; (listen_ptr -> nx_tcp_listen_previous) -> nx_tcp_listen_next = listen_ptr -> nx_tcp_listen_next; /* See if we have to update the active list head pointer. */ if (ip_ptr -> nx_ip_tcp_active_listen_requests == listen_ptr) { /* Yes, move the head pointer to the next link. */ ip_ptr -> nx_ip_tcp_active_listen_requests = listen_ptr -> nx_tcp_listen_next; }if (ip_ptr -> nx_ip_tcp_active_listen_requests == listen_ptr) { ... } }else { ... } /* Add the listen request back to the available list. */ listen_ptr -> nx_tcp_listen_next = ip_ptr -> nx_ip_tcp_available_listen_requests; ip_ptr -> nx_ip_tcp_available_listen_requests = listen_ptr; #ifdef NX_ENABLE_TCPIP_OFFLOAD _nx_tcp_server_socket_driver_unlisten(ip_ptr, socket_ptr, port); #endif /* NX_ENABLE_TCPIP_OFFLOAD */ /* Release the protection. */ tx_mutex_put(&(ip_ptr -> nx_ip_protection)); /* Return success! */ return(NX_SUCCESS); }if (listen_ptr -> nx_tcp_listen_port == port) { ... } /* Move to the next listen request. */ listen_ptr = listen_ptr -> nx_tcp_listen_next; ...} while (listen_ptr != ip_ptr -> nx_ip_tcp_active_listen_requests); }if (listen_ptr) { ... } /* Unsuccessful listen request, release the protection. */ tx_mutex_put(&(ip_ptr -> nx_ip_protection)); /* Return error code. */ return(NX_ENTRY_NOT_FOUND); }{ ... }