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_tcp.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _nx_tcp_socket_transmit_configure                   PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Yuxin Zhou, Microsoft Corporation                                   */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function sets up various parameters associated with the        */
45 /*    socket's transmit operation.                                        */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    socket_ptr                            Pointer to TCP socket         */
50 /*    max_queue_depth                       Maximum number of transmit    */
51 /*                                            packets that can be queued  */
52 /*                                            for the socket              */
53 /*    timeout                               Number of timer ticks for the */
54 /*                                            initial transmit timeout    */
55 /*    max_retries                           Maximum number of retries     */
56 /*    timeout_shift                         Factor to be applied to       */
57 /*                                            subsequent timeouts, a      */
58 /*                                            value of 0 causes identical */
59 /*                                            subsequent timeouts         */
60 /*                                                                        */
61 /*  OUTPUT                                                                */
62 /*                                                                        */
63 /*    status                                Completion status             */
64 /*                                                                        */
65 /*  CALLS                                                                 */
66 /*                                                                        */
67 /*    tx_mutex_get                          Obtain a protection mutex     */
68 /*    tx_mutex_put                          Release a protection mutex    */
69 /*                                                                        */
70 /*  CALLED BY                                                             */
71 /*                                                                        */
72 /*    Application Code                                                    */
73 /*                                                                        */
74 /*  RELEASE HISTORY                                                       */
75 /*                                                                        */
76 /*    DATE              NAME                      DESCRIPTION             */
77 /*                                                                        */
78 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
79 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
80 /*                                            resulting in version 6.1    */
81 /*                                                                        */
82 /**************************************************************************/
_nx_tcp_socket_transmit_configure(NX_TCP_SOCKET * socket_ptr,ULONG max_queue_depth,ULONG timeout,ULONG max_retries,ULONG timeout_shift)83 UINT  _nx_tcp_socket_transmit_configure(NX_TCP_SOCKET *socket_ptr, ULONG max_queue_depth,
84                                         ULONG timeout, ULONG max_retries, ULONG timeout_shift)
85 {
86 
87 NX_IP *ip_ptr;
88 
89 
90     /* Pickup the associated IP structure.  */
91     ip_ptr =  socket_ptr -> nx_tcp_socket_ip_ptr;
92 
93     /* If trace is enabled, insert this event into the trace buffer.  */
94     NX_TRACE_IN_LINE_INSERT(NX_TRACE_TCP_SOCKET_TRANSMIT_CONFIGURE, ip_ptr, socket_ptr, max_queue_depth, timeout, NX_TRACE_TCP_EVENTS, 0, 0);
95 
96     /* Obtain the IP mutex so we can initiate accept processing for this socket.  */
97     tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
98 
99     /* Setup the socket with the new transmit parameters.  */
100     socket_ptr -> nx_tcp_socket_timeout_rate =                    timeout;
101     socket_ptr -> nx_tcp_socket_timeout_max_retries =             max_retries;
102     socket_ptr -> nx_tcp_socket_timeout_shift =                   timeout_shift;
103     socket_ptr -> nx_tcp_socket_transmit_queue_maximum_default =  max_queue_depth;
104     socket_ptr -> nx_tcp_socket_transmit_queue_maximum =          max_queue_depth;
105 
106     /* Release the IP protection.  */
107     tx_mutex_put(&(ip_ptr -> nx_ip_protection));
108 
109     /* Return completion status.  */
110     return(NX_SUCCESS);
111 }
112 
113