Hello @Community member ,
As specified by MS documentation: application data larger than the payload size would require multiple packets chained together. When filling a packet with user data, the application shall use the service nx_packet_data_append.
And it is clearly said: In situations where a packet is not enough to hold user data, additional packets are allocated to store user data.
So before calling nx_packet_data_append, we must have the needed packets number.
After that the nx_tcp_socket_send() is called and also this function will do additional packets allocation in order to do fragmentation..
So before calling nx_packet_data_append, we must have the needed packets number.
Lets explain that with example using Nx_TCP_Echo_Server application and without changing any Pool’s parameters.
- Example 1: transmit 4000 bytes:
//Before calling nx_packet_data_append, AppPool->nx_packet_pool_available = 4
ret = nx_packet_data_append(send_packet,buf,len,&AppPool,NX_WAIT_FOREVER);
//len = 4000 and the number of available bytes in the packet is 1480 so we need allocate 2 more packets in fact 1480 + 1480*2 = 4440 > 4000
//So after calling nx_packet_data_append AppPool->nx_packet_pool_available = 2
ret = nx_tcp_socket_send(&TCPSocket, send_packet, NX_WAIT_FOREVER); // -> OK
//len = 4000 and tcp_window = 1460 so to do fragmentation we need to allocate 2 more packets in fact 1460 + 1460*2 = 4380 > 4000
//So after calling nx_tcp_socket_send AppPool->nx_packet_pool_available = 0
- Example 2: transmit 7000 bytes:
//Before calling nx_packet_data_append AppPool->nx_packet_pool_available = 4
ret = nx_packet_data_append(send_packet,buf,len,&AppPool,NX_WAIT_FOREVER);
//len = 7000 and the number of available bytes in the packet is 1480 so we need to allocate 4 more packets in fact 1480 + 1480*4 = 7400 > 7000
//So after calling nx_packet_data_append AppPool->nx_packet_pool_available = 0 -> so we can not call nx_tcp_socket_send and do fragmentation.
ret = nx_tcp_socket_send (&TCPSocket, send_packet, NX_WAIT_FOREVER); // -> KO
Just to make it short, the maximum payload is a multiple of tcp_window. So, you can adjust your allocation to fit any size, and the transmission will be done automatically once the required data size is reached. tcp_window should be 1480 in most examples. Therefore, the maximum number of bytes to be transmitted can be deduced as explained above.
Hope this Helps.
Walid