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