diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h index d8092d20b84..3ea3459d70b 100644 --- a/include/nuttx/net/net.h +++ b/include/nuttx/net/net.h @@ -240,6 +240,9 @@ struct socket_conn_s sockopt_t s_options; /* Selected socket options */ socktimeo_t s_rcvtimeo; /* Receive timeout value (in deciseconds) */ socktimeo_t s_sndtimeo; /* Send timeout value (in deciseconds) */ +#ifdef CONFIG_NET_SOLINGER + socktimeo_t s_linger; /* Linger timeout value (in deciseconds) */ +#endif #endif /* Connection-specific content may follow */ @@ -260,9 +263,6 @@ struct socket /* Socket options */ #ifdef CONFIG_NET_SOCKOPTS -#ifdef CONFIG_NET_SOLINGER - socktimeo_t s_linger; /* Linger timeout value (in deciseconds) */ -#endif #ifdef CONFIG_NET_TIMESTAMP int32_t s_timestamp; /* Socket timestamp enabled/disabled */ #endif diff --git a/net/socket/net_dup2.c b/net/socket/net_dup2.c index b29815de7bd..9080f286929 100644 --- a/net/socket/net_dup2.c +++ b/net/socket/net_dup2.c @@ -77,11 +77,6 @@ int psock_dup2(FAR struct socket *psock1, FAR struct socket *psock2) psock2->s_domain = psock1->s_domain; /* IP domain: PF_INET, PF_INET6, or PF_PACKET */ psock2->s_type = psock1->s_type; /* Protocol type: Only SOCK_STREAM or SOCK_DGRAM */ psock2->s_sockif = psock1->s_sockif; /* Socket interface */ -#ifdef CONFIG_NET_SOCKOPTS -#ifdef CONFIG_NET_SOLINGER - psock2->s_linger = psock1->s_linger; /* Linger timeout value (in deciseconds) */ -#endif -#endif psock2->s_conn = psock1->s_conn; /* UDP or TCP connection structure */ /* Increment the reference count on the underlying connection structure diff --git a/net/socket/setsockopt.c b/net/socket/setsockopt.c index 670f776617e..50659ce526a 100644 --- a/net/socket/setsockopt.c +++ b/net/socket/setsockopt.c @@ -363,12 +363,12 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option, if (setting->l_onoff) { _SO_SETOPT(conn->s_options, option); - psock->s_linger = 10 * setting->l_linger; + conn->s_linger = 10 * setting->l_linger; } else { _SO_CLROPT(conn->s_options, option); - psock->s_linger = 0; + conn->s_linger = 0; } net_unlock(); diff --git a/net/tcp/tcp_close.c b/net/tcp/tcp_close.c index 69c03d81660..aff74a3275e 100644 --- a/net/tcp/tcp_close.c +++ b/net/tcp/tcp_close.c @@ -285,7 +285,7 @@ static inline int tcp_close_disconnect(FAR struct socket *psock) { /* Wait until for the buffered TX data to be sent. */ - ret = tcp_txdrain(psock, _SO_TIMEOUT(psock->s_linger)); + ret = tcp_txdrain(psock, _SO_TIMEOUT(conn->sconn.s_linger)); if (ret < 0) { /* tcp_txdrain may fail, but that won't stop us from closing diff --git a/net/udp/udp_close.c b/net/udp/udp_close.c index 123934ab339..f2b4ed7027e 100644 --- a/net/udp/udp_close.c +++ b/net/udp/udp_close.c @@ -89,7 +89,7 @@ int udp_close(FAR struct socket *psock) if (_SO_GETOPT(conn->sconn.s_options, SO_LINGER)) { - timeout = _SO_TIMEOUT(psock->s_linger); + timeout = _SO_TIMEOUT(conn->sconn.s_linger); } #endif