From 3fce144aeb739805757adc3b098a02973bdf1905 Mon Sep 17 00:00:00 2001 From: "chao.an" Date: Mon, 7 Feb 2022 14:36:54 +0800 Subject: [PATCH] net/inet: move recv/send timeout into socket_conn_s Signed-off-by: chao.an --- include/nuttx/net/net.h | 4 ++-- net/icmp/icmp_recvmsg.c | 2 +- net/icmp/icmp_sendmsg.c | 3 ++- net/icmpv6/icmpv6_recvmsg.c | 2 +- net/icmpv6/icmpv6_sendmsg.c | 3 ++- net/rpmsg/rpmsg_sockif.c | 8 ++++---- net/sixlowpan/sixlowpan_tcpsend.c | 2 +- net/sixlowpan/sixlowpan_udpsend.c | 2 +- net/socket/getsockopt.c | 4 ++-- net/socket/net_dup2.c | 2 -- net/socket/setsockopt.c | 4 ++-- net/tcp/tcp_recvfrom.c | 3 ++- net/tcp/tcp_send_unbuffered.c | 2 +- net/tcp/tcp_sendfile.c | 4 ++-- net/udp/udp_recvfrom.c | 3 ++- net/udp/udp_sendto_unbuffered.c | 3 ++- net/usrsock/usrsock_accept.c | 2 +- net/usrsock/usrsock_recvmsg.c | 2 +- net/usrsock/usrsock_sendmsg.c | 2 +- 19 files changed, 30 insertions(+), 27 deletions(-) diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h index a88ee72e74..d8092d20b8 100644 --- a/include/nuttx/net/net.h +++ b/include/nuttx/net/net.h @@ -238,6 +238,8 @@ struct socket_conn_s #ifdef CONFIG_NET_SOCKOPTS int16_t s_error; /* Last error that occurred on this socket */ 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) */ #endif /* Connection-specific content may follow */ @@ -258,8 +260,6 @@ struct socket /* Socket options */ #ifdef CONFIG_NET_SOCKOPTS - 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 diff --git a/net/icmp/icmp_recvmsg.c b/net/icmp/icmp_recvmsg.c index 3f4649667f..ee0e5b9837 100644 --- a/net/icmp/icmp_recvmsg.c +++ b/net/icmp/icmp_recvmsg.c @@ -450,7 +450,7 @@ ssize_t icmp_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg, */ ret = net_timedwait(&state.recv_sem, - _SO_TIMEOUT(psock->s_rcvtimeo)); + _SO_TIMEOUT(conn->sconn.s_rcvtimeo)); if (ret < 0) { state.recv_result = ret; diff --git a/net/icmp/icmp_sendmsg.c b/net/icmp/icmp_sendmsg.c index 4fad4c95e7..17097526ff 100644 --- a/net/icmp/icmp_sendmsg.c +++ b/net/icmp/icmp_sendmsg.c @@ -418,7 +418,8 @@ ssize_t icmp_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg, * net_timedwait will also terminate if a signal is received. */ - ret = net_timedwait(&state.snd_sem, _SO_TIMEOUT(psock->s_sndtimeo)); + ret = net_timedwait(&state.snd_sem, + _SO_TIMEOUT(conn->sconn.s_sndtimeo)); if (ret < 0) { if (ret == -ETIMEDOUT) diff --git a/net/icmpv6/icmpv6_recvmsg.c b/net/icmpv6/icmpv6_recvmsg.c index addcdb29bc..86fbd15fe5 100644 --- a/net/icmpv6/icmpv6_recvmsg.c +++ b/net/icmpv6/icmpv6_recvmsg.c @@ -459,7 +459,7 @@ ssize_t icmpv6_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg, */ ret = net_timedwait(&state.recv_sem, - _SO_TIMEOUT(psock->s_rcvtimeo)); + _SO_TIMEOUT(conn->sconn.s_rcvtimeo)); if (ret < 0) { state.recv_result = ret; diff --git a/net/icmpv6/icmpv6_sendmsg.c b/net/icmpv6/icmpv6_sendmsg.c index 57b2efd59f..0471fa5e03 100644 --- a/net/icmpv6/icmpv6_sendmsg.c +++ b/net/icmpv6/icmpv6_sendmsg.c @@ -409,7 +409,8 @@ ssize_t icmpv6_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg, * net_timedwait will also terminate if a signal is received. */ - ret = net_timedwait(&state.snd_sem, _SO_TIMEOUT(psock->s_sndtimeo)); + ret = net_timedwait(&state.snd_sem, + _SO_TIMEOUT(conn->sconn.s_sndtimeo)); if (ret < 0) { if (ret == -ETIMEDOUT) diff --git a/net/rpmsg/rpmsg_sockif.c b/net/rpmsg/rpmsg_sockif.c index 86f9bcba49..542a26c588 100644 --- a/net/rpmsg/rpmsg_sockif.c +++ b/net/rpmsg/rpmsg_sockif.c @@ -693,7 +693,7 @@ static int rpmsg_socket_connect_internal(FAR struct socket *psock) } ret = net_timedwait(&conn->sendsem, - _SO_TIMEOUT(psock->s_rcvtimeo)); + _SO_TIMEOUT(conn->sconn.s_rcvtimeo)); if (ret < 0) { @@ -953,7 +953,7 @@ static ssize_t rpmsg_socket_send_continuous(FAR struct socket *psock, if (!nonblock) { ret = net_timedwait(&conn->sendsem, - _SO_TIMEOUT(psock->s_sndtimeo)); + _SO_TIMEOUT(conn->sconn.s_sndtimeo)); if (!conn->ept.rdev) { ret = -ECONNRESET; @@ -1051,7 +1051,7 @@ static ssize_t rpmsg_socket_send_single(FAR struct socket *psock, if (!nonblock) { ret = net_timedwait(&conn->sendsem, - _SO_TIMEOUT(psock->s_sndtimeo)); + _SO_TIMEOUT(conn->sconn.s_sndtimeo)); if (!conn->ept.rdev) { ret = -ECONNRESET; @@ -1233,7 +1233,7 @@ static ssize_t rpmsg_socket_recvmsg(FAR struct socket *psock, rpmsg_socket_unlock(&conn->recvlock); ret = net_timedwait(&conn->recvsem, - _SO_TIMEOUT(psock->s_rcvtimeo)); + _SO_TIMEOUT(conn->sconn.s_rcvtimeo)); if (!conn->ept.rdev) { ret = -ECONNRESET; diff --git a/net/sixlowpan/sixlowpan_tcpsend.c b/net/sixlowpan/sixlowpan_tcpsend.c index b958908e8d..cd2d3d9f64 100644 --- a/net/sixlowpan/sixlowpan_tcpsend.c +++ b/net/sixlowpan/sixlowpan_tcpsend.c @@ -799,7 +799,7 @@ ssize_t psock_6lowpan_tcp_send(FAR struct socket *psock, FAR const void *buf, */ ret = sixlowpan_send_packet(psock, dev, conn, buf, buflen, &destmac, - _SO_TIMEOUT(psock->s_sndtimeo)); + _SO_TIMEOUT(conn->sconn.s_sndtimeo)); if (ret < 0) { nerr("ERROR: sixlowpan_send_packet() failed: %d\n", ret); diff --git a/net/sixlowpan/sixlowpan_udpsend.c b/net/sixlowpan/sixlowpan_udpsend.c index 7d11c04a72..fd08b7b09b 100644 --- a/net/sixlowpan/sixlowpan_udpsend.c +++ b/net/sixlowpan/sixlowpan_udpsend.c @@ -297,7 +297,7 @@ ssize_t psock_6lowpan_udp_sendto(FAR struct socket *psock, &conn->sconn.list_tail, (FAR const struct ipv6_hdr_s *)&ipv6udp, buf, buflen, &destmac, - _SO_TIMEOUT(psock->s_sndtimeo)); + _SO_TIMEOUT(conn->sconn.s_sndtimeo)); if (ret < 0) { nerr("ERROR: sixlowpan_send() failed: %d\n", ret); diff --git a/net/socket/getsockopt.c b/net/socket/getsockopt.c index 054e946d75..ec610f466b 100644 --- a/net/socket/getsockopt.c +++ b/net/socket/getsockopt.c @@ -115,11 +115,11 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option, if (option == SO_RCVTIMEO) { - timeo = psock->s_rcvtimeo; + timeo = conn->s_rcvtimeo; } else { - timeo = psock->s_sndtimeo; + timeo = conn->s_sndtimeo; } /* Then return the timeout value to the caller */ diff --git a/net/socket/net_dup2.c b/net/socket/net_dup2.c index 3e7f705d8e..b29815de7b 100644 --- a/net/socket/net_dup2.c +++ b/net/socket/net_dup2.c @@ -78,8 +78,6 @@ int psock_dup2(FAR struct socket *psock1, FAR struct socket *psock2) 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 - psock2->s_rcvtimeo = psock1->s_rcvtimeo; /* Receive timeout value (in deciseconds) */ - psock2->s_sndtimeo = psock1->s_sndtimeo; /* Send timeout value (in deciseconds) */ #ifdef CONFIG_NET_SOLINGER psock2->s_linger = psock1->s_linger; /* Linger timeout value (in deciseconds) */ #endif diff --git a/net/socket/setsockopt.c b/net/socket/setsockopt.c index 63ecccb00a..670f776617 100644 --- a/net/socket/setsockopt.c +++ b/net/socket/setsockopt.c @@ -116,11 +116,11 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option, if (option == SO_RCVTIMEO) { - psock->s_rcvtimeo = timeo; + conn->s_rcvtimeo = timeo; } else { - psock->s_sndtimeo = timeo; + conn->s_sndtimeo = timeo; } /* Set/clear the corresponding enable/disable bit */ diff --git a/net/tcp/tcp_recvfrom.c b/net/tcp/tcp_recvfrom.c index ccc148b991..cc45326e83 100644 --- a/net/tcp/tcp_recvfrom.c +++ b/net/tcp/tcp_recvfrom.c @@ -741,7 +741,8 @@ ssize_t psock_tcp_recvfrom(FAR struct socket *psock, FAR void *buf, * received. */ - ret = net_timedwait(&state.ir_sem, _SO_TIMEOUT(psock->s_rcvtimeo)); + ret = net_timedwait(&state.ir_sem, + _SO_TIMEOUT(conn->sconn.s_rcvtimeo)); if (ret == -ETIMEDOUT) { ret = -EAGAIN; diff --git a/net/tcp/tcp_send_unbuffered.c b/net/tcp/tcp_send_unbuffered.c index b123d5fcfc..b819b708c9 100644 --- a/net/tcp/tcp_send_unbuffered.c +++ b/net/tcp/tcp_send_unbuffered.c @@ -666,7 +666,7 @@ ssize_t psock_tcp_send(FAR struct socket *psock, uint32_t acked = state.snd_acked; ret = net_timedwait(&state.snd_sem, - _SO_TIMEOUT(psock->s_sndtimeo)); + _SO_TIMEOUT(conn->sconn.s_sndtimeo)); if (ret != -ETIMEDOUT || acked == state.snd_acked) { break; /* Timeout without any progress */ diff --git a/net/tcp/tcp_sendfile.c b/net/tcp/tcp_sendfile.c index 4a4463f68e..fb949c4e3d 100644 --- a/net/tcp/tcp_sendfile.c +++ b/net/tcp/tcp_sendfile.c @@ -568,8 +568,8 @@ ssize_t tcp_sendfile(FAR struct socket *psock, FAR struct file *infile, { uint32_t acked = state.snd_acked; - ret = net_timedwait_uninterruptible(&state.snd_sem, - _SO_TIMEOUT(psock->s_sndtimeo)); + ret = net_timedwait_uninterruptible( + &state.snd_sem, _SO_TIMEOUT(conn->sconn.s_sndtimeo)); if (ret != -ETIMEDOUT || acked == state.snd_acked) { break; /* Successful completion or timeout without any progress */ diff --git a/net/udp/udp_recvfrom.c b/net/udp/udp_recvfrom.c index a17d495d27..bed664189a 100644 --- a/net/udp/udp_recvfrom.c +++ b/net/udp/udp_recvfrom.c @@ -674,7 +674,8 @@ ssize_t psock_udp_recvfrom(FAR struct socket *psock, FAR void *buf, * received. */ - ret = net_timedwait(&state.ir_sem, _SO_TIMEOUT(psock->s_rcvtimeo)); + ret = net_timedwait(&state.ir_sem, + _SO_TIMEOUT(conn->sconn.s_rcvtimeo)); if (ret == -ETIMEDOUT) { ret = -EAGAIN; diff --git a/net/udp/udp_sendto_unbuffered.c b/net/udp/udp_sendto_unbuffered.c index 5760406273..871b5bc2bd 100644 --- a/net/udp/udp_sendto_unbuffered.c +++ b/net/udp/udp_sendto_unbuffered.c @@ -473,7 +473,8 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf, * is received. */ - ret = net_timedwait(&state.st_sem, _SO_TIMEOUT(psock->s_sndtimeo)); + ret = net_timedwait(&state.st_sem, + _SO_TIMEOUT(conn->sconn.s_sndtimeo)); if (ret >= 0) { /* The result of the sendto operation is the number of bytes diff --git a/net/usrsock/usrsock_accept.c b/net/usrsock/usrsock_accept.c index cfaa61fcca..d5391d9447 100644 --- a/net/usrsock/usrsock_accept.c +++ b/net/usrsock/usrsock_accept.c @@ -327,7 +327,7 @@ int usrsock_accept(FAR struct socket *psock, FAR struct sockaddr *addr, /* Wait for receive-avail (or abort, or timeout, or signal). */ ret = net_timedwait(&state.reqstate.recvsem, - _SO_TIMEOUT(psock->s_rcvtimeo)); + _SO_TIMEOUT(conn->sconn.s_rcvtimeo)); if (ret < 0) { if (ret == -ETIMEDOUT) diff --git a/net/usrsock/usrsock_recvmsg.c b/net/usrsock/usrsock_recvmsg.c index c6e08ced5d..e37874c9ec 100644 --- a/net/usrsock/usrsock_recvmsg.c +++ b/net/usrsock/usrsock_recvmsg.c @@ -326,7 +326,7 @@ ssize_t usrsock_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg, /* Wait for receive-avail (or abort, or timeout, or signal). */ ret = net_timedwait(&state.reqstate.recvsem, - _SO_TIMEOUT(psock->s_rcvtimeo)); + _SO_TIMEOUT(conn->sconn.s_rcvtimeo)); if (ret < 0) { if (ret == -ETIMEDOUT) diff --git a/net/usrsock/usrsock_sendmsg.c b/net/usrsock/usrsock_sendmsg.c index 695dc6465e..fe5c612df7 100644 --- a/net/usrsock/usrsock_sendmsg.c +++ b/net/usrsock/usrsock_sendmsg.c @@ -307,7 +307,7 @@ ssize_t usrsock_sendmsg(FAR struct socket *psock, /* Wait for send-ready (or abort, or timeout, or signal). */ ret = net_timedwait(&state.recvsem, - _SO_TIMEOUT(psock->s_sndtimeo)); + _SO_TIMEOUT(conn->sconn.s_sndtimeo)); if (ret < 0) { if (ret == -ETIMEDOUT)