硬汉嵌入式论坛

 找回密码
 立即注册
查看: 1819|回复: 1
收起左侧

[ThreadX全家桶] NetXDUO函数nx_packet_allocate创建TCP Packet和NX_TCP_SOCKET TCPSocket定义一个的效果是一样的

[复制链接]

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
115834
QQ
发表于 2021-12-19 09:18:21 | 显示全部楼层 |阅读模式

这个函数可以申请各种类似数据包:

QQ截图20211219091218.png

比如申请TCP Packet
  1. /* Allocate a new TCP packet from the previously created packet pool
  2.    and suspend for a maximum of 5 timer ticks if the pool is
  3.    empty. */
  4. status = nx_packet_allocate(&pool_0, &packet_ptr,
  5.                             NX_TCP_PACKET, 5);
复制代码


如果我们定义一个效果是一样的

NX_TCP_SOCKET TCPSocket


回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
115834
QQ
 楼主| 发表于 2021-12-19 09:19:40 | 显示全部楼层

TCP包的结构体定义如下:

  1. /* Define the basic TCP socket structure.  This structure is used to manage all information
  2.    necessary to manage TCP transmission and reception.  */

  3. typedef struct NX_TCP_SOCKET_STRUCT
  4. {

  5.     /* Define the TCP identification that is used to determine if the TCP socket has
  6.        been created.  */
  7.     ULONG       nx_tcp_socket_id;

  8.     /* Define the Application defined name for this TCP socket instance.  */
  9.     CHAR        *nx_tcp_socket_name;

  10.     /* Define the socket type flag.  If true, this socket is a client socket.  */
  11.     UINT        nx_tcp_socket_client_type;

  12.     /* Define the TCP port that was bound to.  */
  13.     UINT        nx_tcp_socket_port;

  14.     /* Define the TCP socket's maximum segment size (mss). By default, this is setup to the
  15.        IP's MTU less the size of the IP and TCP headers.  */
  16.     ULONG       nx_tcp_socket_mss;

  17.     /* Define the connected IP and port information.  */
  18.     NXD_ADDRESS nx_tcp_socket_connect_ip;
  19.     UINT        nx_tcp_socket_connect_port;
  20.     ULONG       nx_tcp_socket_connect_mss;
  21.     ULONG       nx_tcp_socket_peer_mss;
  22.     struct NX_INTERFACE_STRUCT
  23.                 *nx_tcp_socket_connect_interface;
  24.     ULONG       nx_tcp_socket_next_hop_address;

  25.     /* mss2 is the holding place for the smss * smss value.
  26.        It is computed and stored here once for later use. */
  27.     ULONG       nx_tcp_socket_connect_mss2;

  28.     ULONG       nx_tcp_socket_tx_slow_start_threshold;

  29.     /* Define the state of the TCP connection.  */
  30.     UINT        nx_tcp_socket_state;

  31.     /* Define the receive and transmit sequence numbers.   */
  32.     ULONG       nx_tcp_socket_tx_sequence;
  33.     ULONG       nx_tcp_socket_rx_sequence;
  34.     ULONG       nx_tcp_socket_rx_sequence_acked;
  35.     ULONG       nx_tcp_socket_delayed_ack_timeout;
  36.     ULONG       nx_tcp_socket_fin_sequence;
  37.     USHORT      nx_tcp_socket_fin_received;
  38.     USHORT      nx_tcp_socket_fin_acked;

  39.     /* Track the advertised window size */
  40.     ULONG       nx_tcp_socket_tx_window_advertised;
  41.     ULONG       nx_tcp_socket_tx_window_congestion;
  42.     ULONG       nx_tcp_socket_tx_outstanding_bytes; /* Data transmitted but not acked. */

  43.     /* Define the transmit sequence that enters fast transmit. */
  44.     ULONG       nx_tcp_socket_tx_sequence_recover;

  45.     /* Define the previous cumulative acknowledgment.  */
  46.     ULONG       nx_tcp_socket_previous_highest_ack;

  47.     /* Counter for "ack-N-packet" */
  48.     ULONG       nx_tcp_socket_ack_n_packet_counter;

  49.     /* Counter for duplicated ACK  */
  50.     UINT        nx_tcp_socket_duplicated_ack_received;

  51.     /* Define the window size fields of the TCP socket structure.  */
  52.     ULONG       nx_tcp_socket_rx_window_default;
  53.     ULONG       nx_tcp_socket_rx_window_current;
  54.     ULONG       nx_tcp_socket_rx_window_last_sent;

  55.     /* Define the statistic and error counters for this TCP socket.  */
  56.     ULONG       nx_tcp_socket_packets_sent;
  57.     ULONG       nx_tcp_socket_bytes_sent;
  58.     ULONG       nx_tcp_socket_packets_received;
  59.     ULONG       nx_tcp_socket_bytes_received;
  60.     ULONG       nx_tcp_socket_retransmit_packets;
  61.     ULONG       nx_tcp_socket_checksum_errors;

  62.     /* Define data for zero window probe. */
  63.     ULONG       nx_tcp_socket_zero_window_probe_failure;
  64.     ULONG       nx_tcp_socket_zero_window_probe_sequence;
  65.     UCHAR       nx_tcp_socket_zero_window_probe_has_data;
  66.     UCHAR       nx_tcp_socket_zero_window_probe_data;

  67.     /* Define whether or not TCP socket is in fast recovery procedure. */
  68.     UCHAR       nx_tcp_socket_fast_recovery;

  69.     /* Reserved to four bytes alignment. */
  70.     /*lint -esym(768,NX_TCP_SOCKET_STRUCT::nx_tcp_socket_reserved) suppress member not referenced. It is reserved for future use. */
  71.     UCHAR       nx_tcp_socket_reserved;

  72.     /* Define the entry that this TCP socket belongs to.  */
  73.     struct NX_IP_STRUCT
  74.                 *nx_tcp_socket_ip_ptr;

  75.     /* Define the type of service for this TCP instance.  */
  76.     ULONG       nx_tcp_socket_type_of_service;

  77.     /* Define the time-to-live for this TCP instance.  */
  78.     UINT        nx_tcp_socket_time_to_live;

  79.     /* Define the fragment enable bit for this TCP instance.  */
  80.     ULONG       nx_tcp_socket_fragment_enable;

  81.     /* Define the TCP receive packet queue pointers, queue counter, and
  82.        the maximum queue depth.  */
  83.     ULONG       nx_tcp_socket_receive_queue_count;
  84.     NX_PACKET   *nx_tcp_socket_receive_queue_head,
  85.                 *nx_tcp_socket_receive_queue_tail;

  86.     /* Define the TCP packet sent queue. This queue is used to keep track of the
  87.        transmit packets already send.  Before they can be released we need to receive
  88.        an ACK back from the other end of the connection.  If no ACK is received, the
  89.        packet(s) need to be re-transmitted.  */
  90.     ULONG       nx_tcp_socket_transmit_queue_maximum;
  91.     ULONG       nx_tcp_socket_transmit_sent_count;
  92.     NX_PACKET   *nx_tcp_socket_transmit_sent_head,
  93.                 *nx_tcp_socket_transmit_sent_tail;

  94.     /* Define the maximum TCP packet receive queue. */
  95. #ifdef NX_ENABLE_LOW_WATERMARK
  96.     ULONG   nx_tcp_socket_receive_queue_maximum;
  97. #endif /* NX_ENABLE_LOW_WATERMARK */

  98.     /* Define the TCP transmit timeout parameters.  If the socket timeout is non-zero,
  99.        there is an active timeout on the TCP socket.  Subsequent timeouts are derived
  100.        from the timeout rate, which is adjusted higher as timeouts occur.  */
  101.     ULONG       nx_tcp_socket_timeout;
  102.     ULONG       nx_tcp_socket_timeout_rate;
  103.     ULONG       nx_tcp_socket_timeout_retries;
  104.     ULONG       nx_tcp_socket_timeout_max_retries;
  105.     ULONG       nx_tcp_socket_timeout_shift;

  106. #ifdef NX_ENABLE_TCP_WINDOW_SCALING
  107.     /* Local receive window size, when user creates the TCP socket. */
  108.     ULONG       nx_tcp_socket_rx_window_maximum;

  109.     /* Window scale this side needs to offer to the peer. */
  110.     ULONG       nx_tcp_rcv_win_scale_value;

  111.     /* Window scale offered by the peer.  0xFF indicates the peer does not support window scaling. */
  112.     ULONG       nx_tcp_snd_win_scale_value;
  113. #endif /* NX_ENABLE_TCP_WINDOW_SCALING */

  114.     /* Define the TCP keepalive timer parameters.  If enabled with NX_ENABLE_TCP_KEEPALIVE,
  115.        these parameters are used to implement the keepalive timer.  */
  116. #ifdef NX_ENABLE_TCP_KEEPALIVE
  117.     ULONG       nx_tcp_socket_keepalive_timeout;
  118.     ULONG       nx_tcp_socket_keepalive_retries;
  119. #endif /* NX_ENABLE_TCP_KEEPALIVE */

  120.     /* Define the TCP socket bound list.  These pointers are used to manage the list
  121.        of TCP sockets on a particular hashed port index.  */
  122.     struct NX_TCP_SOCKET_STRUCT
  123.                 *nx_tcp_socket_bound_next,
  124.                 *nx_tcp_socket_bound_previous;

  125.     /* Define the TCP socket bind suspension thread pointer.  This pointer points
  126.        to the thread that that is suspended attempting to bind to a port that is
  127.        already bound to another socket.  */
  128.     TX_THREAD   *nx_tcp_socket_bind_in_progress;

  129.     /* Define the TCP receive suspension list head associated with a count of
  130.        how many threads are suspended attempting to receive from the same TCP port.  */
  131.     TX_THREAD   *nx_tcp_socket_receive_suspension_list;
  132.     ULONG       nx_tcp_socket_receive_suspended_count;

  133.     /* Define the TCP transmit suspension list head associated with a count of
  134.        how many threads are suspended attempting to transmit from the same TCP port.  */
  135.     TX_THREAD   *nx_tcp_socket_transmit_suspension_list;
  136.     ULONG       nx_tcp_socket_transmit_suspended_count;

  137.     /* Define the TCP connect suspension pointer that contains the pointer to the
  138.        thread suspended attempting to establish a TCP connection.  */
  139.     TX_THREAD   *nx_tcp_socket_connect_suspended_thread;

  140.     /* Define the TCP disconnect suspension pointer that contains the pointer to the
  141.        thread suspended attempting to break a TCP connection.  */
  142.     TX_THREAD   *nx_tcp_socket_disconnect_suspended_thread;

  143.     /* Define the TCP bind suspension list head associated with a count of
  144.        how many threads are suspended attempting to bind to the same TCP port.  The
  145.        currently bound socket will maintain the head pointer.  When a socket unbinds,
  146.        the head of the suspension list is given the port and the remaining entries
  147.        of the suspension list are transferred to its suspension list head pointer.  */
  148.     TX_THREAD   *nx_tcp_socket_bind_suspension_list;
  149.     ULONG       nx_tcp_socket_bind_suspended_count;

  150.     /* Define the link between other TCP structures created by the application.  This
  151.        is linked to the IP instance the socket was created on.  */
  152.     struct NX_TCP_SOCKET_STRUCT
  153.             *nx_tcp_socket_created_next,
  154.             *nx_tcp_socket_created_previous;

  155.     /* Define the callback function for urgent data reception.  This is for future use.  */
  156.     VOID (*nx_tcp_urgent_data_callback)(struct NX_TCP_SOCKET_STRUCT *socket_ptr);

  157. #ifndef NX_DISABLE_EXTENDED_NOTIFY_SUPPORT
  158.     /* Define the callback function for notifying an incoming SYN request. */
  159.     UINT (*nx_tcp_socket_syn_received_notify)(struct NX_TCP_SOCKET_STRUCT *socket_ptr, NX_PACKET *packet_ptr);

  160.     /* Define the callback function for notifying the host application of a connection handshake completion
  161.        with a remote host.  */
  162.     VOID (*nx_tcp_establish_notify)(struct NX_TCP_SOCKET_STRUCT *socket_ptr);

  163.     /* Define the callback function for notifying the host application of disconnection completion
  164.        with a remote host.  */
  165.     VOID (*nx_tcp_disconnect_complete_notify)(struct NX_TCP_SOCKET_STRUCT *socket_ptr);

  166.     /* Define the callback function for notifying the host application to set the socket
  167.        state in the timed wait state.  */
  168.     VOID (*nx_tcp_timed_wait_callback)(struct NX_TCP_SOCKET_STRUCT *socket_ptr);
  169. #endif

  170.     /* Define the callback function for disconnect detection from the other side of
  171.        the connection.  */
  172.     VOID (*nx_tcp_disconnect_callback)(struct NX_TCP_SOCKET_STRUCT *socket_ptr);

  173.     /* Define the callback function for receive packet notification. If specified
  174.        by the application, this function is called whenever a receive packet is
  175.        available on for the socket.  */
  176.     VOID (*nx_tcp_receive_callback)(struct NX_TCP_SOCKET_STRUCT *socket_ptr);

  177.     /* Define the callback function for receive packet notification. If specified
  178.        by the application, this function is called whenever a receive packet is
  179.        available on for the socket.  */
  180.     VOID (*nx_tcp_socket_window_update_notify)(struct NX_TCP_SOCKET_STRUCT *socket_ptr);

  181. #ifdef   NX_ENABLE_TCP_QUEUE_DEPTH_UPDATE_NOTIFY
  182.     VOID (*nx_tcp_socket_queue_depth_notify)(struct NX_TCP_SOCKET_STRUCT *socket_ptr);
  183. #endif

  184.     /* This pointer is reserved for application specific use.  */
  185.     /*lint -esym(768,NX_TCP_SOCKET_STRUCT::nx_tcp_socket_reserved_ptr) suppress member not referenced. It is reserved for application specific use. */
  186.     void    *nx_tcp_socket_reserved_ptr;

  187.     /* Define the default maximum queue size. This is necessary to dynamically
  188.        change the maximum queue size dynamically.  */
  189.     ULONG   nx_tcp_socket_transmit_queue_maximum_default;

  190.     /* Define a flag for enabling the keepalive feature per TCP socket. */
  191. #ifdef NX_ENABLE_TCP_KEEPALIVE
  192.     UINT    nx_tcp_socket_keepalive_enabled;
  193. #endif /* NX_ENABLE_TCP_KEEPALIVE */

  194. #ifdef FEATURE_NX_IPV6
  195.     struct NXD_IPV6_ADDRESS_STRUCT *nx_tcp_socket_ipv6_addr;
  196. #endif /* FEATURE_NX_IPV6 */

  197. #ifdef NX_IPSEC_ENABLE
  198.     /* Stores a pointer to the SA, if the traffic needs to be protected. */
  199.     VOID *nx_tcp_socket_egress_sa;

  200.     /* Number of bytes to offset from IP header.  This offset is needed to accommondate security header. */
  201.     UINT  nx_tcp_socket_egress_sa_data_offset;

  202. #endif /* NX_IPSEC_ENABLE */

  203.     /* Define the port extension in the TCP socket control block. This
  204.        is typically defined to whitespace in nx_port.h.  */
  205.     NX_TCP_SOCKET_MODULE_EXTENSION
  206.    
  207. } NX_TCP_SOCKET;
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2025-5-21 16:15 , Processed in 0.700917 second(s), 27 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表