1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** NetX Component                                                        */
17 /**                                                                       */
18 /**   Transmission Control Protocol (TCP)                                 */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 #define NX_SOURCE_CODE
24 
25 
26 /* Include necessary system files.  */
27 
28 #include "nx_api.h"
29 #include "nx_ip.h"
30 #include "nx_packet.h"
31 #include "nx_tcp.h"
32 
33 
34 /**************************************************************************/
35 /*                                                                        */
36 /*  FUNCTION                                               RELEASE        */
37 /*                                                                        */
38 /*    _nx_tcp_socket_transmit_queue_flush                 PORTABLE C      */
39 /*                                                           6.1          */
40 /*  AUTHOR                                                                */
41 /*                                                                        */
42 /*    Yuxin Zhou, Microsoft Corporation                                   */
43 /*                                                                        */
44 /*  DESCRIPTION                                                           */
45 /*                                                                        */
46 /*    This function releases all packets in the specified socket's        */
47 /*    transmit queue.                                                     */
48 /*                                                                        */
49 /*  INPUT                                                                 */
50 /*                                                                        */
51 /*    socket_ptr                            Pointer to socket             */
52 /*                                                                        */
53 /*  OUTPUT                                                                */
54 /*                                                                        */
55 /*    None                                                                */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*    _nx_packet_release                    Release a packet              */
60 /*                                                                        */
61 /*  CALLED BY                                                             */
62 /*                                                                        */
63 /*    _nx_tcp_socket_connection_reset       Socket connection reset       */
64 /*                                            processing                  */
65 /*    _nx_tcp_socket_disconnect             Socket disconnect processing  */
66 /*                                                                        */
67 /*  RELEASE HISTORY                                                       */
68 /*                                                                        */
69 /*    DATE              NAME                      DESCRIPTION             */
70 /*                                                                        */
71 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
72 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
73 /*                                            resulting in version 6.1    */
74 /*                                                                        */
75 /**************************************************************************/
_nx_tcp_socket_transmit_queue_flush(NX_TCP_SOCKET * socket_ptr)76 VOID  _nx_tcp_socket_transmit_queue_flush(NX_TCP_SOCKET *socket_ptr)
77 {
78 
79 TX_INTERRUPT_SAVE_AREA
80 
81 NX_PACKET *packet_ptr;
82 NX_PACKET *next_packet_ptr;
83 
84 
85     /* Setup packet pointer.  */
86     packet_ptr =  socket_ptr -> nx_tcp_socket_transmit_sent_head;
87 
88     /* Clear the head and the tail pointers.  */
89     socket_ptr -> nx_tcp_socket_transmit_sent_head =  NX_NULL;
90     socket_ptr -> nx_tcp_socket_transmit_sent_tail =  NX_NULL;
91 
92     /* Loop to clear all the packets out.  */
93     while (socket_ptr -> nx_tcp_socket_transmit_sent_count)
94     {
95 
96         /* Disable interrupts.  */
97         TX_DISABLE
98 
99         /* Pickup the next queued packet.  */
100         next_packet_ptr =  packet_ptr -> nx_packet_union_next.nx_packet_tcp_queue_next;
101 
102         /* Mark the packet as no longer being in a TCP queue.  */
103         /*lint -e{923} suppress cast of ULONG to pointer.  */
104         packet_ptr -> nx_packet_union_next.nx_packet_tcp_queue_next =  (NX_PACKET *)NX_PACKET_ALLOCATED;
105 
106         /* Has the packet been transmitted?  */
107         /*lint -e{923} suppress cast of ULONG to pointer.  */
108         if (packet_ptr -> nx_packet_queue_next ==  ((NX_PACKET *)NX_DRIVER_TX_DONE))
109         {
110 
111             /* Yes, the driver has already released the packet.  */
112 
113             /* Restore interrupts.  */
114             TX_RESTORE
115 
116             /* Release the packet.  */
117             _nx_packet_release(packet_ptr);
118         }
119         else
120         {
121 
122             /* Just restore interrupts.  */
123             TX_RESTORE
124         }
125 
126         /* Move to the next packet.  */
127         packet_ptr =  next_packet_ptr;
128 
129         /* Decrease the queued packet count.  */
130         socket_ptr -> nx_tcp_socket_transmit_sent_count--;
131     }
132 }
133 
134