diff options
author | patacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679> | 2012-09-07 16:51:53 +0000 |
---|---|---|
committer | patacongo <patacongo@7fd9a85b-ad96-42d3-883c-3090e2eb8679> | 2012-09-07 16:51:53 +0000 |
commit | 704679d7b1a8338d656f3ce6565390568ef876b4 (patch) | |
tree | 939ea103590e28bbbde24667cb1a88f9fa559035 | |
parent | b53b1fa813857a9c5053e2e54deb9170d3f5809a (diff) | |
download | px4-firmware-704679d7b1a8338d656f3ce6565390568ef876b4.tar.gz px4-firmware-704679d7b1a8338d656f3ce6565390568ef876b4.tar.bz2 px4-firmware-704679d7b1a8338d656f3ce6565390568ef876b4.zip |
Removed delay after receiving in recvfrom(). This was killing network performance
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@5107 7fd9a85b-ad96-42d3-883c-3090e2eb8679
28 files changed, 130 insertions, 48 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 9e0ca4b68..5f27953c9 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -3274,4 +3274,10 @@ * Kconfig: Verify configuration settings for the LPC43xx. This includes some corrections to configuration variable names and defconfig settings. * Kconfig: Add and verify configuration settings for the LPC31xx. - + * arch/arm/src/stm32/stm32_uart.h and stm32_serial.c: Add logic to + re-initialize the console UART as needed to enable DMA on the + console UART (contributed by Mike Smith). + * net/recvfrom.c, net/Kconfig, include/nuttx/net/uipopt.h: Remove delay + after receiving data. That has historical reasons to be there (it + was needed before read-ahead buffering was added), but kills performance. + (Noted by Max Holtzberg). diff --git a/nuttx/Documentation/NuttxPortingGuide.html b/nuttx/Documentation/NuttxPortingGuide.html index a03d9810f..b5473549a 100644 --- a/nuttx/Documentation/NuttxPortingGuide.html +++ b/nuttx/Documentation/NuttxPortingGuide.html @@ -5037,7 +5037,12 @@ build <code>CONFIG_NET_TCP_READAHEAD_BUFSIZE</code>: Size of TCP read-ahead buffers </li> <li> - <code>CONFIG_NET_NTCP_READAHEAD_BUFFERS</code>: Number of TCP read-ahead buffers (may be zero) + <code>CONFIG_NET_NTCP_READAHEAD_BUFFERS</code>: Number of TCP read-ahead buffers (may be zero to disable TCP/IP read-ahead buffering) + </li> + <li> + <code>CONFIG_NET_TCP_RECVDELAY</code>: Delay (in deciseconds) after a TCP/IP packet is received. + This delay may allow catching of additional packets when TCP/IP read-ahead is disabled. + Default: 0 </li> <li> <code>CONFIG_NET_MAX_LISTENPORTS</code>: Maximum number of listening TCP ports (all tasks). diff --git a/nuttx/arch/arm/src/stm32/stm32_uart.h b/nuttx/arch/arm/src/stm32/stm32_uart.h index 7888d6316..a70923cbf 100644 --- a/nuttx/arch/arm/src/stm32/stm32_uart.h +++ b/nuttx/arch/arm/src/stm32/stm32_uart.h @@ -198,11 +198,11 @@ # define SERIAL_HAVE_CONSOLE_DMA 1 #elif defined(CONFIG_USART3_SERIAL_CONSOLE) && defined(CONFIG_USART3_RXDMA) # define SERIAL_HAVE_CONSOLE_DMA 1 -#elif defined(CONFIG_UART4_SERIAL_CONSOLE) && !efined(CONFIG_UART4_RXDMA) +#elif defined(CONFIG_UART4_SERIAL_CONSOLE) && defined(CONFIG_UART4_RXDMA) # define SERIAL_HAVE_CONSOLE_DMA 1 #elif defined(CONFIG_UART5_SERIAL_CONSOLE) && defined(CONFIG_UART5_RXDMA) # define SERIAL_HAVE_CONSOLE_DMA 1 -#elif defined(CONFIG_USART6_SERIAL_CONSOLE) && !efined(CONFIG_USART6_RXDMA) +#elif defined(CONFIG_USART6_SERIAL_CONSOLE) && defined(CONFIG_USART6_RXDMA) # define SERIAL_HAVE_CONSOLE_DMA 1 #endif diff --git a/nuttx/configs/README.txt b/nuttx/configs/README.txt index 7ad2825d0..6cd5eef3f 100644 --- a/nuttx/configs/README.txt +++ b/nuttx/configs/README.txt @@ -990,7 +990,10 @@ defconfig -- This is a configuration file similar to the Linux CONFIG_NET_MAX_LISTENPORTS - Maximum number of listening TCP ports (all tasks) CONFIG_NET_TCP_READAHEAD_BUFSIZE - Size of TCP read-ahead buffers CONFIG_NET_NTCP_READAHEAD_BUFFERS - Number of TCP read-ahead buffers - (may be zero) + (may be zero to disable TCP/IP read-ahead buffering) + CONFIG_NET_TCP_RECVDELAY - Delay (in deciseconds) after a TCP/IP packet + is received. This delay may allow catching of additional packets + when TCP/IP read-ahead is disabled. Default: 0 CONFIG_NET_TCPBACKLOG - Incoming connections pend in a backlog until accept() is called. The size of the backlog is selected when listen() is called. diff --git a/nuttx/configs/olimex-stm32-p107/nsh/defconfig b/nuttx/configs/olimex-stm32-p107/nsh/defconfig index 18858d5df..c7c71018a 100644 --- a/nuttx/configs/olimex-stm32-p107/nsh/defconfig +++ b/nuttx/configs/olimex-stm32-p107/nsh/defconfig @@ -365,7 +365,7 @@ CONFIG_NET_MULTICAST=n # # STM32F107vc Ethernet device driver settings # -CONFIG_STM32_PHYADDR=0x01 +CONFIG_STM32_PHYADDR=1 CONFIG_STM32_MII=n CONFIG_STM32_RMII=y CONFIG_STM32_RMII_MCO=y diff --git a/nuttx/configs/stm3220g-eval/dhcpd/defconfig b/nuttx/configs/stm3220g-eval/dhcpd/defconfig index 848121e04..433fe97d2 100644 --- a/nuttx/configs/stm3220g-eval/dhcpd/defconfig +++ b/nuttx/configs/stm3220g-eval/dhcpd/defconfig @@ -197,7 +197,7 @@ CONFIG_CAN2_BAUD=700000 # # STM32F20xxx Ethernet device driver settings # -CONFIG_STM32_PHYADDR=0x01 +CONFIG_STM32_PHYADDR=1 CONFIG_STM32_MII=y CONFIG_STM32_MII_MCO1=y CONFIG_STM32_MII_MCO2=n diff --git a/nuttx/configs/stm3220g-eval/nettest/defconfig b/nuttx/configs/stm3220g-eval/nettest/defconfig index 7e660ad02..ef5c2da96 100644 --- a/nuttx/configs/stm3220g-eval/nettest/defconfig +++ b/nuttx/configs/stm3220g-eval/nettest/defconfig @@ -197,7 +197,7 @@ CONFIG_CAN2_BAUD=700000 # # STM32F20xxx Ethernet device driver settings # -CONFIG_STM32_PHYADDR=0x01 +CONFIG_STM32_PHYADDR=1 CONFIG_STM32_MII=y CONFIG_STM32_MII_MCO1=y CONFIG_STM32_MII_MCO2=n diff --git a/nuttx/configs/stm3220g-eval/nsh/defconfig b/nuttx/configs/stm3220g-eval/nsh/defconfig index 48912bd8b..591f24616 100644 --- a/nuttx/configs/stm3220g-eval/nsh/defconfig +++ b/nuttx/configs/stm3220g-eval/nsh/defconfig @@ -197,7 +197,7 @@ CONFIG_CAN2_BAUD=700000 # # STM32F20xxx Ethernet device driver settings # -CONFIG_STM32_PHYADDR=0x01 +CONFIG_STM32_PHYADDR=1 CONFIG_STM32_MII=y CONFIG_STM32_MII_MCO1=y CONFIG_STM32_MII_MCO2=n diff --git a/nuttx/configs/stm3220g-eval/nsh2/defconfig b/nuttx/configs/stm3220g-eval/nsh2/defconfig index c2ede9c67..03ee777f4 100644 --- a/nuttx/configs/stm3220g-eval/nsh2/defconfig +++ b/nuttx/configs/stm3220g-eval/nsh2/defconfig @@ -197,7 +197,7 @@ CONFIG_CAN2_BAUD=700000 # # STM32F20xxx Ethernet device driver settings # -CONFIG_STM32_PHYADDR=0x01 +CONFIG_STM32_PHYADDR=1 CONFIG_STM32_MII=y CONFIG_STM32_MII_MCO1=y CONFIG_STM32_MII_MCO2=n diff --git a/nuttx/configs/stm3220g-eval/nxwm/defconfig b/nuttx/configs/stm3220g-eval/nxwm/defconfig index 6e6933325..bd59f47de 100644 --- a/nuttx/configs/stm3220g-eval/nxwm/defconfig +++ b/nuttx/configs/stm3220g-eval/nxwm/defconfig @@ -197,7 +197,7 @@ CONFIG_CAN2_BAUD=700000 # # STM32F20xxx Ethernet device driver settings # -CONFIG_STM32_PHYADDR=0x01 +CONFIG_STM32_PHYADDR=1 CONFIG_STM32_MII=y CONFIG_STM32_MII_MCO1=y CONFIG_STM32_MII_MCO2=n diff --git a/nuttx/configs/stm3220g-eval/ostest/defconfig b/nuttx/configs/stm3220g-eval/ostest/defconfig index d0ace11bc..30ec69419 100644 --- a/nuttx/configs/stm3220g-eval/ostest/defconfig +++ b/nuttx/configs/stm3220g-eval/ostest/defconfig @@ -197,7 +197,7 @@ CONFIG_CAN2_BAUD=700000 # # STM32F20xxx Ethernet device driver settings # -CONFIG_STM32_PHYADDR=0x01 +CONFIG_STM32_PHYADDR=1 CONFIG_STM32_MII=y CONFIG_STM32_MII_MCO1=y CONFIG_STM32_MII_MCO2=n diff --git a/nuttx/configs/stm3220g-eval/telnetd/defconfig b/nuttx/configs/stm3220g-eval/telnetd/defconfig index 2ff215afc..550f654ba 100644 --- a/nuttx/configs/stm3220g-eval/telnetd/defconfig +++ b/nuttx/configs/stm3220g-eval/telnetd/defconfig @@ -197,7 +197,7 @@ CONFIG_CAN2_BAUD=700000 # # STM32F20xxx Ethernet device driver settings # -CONFIG_STM32_PHYADDR=0x01 +CONFIG_STM32_PHYADDR=1 CONFIG_STM32_MII=y CONFIG_STM32_MII_MCO1=y CONFIG_STM32_MII_MCO2=n diff --git a/nuttx/configs/stm3240g-eval/dhcpd/defconfig b/nuttx/configs/stm3240g-eval/dhcpd/defconfig index 382ce6155..4e22244bb 100644 --- a/nuttx/configs/stm3240g-eval/dhcpd/defconfig +++ b/nuttx/configs/stm3240g-eval/dhcpd/defconfig @@ -203,7 +203,7 @@ CONFIG_CAN2_BAUD=700000 # # STM32F40xxx Ethernet device driver settings # -CONFIG_STM32_PHYADDR=0x01 +CONFIG_STM32_PHYADDR=1 CONFIG_STM32_MII=y CONFIG_STM32_MII_MCO1=y CONFIG_STM32_MII_MCO2=n diff --git a/nuttx/configs/stm3240g-eval/nettest/defconfig b/nuttx/configs/stm3240g-eval/nettest/defconfig index 9eb8f3d5c..e21c1070b 100644 --- a/nuttx/configs/stm3240g-eval/nettest/defconfig +++ b/nuttx/configs/stm3240g-eval/nettest/defconfig @@ -203,7 +203,7 @@ CONFIG_CAN2_BAUD=700000 # # STM32F40xxx Ethernet device driver settings # -CONFIG_STM32_PHYADDR=0x01 +CONFIG_STM32_PHYADDR=1 CONFIG_STM32_MII=y CONFIG_STM32_MII_MCO1=y CONFIG_STM32_MII_MCO2=n diff --git a/nuttx/configs/stm3240g-eval/nsh/defconfig b/nuttx/configs/stm3240g-eval/nsh/defconfig index 8b2617ec0..34f84db07 100644 --- a/nuttx/configs/stm3240g-eval/nsh/defconfig +++ b/nuttx/configs/stm3240g-eval/nsh/defconfig @@ -203,7 +203,7 @@ CONFIG_CAN2_BAUD=700000 # # STM32F40xxx Ethernet device driver settings # -CONFIG_STM32_PHYADDR=0x01 +CONFIG_STM32_PHYADDR=1 CONFIG_STM32_MII=y CONFIG_STM32_MII_MCO1=y CONFIG_STM32_MII_MCO2=n diff --git a/nuttx/configs/stm3240g-eval/nsh2/defconfig b/nuttx/configs/stm3240g-eval/nsh2/defconfig index 00d9dac0a..dfb837e8a 100644 --- a/nuttx/configs/stm3240g-eval/nsh2/defconfig +++ b/nuttx/configs/stm3240g-eval/nsh2/defconfig @@ -204,7 +204,7 @@ CONFIG_CAN2_BAUD=700000 # # STM32F40xxx Ethernet device driver settings # -CONFIG_STM32_PHYADDR=0x01 +CONFIG_STM32_PHYADDR=1 CONFIG_STM32_MII=y CONFIG_STM32_MII_MCO1=y CONFIG_STM32_MII_MCO2=n diff --git a/nuttx/configs/stm3240g-eval/nxconsole/defconfig b/nuttx/configs/stm3240g-eval/nxconsole/defconfig index 172d17b6f..417201f3e 100644 --- a/nuttx/configs/stm3240g-eval/nxconsole/defconfig +++ b/nuttx/configs/stm3240g-eval/nxconsole/defconfig @@ -203,7 +203,7 @@ CONFIG_CAN2_BAUD=700000 # # STM32F40xxx Ethernet device driver settings # -CONFIG_STM32_PHYADDR=0x01 +CONFIG_STM32_PHYADDR=1 CONFIG_STM32_MII=y CONFIG_STM32_MII_MCO1=y CONFIG_STM32_MII_MCO2=n diff --git a/nuttx/configs/stm3240g-eval/nxwm/defconfig b/nuttx/configs/stm3240g-eval/nxwm/defconfig index 07bc408dc..88d3ecb8d 100644 --- a/nuttx/configs/stm3240g-eval/nxwm/defconfig +++ b/nuttx/configs/stm3240g-eval/nxwm/defconfig @@ -203,7 +203,7 @@ CONFIG_CAN2_BAUD=700000 # # STM32F40xxx Ethernet device driver settings # -CONFIG_STM32_PHYADDR=0x01 +CONFIG_STM32_PHYADDR=1 CONFIG_STM32_MII=y CONFIG_STM32_MII_MCO1=y CONFIG_STM32_MII_MCO2=n diff --git a/nuttx/configs/stm3240g-eval/ostest/defconfig b/nuttx/configs/stm3240g-eval/ostest/defconfig index 1f2304730..2b95735bb 100644 --- a/nuttx/configs/stm3240g-eval/ostest/defconfig +++ b/nuttx/configs/stm3240g-eval/ostest/defconfig @@ -203,7 +203,7 @@ CONFIG_CAN2_BAUD=700000 # # STM32F40xxx Ethernet device driver settings # -CONFIG_STM32_PHYADDR=0x01 +CONFIG_STM32_PHYADDR=1 CONFIG_STM32_MII=y CONFIG_STM32_MII_MCO1=y CONFIG_STM32_MII_MCO2=n diff --git a/nuttx/configs/stm3240g-eval/telnetd/defconfig b/nuttx/configs/stm3240g-eval/telnetd/defconfig index 44a0f27ba..9dc5bfc28 100644 --- a/nuttx/configs/stm3240g-eval/telnetd/defconfig +++ b/nuttx/configs/stm3240g-eval/telnetd/defconfig @@ -203,7 +203,7 @@ CONFIG_CAN2_BAUD=700000 # # STM32F40xxx Ethernet device driver settings # -CONFIG_STM32_PHYADDR=0x01 +CONFIG_STM32_PHYADDR=1 CONFIG_STM32_MII=y CONFIG_STM32_MII_MCO1=y CONFIG_STM32_MII_MCO2=n diff --git a/nuttx/configs/stm3240g-eval/webserver/defconfig b/nuttx/configs/stm3240g-eval/webserver/defconfig index 7bd8e52ce..8f3ea36dc 100644 --- a/nuttx/configs/stm3240g-eval/webserver/defconfig +++ b/nuttx/configs/stm3240g-eval/webserver/defconfig @@ -203,7 +203,7 @@ CONFIG_CAN2_BAUD=700000 # # STM32F40xxx Ethernet device driver settings # -CONFIG_STM32_PHYADDR=0x01 +CONFIG_STM32_PHYADDR=1 CONFIG_STM32_MII=y CONFIG_STM32_MII_MCO1=y CONFIG_STM32_MII_MCO2=n diff --git a/nuttx/configs/stm32f4discovery/nsh/defconfig b/nuttx/configs/stm32f4discovery/nsh/defconfig index 0a07e8489..12848ddee 100644 --- a/nuttx/configs/stm32f4discovery/nsh/defconfig +++ b/nuttx/configs/stm32f4discovery/nsh/defconfig @@ -197,7 +197,7 @@ CONFIG_CAN2_BAUD=700000 # # STM32F40xxx Ethernet device driver settings # -CONFIG_STM32_PHYADDR=0x01 +CONFIG_STM32_PHYADDR=1 CONFIG_STM32_MII=y CONFIG_STM32_MII_MCO1=y CONFIG_STM32_MII_MCO2=n diff --git a/nuttx/configs/stm32f4discovery/nxlines/defconfig b/nuttx/configs/stm32f4discovery/nxlines/defconfig index 52705977a..f99af0233 100644 --- a/nuttx/configs/stm32f4discovery/nxlines/defconfig +++ b/nuttx/configs/stm32f4discovery/nxlines/defconfig @@ -197,7 +197,7 @@ CONFIG_CAN2_BAUD=700000 # # STM32F40xxx Ethernet device driver settings # -CONFIG_STM32_PHYADDR=0x01 +CONFIG_STM32_PHYADDR=1 CONFIG_STM32_MII=y CONFIG_STM32_MII_MCO1=y CONFIG_STM32_MII_MCO2=n diff --git a/nuttx/configs/stm32f4discovery/ostest/defconfig b/nuttx/configs/stm32f4discovery/ostest/defconfig index 5c120c614..8657d7edf 100644 --- a/nuttx/configs/stm32f4discovery/ostest/defconfig +++ b/nuttx/configs/stm32f4discovery/ostest/defconfig @@ -192,7 +192,7 @@ CONFIG_CAN2_BAUD=700000 # # STM32F40xxx Ethernet device driver settings # -CONFIG_STM32_PHYADDR=0x01 +CONFIG_STM32_PHYADDR=1 CONFIG_STM32_MII=y CONFIG_STM32_MII_MCO1=y CONFIG_STM32_MII_MCO2=n diff --git a/nuttx/configs/stm32f4discovery/pm/defconfig b/nuttx/configs/stm32f4discovery/pm/defconfig index 592ce5701..4608c16c6 100644 --- a/nuttx/configs/stm32f4discovery/pm/defconfig +++ b/nuttx/configs/stm32f4discovery/pm/defconfig @@ -198,7 +198,7 @@ CONFIG_CAN2_BAUD=700000 # # STM32F40xxx Ethernet device driver settings # -CONFIG_STM32_PHYADDR=0x01 +CONFIG_STM32_PHYADDR=1 CONFIG_STM32_MII=y CONFIG_STM32_MII_MCO1=y CONFIG_STM32_MII_MCO2=n diff --git a/nuttx/include/nuttx/net/uip/uipopt.h b/nuttx/include/nuttx/net/uip/uipopt.h index 4eff56fe8..9797e0482 100644 --- a/nuttx/include/nuttx/net/uip/uipopt.h +++ b/nuttx/include/nuttx/net/uip/uipopt.h @@ -296,7 +296,23 @@ /* The size of the TCP read buffer size */ #ifndef CONFIG_NET_TCP_READAHEAD_BUFSIZE -# define CONFIG_NET_TCP_READAHEAD_BUFSIZE UIP_TCP_MSS +# if CONFIG_NET_NTCP_READAHEAD_BUFFERS < 1 +# define CONFIG_NET_TCP_READAHEAD_BUFSIZE 0 +# else +# define CONFIG_NET_TCP_READAHEAD_BUFSIZE UIP_TCP_MSS +# endif +#endif + +/* Delay after receive to catch a following packet. No delay should be + * required if TCP/IP read-ahead buffering is enabled. + */ + +#ifndef CONFIG_NET_TCP_RECVDELAY +# if CONFIG_NET_NTCP_READAHEAD_BUFFERS > 0 +# define CONFIG_NET_TCP_RECVDELAY 0 +# else +# define CONFIG_NET_TCP_RECVDELAY 5 +# endif #endif /**************************************************************************** diff --git a/nuttx/net/Kconfig b/nuttx/net/Kconfig index b6e10a2e0..3d39dc1d7 100644 --- a/nuttx/net/Kconfig +++ b/nuttx/net/Kconfig @@ -112,16 +112,43 @@ config NET_MAX_LISTENPORTS Maximum number of listening TCP/IP ports (all tasks). Default: 20 config NET_TCP_READAHEAD_BUFSIZE - bool "TCP/IP read-ahead buffer size" + int "TCP/IP read-ahead buffer size" default 562 ---help--- - Size of TCP/IP read-ahead buffers + Read-ahead buffers allows buffering of TCP/IP packets when there is no + receive in place to catch the TCP packet. In that case, the packet + will be retained in the NuttX read-ahead buffers. + + This setting specifies the size of one TCP/IP read-ahead buffer. + This should best be a equal to the maximum packet size (NET_BUFSIZE). config NET_NTCP_READAHEAD_BUFFERS int "Number of TCP/IP read-ahead buffers" default 8 ---help--- - Number of TCP/IP read-ahead buffers (may be zero) + Read-ahead buffers allows buffering of TCP/IP packets when there is no + receive in place to catch the TCP packet. In that case, the packet + will be retained in the NuttX read-ahead buffers. + + This setting specifies the number of TCP/IP read-ahead buffers This + value can be set to zero to disable all TCP/IP read-ahead buffering. + You might want to disable TCP/IP read-ahead buffering on a highly + memory constained system that does not have any TCP/IP packet rate + issues. + +config NET_TCP_RECVDELAY + int "TCP Rx delay" + default 0 + ---help--- + If NET_NTCP_READAHEAD_BUFFERS is zero, then there will be no buffering + of TCP/IP packets: Any TCP/IP packet received will be ACKed, but its contents + will be dropped in the bit-bucket. + + One low-performance option is delay for a short period of time after a + TCP/IP packet is received to see if another comes right behind it. Then + the packet data from both can be combined. This option only makes since + if performance is not an issue and you need to handle short bursts of + small, back-to-back packets. The delay is in units of deciseconds. config NET_TCPBACKLOG bool "TCP/IP backlog support" diff --git a/nuttx/net/recvfrom.c b/nuttx/net/recvfrom.c index 741cd4c72..6b9eb9a90 100644 --- a/nuttx/net/recvfrom.c +++ b/nuttx/net/recvfrom.c @@ -59,8 +59,6 @@ * Definitions ****************************************************************************/ -#define TCP_TIMEO 10 /* Deciseconds after data received before recv() returns */ - #define UDPBUF ((struct uip_udpip_hdr *)&dev->d_buf[UIP_LLH_LEN]) #define TCPBUF ((struct uip_tcpip_hdr *)&dev->d_buf[UIP_LLH_LEN]) @@ -354,31 +352,39 @@ static int recvfrom_timeout(struct recvfrom_s *pstate) FAR struct socket *psock = 0; socktimeo_t timeo = 0; - /* If this is a TCP socket that has already received some data, - * than we will always use a short timeout. + /* Check for a timeout configured via setsockopts(SO_RCVTIMEO). If none... + * we well let the read hang forever (except for the special case below). */ - if (pstate->rf_recvlen > 0) + /* Get the socket reference from the private data */ + + psock = pstate->rf_sock; + if (psock) { - /* Use the short timeout */ + /* Recover the timeout value (zero if no timeout) */ - timeo = TCP_TIMEO; + timeo = psock->s_rcvtimeo; } - /* No.. check for a timeout configured via setsockopts(SO_RCVTIMEO). - * If none... we well let the read hang forever. + /* Use a fixed, configurable delay under the following circumstances: + * + * 1) This delay function has been enabled with CONFIG_NET_TCP_RECVDELAY > 0 + * 2) Some data has already been received from the socket. Since this can + * only be true for a TCP/IP socket, this logic applies only to TCP/IP + * sockets, and either + * 3) There is no configured receive timeout, or + * 4) The configured receive timeout is greater than than the delay */ - else +#if CONFIG_NET_TCP_RECVDELAY > 0 + if ((timeo == 0 || timeo > CONFIG_NET_TCP_RECVDELAY) && + pstate->rf_recvlen > 0) { - /* Get the socket reference from the private data */ + /* Use the configured timeout */ - psock = pstate->rf_sock; - if (psock) - { - timeo = psock->s_rcvtimeo; - } + timeo = CONFIG_NET_TCP_RECVDELAY; } +#endif /* Is there an effective timeout? */ @@ -389,7 +395,7 @@ static int recvfrom_timeout(struct recvfrom_s *pstate) return net_timeo(pstate->rf_starttime, timeo); } - /* No timeout */ + /* No timeout -- hang forever waiting for data. */ return FALSE; } @@ -489,9 +495,28 @@ static uint16_t recvfrom_tcpinterrupt(struct uip_driver_s *dev, void *conn, flags = (flags & ~UIP_NEWDATA) | UIP_SNDACK; - /* If the user buffer has been filled, then we are finished. */ + /* Check for transfer complete. We will consider the transfer + * complete in own of two different ways, depending on the setting + * of CONFIG_NET_TCP_RECVDELAY. + * + * 1) If CONFIG_NET_TCP_RECVDELAY == 0 then we will consider the + * TCP/IP transfer complete as soon as any data has been received. + * This is safe because if any additional data is received, it + * will be retained inthe TCP/IP read-ahead buffer until the + * next receive is performed. + * 2) CONFIG_NET_TCP_RECVDELAY > 0 may be set to wait a little + * bit to determine if more data will be received. You might + * do this if read-ahead buffereing is disabled and we want to + * minimize the loss of back-to-back packets. In this case, + * the transfer is complete when either a) the entire user buffer + * is full or 2) when the receive timeout occurs (below). + */ +#if CONFIG_NET_TCP_RECVDELAY > 0 if (pstate->rf_buflen == 0) +#else + if (pstate->rf_recvlen > 0) +#endif { nllvdbg("TCP resume\n"); |