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_receive_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 /* receive 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_server_socket_unaccept Server socket unaccept */ 65 /* 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_receive_queue_flush(NX_TCP_SOCKET * socket_ptr)76VOID _nx_tcp_socket_receive_queue_flush(NX_TCP_SOCKET *socket_ptr) 77 { 78 79 NX_PACKET *packet_ptr; 80 NX_PACKET *next_packet_ptr; 81 82 83 /* Setup packet pointer. */ 84 packet_ptr = socket_ptr -> nx_tcp_socket_receive_queue_head; 85 86 /* Clear the head and the tail pointers. */ 87 socket_ptr -> nx_tcp_socket_receive_queue_head = NX_NULL; 88 socket_ptr -> nx_tcp_socket_receive_queue_tail = NX_NULL; 89 90 /* Loop to clear all the packets out. */ 91 while (socket_ptr -> nx_tcp_socket_receive_queue_count) 92 { 93 94 /* Pickup the next queued packet. */ 95 next_packet_ptr = packet_ptr -> nx_packet_union_next.nx_packet_tcp_queue_next; 96 97 /* Mark it as allocated so it will be released. */ 98 /*lint -e{923} suppress cast of ULONT to pointer. */ 99 packet_ptr -> nx_packet_union_next.nx_packet_tcp_queue_next = (NX_PACKET *)NX_PACKET_ALLOCATED; 100 101 /* Release the packet. */ 102 _nx_packet_release(packet_ptr); 103 104 /* Move to the next packet. */ 105 packet_ptr = next_packet_ptr; 106 107 /* Decrease the queued packet count. */ 108 socket_ptr -> nx_tcp_socket_receive_queue_count--; 109 } 110 } 111 112