net/inet: move recv/send timeout into socket_conn_s

Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
chao.an 2022-02-07 14:36:54 +08:00 committed by Alan Carvalho de Assis
parent cc6add58dc
commit 3fce144aeb
19 changed files with 30 additions and 27 deletions

View File

@ -238,6 +238,8 @@ struct socket_conn_s
#ifdef CONFIG_NET_SOCKOPTS #ifdef CONFIG_NET_SOCKOPTS
int16_t s_error; /* Last error that occurred on this socket */ int16_t s_error; /* Last error that occurred on this socket */
sockopt_t s_options; /* Selected socket options */ 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 #endif
/* Connection-specific content may follow */ /* Connection-specific content may follow */
@ -258,8 +260,6 @@ struct socket
/* Socket options */ /* Socket options */
#ifdef CONFIG_NET_SOCKOPTS #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 #ifdef CONFIG_NET_SOLINGER
socktimeo_t s_linger; /* Linger timeout value (in deciseconds) */ socktimeo_t s_linger; /* Linger timeout value (in deciseconds) */
#endif #endif

View File

@ -450,7 +450,7 @@ ssize_t icmp_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
*/ */
ret = net_timedwait(&state.recv_sem, ret = net_timedwait(&state.recv_sem,
_SO_TIMEOUT(psock->s_rcvtimeo)); _SO_TIMEOUT(conn->sconn.s_rcvtimeo));
if (ret < 0) if (ret < 0)
{ {
state.recv_result = ret; state.recv_result = ret;

View File

@ -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. * 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 < 0)
{ {
if (ret == -ETIMEDOUT) if (ret == -ETIMEDOUT)

View File

@ -459,7 +459,7 @@ ssize_t icmpv6_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
*/ */
ret = net_timedwait(&state.recv_sem, ret = net_timedwait(&state.recv_sem,
_SO_TIMEOUT(psock->s_rcvtimeo)); _SO_TIMEOUT(conn->sconn.s_rcvtimeo));
if (ret < 0) if (ret < 0)
{ {
state.recv_result = ret; state.recv_result = ret;

View File

@ -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. * 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 < 0)
{ {
if (ret == -ETIMEDOUT) if (ret == -ETIMEDOUT)

View File

@ -693,7 +693,7 @@ static int rpmsg_socket_connect_internal(FAR struct socket *psock)
} }
ret = net_timedwait(&conn->sendsem, ret = net_timedwait(&conn->sendsem,
_SO_TIMEOUT(psock->s_rcvtimeo)); _SO_TIMEOUT(conn->sconn.s_rcvtimeo));
if (ret < 0) if (ret < 0)
{ {
@ -953,7 +953,7 @@ static ssize_t rpmsg_socket_send_continuous(FAR struct socket *psock,
if (!nonblock) if (!nonblock)
{ {
ret = net_timedwait(&conn->sendsem, ret = net_timedwait(&conn->sendsem,
_SO_TIMEOUT(psock->s_sndtimeo)); _SO_TIMEOUT(conn->sconn.s_sndtimeo));
if (!conn->ept.rdev) if (!conn->ept.rdev)
{ {
ret = -ECONNRESET; ret = -ECONNRESET;
@ -1051,7 +1051,7 @@ static ssize_t rpmsg_socket_send_single(FAR struct socket *psock,
if (!nonblock) if (!nonblock)
{ {
ret = net_timedwait(&conn->sendsem, ret = net_timedwait(&conn->sendsem,
_SO_TIMEOUT(psock->s_sndtimeo)); _SO_TIMEOUT(conn->sconn.s_sndtimeo));
if (!conn->ept.rdev) if (!conn->ept.rdev)
{ {
ret = -ECONNRESET; ret = -ECONNRESET;
@ -1233,7 +1233,7 @@ static ssize_t rpmsg_socket_recvmsg(FAR struct socket *psock,
rpmsg_socket_unlock(&conn->recvlock); rpmsg_socket_unlock(&conn->recvlock);
ret = net_timedwait(&conn->recvsem, ret = net_timedwait(&conn->recvsem,
_SO_TIMEOUT(psock->s_rcvtimeo)); _SO_TIMEOUT(conn->sconn.s_rcvtimeo));
if (!conn->ept.rdev) if (!conn->ept.rdev)
{ {
ret = -ECONNRESET; ret = -ECONNRESET;

View File

@ -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, ret = sixlowpan_send_packet(psock, dev, conn, buf, buflen, &destmac,
_SO_TIMEOUT(psock->s_sndtimeo)); _SO_TIMEOUT(conn->sconn.s_sndtimeo));
if (ret < 0) if (ret < 0)
{ {
nerr("ERROR: sixlowpan_send_packet() failed: %d\n", ret); nerr("ERROR: sixlowpan_send_packet() failed: %d\n", ret);

View File

@ -297,7 +297,7 @@ ssize_t psock_6lowpan_udp_sendto(FAR struct socket *psock,
&conn->sconn.list_tail, &conn->sconn.list_tail,
(FAR const struct ipv6_hdr_s *)&ipv6udp, (FAR const struct ipv6_hdr_s *)&ipv6udp,
buf, buflen, &destmac, buf, buflen, &destmac,
_SO_TIMEOUT(psock->s_sndtimeo)); _SO_TIMEOUT(conn->sconn.s_sndtimeo));
if (ret < 0) if (ret < 0)
{ {
nerr("ERROR: sixlowpan_send() failed: %d\n", ret); nerr("ERROR: sixlowpan_send() failed: %d\n", ret);

View File

@ -115,11 +115,11 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option,
if (option == SO_RCVTIMEO) if (option == SO_RCVTIMEO)
{ {
timeo = psock->s_rcvtimeo; timeo = conn->s_rcvtimeo;
} }
else else
{ {
timeo = psock->s_sndtimeo; timeo = conn->s_sndtimeo;
} }
/* Then return the timeout value to the caller */ /* Then return the timeout value to the caller */

View File

@ -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_type = psock1->s_type; /* Protocol type: Only SOCK_STREAM or SOCK_DGRAM */
psock2->s_sockif = psock1->s_sockif; /* Socket interface */ psock2->s_sockif = psock1->s_sockif; /* Socket interface */
#ifdef CONFIG_NET_SOCKOPTS #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 #ifdef CONFIG_NET_SOLINGER
psock2->s_linger = psock1->s_linger; /* Linger timeout value (in deciseconds) */ psock2->s_linger = psock1->s_linger; /* Linger timeout value (in deciseconds) */
#endif #endif

View File

@ -116,11 +116,11 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option,
if (option == SO_RCVTIMEO) if (option == SO_RCVTIMEO)
{ {
psock->s_rcvtimeo = timeo; conn->s_rcvtimeo = timeo;
} }
else else
{ {
psock->s_sndtimeo = timeo; conn->s_sndtimeo = timeo;
} }
/* Set/clear the corresponding enable/disable bit */ /* Set/clear the corresponding enable/disable bit */

View File

@ -741,7 +741,8 @@ ssize_t psock_tcp_recvfrom(FAR struct socket *psock, FAR void *buf,
* received. * 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) if (ret == -ETIMEDOUT)
{ {
ret = -EAGAIN; ret = -EAGAIN;

View File

@ -666,7 +666,7 @@ ssize_t psock_tcp_send(FAR struct socket *psock,
uint32_t acked = state.snd_acked; uint32_t acked = state.snd_acked;
ret = net_timedwait(&state.snd_sem, ret = net_timedwait(&state.snd_sem,
_SO_TIMEOUT(psock->s_sndtimeo)); _SO_TIMEOUT(conn->sconn.s_sndtimeo));
if (ret != -ETIMEDOUT || acked == state.snd_acked) if (ret != -ETIMEDOUT || acked == state.snd_acked)
{ {
break; /* Timeout without any progress */ break; /* Timeout without any progress */

View File

@ -568,8 +568,8 @@ ssize_t tcp_sendfile(FAR struct socket *psock, FAR struct file *infile,
{ {
uint32_t acked = state.snd_acked; uint32_t acked = state.snd_acked;
ret = net_timedwait_uninterruptible(&state.snd_sem, ret = net_timedwait_uninterruptible(
_SO_TIMEOUT(psock->s_sndtimeo)); &state.snd_sem, _SO_TIMEOUT(conn->sconn.s_sndtimeo));
if (ret != -ETIMEDOUT || acked == state.snd_acked) if (ret != -ETIMEDOUT || acked == state.snd_acked)
{ {
break; /* Successful completion or timeout without any progress */ break; /* Successful completion or timeout without any progress */

View File

@ -674,7 +674,8 @@ ssize_t psock_udp_recvfrom(FAR struct socket *psock, FAR void *buf,
* received. * 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) if (ret == -ETIMEDOUT)
{ {
ret = -EAGAIN; ret = -EAGAIN;

View File

@ -473,7 +473,8 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf,
* is received. * 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) if (ret >= 0)
{ {
/* The result of the sendto operation is the number of bytes /* The result of the sendto operation is the number of bytes

View File

@ -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). */ /* Wait for receive-avail (or abort, or timeout, or signal). */
ret = net_timedwait(&state.reqstate.recvsem, ret = net_timedwait(&state.reqstate.recvsem,
_SO_TIMEOUT(psock->s_rcvtimeo)); _SO_TIMEOUT(conn->sconn.s_rcvtimeo));
if (ret < 0) if (ret < 0)
{ {
if (ret == -ETIMEDOUT) if (ret == -ETIMEDOUT)

View File

@ -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). */ /* Wait for receive-avail (or abort, or timeout, or signal). */
ret = net_timedwait(&state.reqstate.recvsem, ret = net_timedwait(&state.reqstate.recvsem,
_SO_TIMEOUT(psock->s_rcvtimeo)); _SO_TIMEOUT(conn->sconn.s_rcvtimeo));
if (ret < 0) if (ret < 0)
{ {
if (ret == -ETIMEDOUT) if (ret == -ETIMEDOUT)

View File

@ -307,7 +307,7 @@ ssize_t usrsock_sendmsg(FAR struct socket *psock,
/* Wait for send-ready (or abort, or timeout, or signal). */ /* Wait for send-ready (or abort, or timeout, or signal). */
ret = net_timedwait(&state.recvsem, ret = net_timedwait(&state.recvsem,
_SO_TIMEOUT(psock->s_sndtimeo)); _SO_TIMEOUT(conn->sconn.s_sndtimeo));
if (ret < 0) if (ret < 0)
{ {
if (ret == -ETIMEDOUT) if (ret == -ETIMEDOUT)