From 687245d6898eac03302b3f023090cb54c9e284c9 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 14 Jan 2014 18:19:43 -0600 Subject: If write buffering is enabled, then it is necessary to release the write buffer resources (callback structure) when the socket is closed --- apps/netutils/telnetd/telnetd_driver.c | 14 +++++++++++--- nuttx/ChangeLog | 9 ++++++--- nuttx/net/net_close.c | 16 ++++++++++++++-- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/apps/netutils/telnetd/telnetd_driver.c b/apps/netutils/telnetd/telnetd_driver.c index 13d1e00e4..7f87b8c70 100644 --- a/apps/netutils/telnetd/telnetd_driver.c +++ b/apps/netutils/telnetd/telnetd_driver.c @@ -215,7 +215,7 @@ static void telnetd_getchar(FAR struct telnetd_dev_s *priv, uint8_t ch, * Name: telnetd_receive * * Description: - * Process a received telenet buffer + * Process a received Telnet buffer * ****************************************************************************/ @@ -500,12 +500,20 @@ static int telnetd_close(FAR struct file *filep) } else { - /* Unregister the character driver */ + /* Un-register the character driver */ ret = unregister_driver(devpath); if (ret < 0) { - nlldbg("Failed to unregister the driver %s: %d\n", devpath, ret); + /* NOTE: a return value of -EBUSY is not an error, it simply + * means that the Telnet driver is busy now and cannot be + * registered now because there are other sessions using the + * connection. The driver will be properly unregistered when + * the final session terminates. + */ + + nlldbg("Failed to unregister the driver %s: %d\n", + devpath, ret); } free(devpath); diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 68640e5a3..13d4bb777 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -6436,6 +6436,9 @@ in the PX4 GIT repository. * fs/fat/fs_fat32.c: A correction to FAT cluster allocation from Tridge via Lorenz Meier (2014-1-14). - * net/net_clone.c: Need to clone fields for TCP write buffering - as well (2014-1-14). - + * net/net_clone.c: If CONFIG_NET_TCP_WRITE_BUFFERS is selected, + then the socket-related write buffering information must copied + with the other cloned socket data (2014-1-14). + * net/net_close.c: If CONFIG_NET_TCP_WRITE_BUFFERS is selected, + then it is necessary to free the write buffere callback structure + when the socket is closed (2014-1-14). diff --git a/nuttx/net/net_close.c b/nuttx/net/net_close.c index 0d8a0cac1..7bec9237c 100644 --- a/nuttx/net/net_close.c +++ b/nuttx/net/net_close.c @@ -285,9 +285,21 @@ static inline int netclose_disconnect(FAR struct socket *psock) flags = uip_lock(); conn = (struct uip_conn*)psock->s_conn; - /* There shouldn't be any callbacks registered */ + /* If we have a semi-permanent write buffer callback in place, then + * release it now. + */ + +#ifdef CONFIG_NET_TCP_WRITE_BUFFERS + if (psock->s_sndcb) + { + uip_tcpcallbackfree(conn, psock->s_sndcb); + psock->s_sndcb = NULL; + } +#endif + + /* There shouldn't be any callbacks registered. */ - DEBUGASSERT(conn->list == NULL); + DEBUGASSERT(conn && conn->list == NULL); /* Check for the case where the host beat us and disconnected first */ -- cgit v1.2.3