Hi Matt,
Some remarks about the progress we’ve made:
- There were unnecessary retransmissions because the IP-stack is impatient.
Recently I created a patch that should avoid this behaviour: “TCP minimum time for retransmissions (PR #387)”. See also this post.
For now you can try this change in FreeRTOS_TCP_WIN.c
-#define winSRTT_CAP_mS 50 /**< Cap in milliseconds. */
+#define winSRTT_CAP_mS 1000 /**< Cap in milliseconds. */
This avoids unnecessary retransmissions. But it doesn’t solve you problem.
- You found that the communication sometimes stalls for 5 seconds.
Could it be that FreeRTOS_send()
can not deliver its data, and it will block for the maximum of 5 seconds?
Note that:
static const TickType_t xSendTimeOut = pdMS_TO_TICKS( 5000 );
I think that FreeRTOS_send()
blocks because of invalid settings, described in the next item 3).
- I noticed that the socket in your application has very little buffer space.
xWinProps.lTxBufSize = ipconfigTCP_TX_BUFFER_LENGTH; // 1000 bytes
xWinProps.lTxWinSize = configECHO_SERVER_TX_WINDOW_SIZE; // 2 segments
xWinProps.lRxBufSize = ipconfigTCP_RX_BUFFER_LENGTH; // 1000 bytes
xWinProps.lRxWinSize = configECHO_SERVER_RX_WINDOW_SIZE; // 2 segments;
The sizes of the buffers are far too small, less than a TCP segment.
These settings are passed to a socket with the socket option FREERTOS_SO_WIN_PROPERTIES
.
Maybe we should adapt the handling in FreeRTOS_setsockopt()
of the FREERTOS_SO_WIN_PROPERTIES
option and refuse wrong settings.
It should be true that:
lTxBufSize >= lTxWinSize * ipconfigTCP_MSS
lRxBufSize >= lRxWinSize * ipconfigTCP_MSS
The help page shows this example:
/* Fill in the required buffer and window sizes. */
/* Unit: bytes */
xWinProps.lTxBufSize = 4 * ipconfigTCP_MSS;
/* Unit: MSS */
xWinProps.lTxWinSize = 2;
/* Unit: bytes */
xWinProps.lRxBufSize = 4 * ipconfigTCP_MSS;
/* Unit: MSS */
xWinProps.lRxWinSize = 2;
It defines:
- lTxBufSize: The size of the internal TX buffer (bytes)
- lTxWinSize: The maximum TCP WIN size for transmissions ( unit MSS, e.g. 1460 bytes )
- lRxBufSize: The size of the internal TX buffer (bytes)
- lRxWinSize: The maximum TCP WIN size for reception ( unit MSS, e.g. 1460 bytes )
Transmission buffers are allocated as soon as they are needed: on reception of the first byte, or when sending the first packet. The configured buffer and WIN sizes are fixed for the life time of the socket.
Thanks,