heinbali01 wrote on Sunday, August 09, 2015:
Hi Rob,
We handled the issue directly through email. Now for the readers of this forum, here below is a summary of the things that we have found:
Your HTML server replied with data, but you had forgotten to include a ‘Content-Length’, as in:
HTTP/1.1 200 OK
Date: Sun, 9 Aug 2015 22:27:48 GMT
Content-Length: 10<CR><LF>
<CR><LF>
contents<CR><LF>
The browser didn’t like the answers it was receiving and it kept on creating new connections. At your site, the half-closed sockets weren’t properly removed (closed) and after a while all TCP resources were exhausted.
Also I wrote that in a HTML server, sockets must only be closed after a function returns a negative value (normally FreeRTOS_recv()
returning -pdFREERTOS_ERRNO_ENOTCONN
). In principle, the browser is responsible for shutting down unused connections.
Later you asked me why it takes so much time for your bootloader to download its firmware. I answered with the following text:
If you have very little RAM, try at least to make ‘Win
’ double as large as ‘MSS
’. See:
http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/API/setsockopt.html
with the option FREERTOS_SO_WIN_PROPERTIES
.
(
With ‘Win
’ I mean the Window size of the TCP-slicing-windows. It is the maximum amount of data that can be outstanding before receiving an ACK. The RX buffer size must always be at least as big as ‘Win
’, preferably double the size of ‘Win
’.
‘MSS
’ stands for Maximum Segment Size: it is the amount of nett TCP-data (or payload) that will fit in a single Ethernet packet. In the source-code it may be defined as:
#define ipconfigTCP_MSS (ipconfigNETWORK_MTU - ipSIZE_OF_IP_HEADER - ipSIZE_OF_TCP_HEADER)
)
TCP performance is greatly enhanced if there can be at least 1 outstanding packet.
In the following example you will get ‘Win = 2 * MSS
’ for both directions:
/* Declare an xWinProperties structure. */
xWinProperties_t xWinProps;
/* Clear the struct, just in case it will
get extended in the future. */
memset( &xWinProps, '\0', sizeof( xWinProps ) );
/* Fill in the required buffer and window sizes. */
/* Unit: bytes */
xWinProps.lTxBufSize = 2 * ipconfigTCP_MSS;
/* Unit: MSS */
xWinProps.lTxWinSize = 2;
/* Unit: bytes */
xWinProps.lRxBufSize = 2 * ipconfigTCP_MSS; // two or more
/* Unit: MSS */
xWinProps.lRxWinSize = 2;
If your MCU has very little RAM you might want to try a smaller MSS:
#define ipconfigTCP_MSS 536
and get an RX buffer size of at least 2 * 536 = 1072.
If you have enough RAM, you may want to use the maximum of:
#define ipconfigTCP_MSS 1460
Note that you do not set ipconfigTCP_MSS
directly, it will be derived from what you define for MTU:
#define ipconfigNETWORK_MTU 1500
So in order to get an MSS of 536, you’ll define MTU as 536 + 40 = 576:
#define ipconfigNETWORK_MTU 576
After changing the TCP buffer sizes, you wrote: “The speed of the bootloader is staggering now. It programs it faster than a JTAG interface”.
Thanks for that,
Regards.