You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ma...@apache.org on 2021/07/06 23:41:02 UTC
[incubator-nuttx] branch master updated: usrsock/recv: guarantee
all data is received before close
This is an automated email from the ASF dual-hosted git repository.
masayuki pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new e506b2a usrsock/recv: guarantee all data is received before close
e506b2a is described below
commit e506b2a52cb8a617e1d3cdc0465bb90c4db61b67
Author: chao.an <an...@xiaomi.com>
AuthorDate: Thu Mar 18 22:08:44 2021 +0800
usrsock/recv: guarantee all data is received before close
adjust the close sequence to avoid data discard
Signed-off-by: chao.an <an...@xiaomi.com>
---
net/usrsock/usrsock_event.c | 19 +++++++++----------
net/usrsock/usrsock_recvmsg.c | 18 ++++++++++--------
2 files changed, 19 insertions(+), 18 deletions(-)
diff --git a/net/usrsock/usrsock_event.c b/net/usrsock/usrsock_event.c
index 62f307c..42325f2 100644
--- a/net/usrsock/usrsock_event.c
+++ b/net/usrsock/usrsock_event.c
@@ -99,16 +99,6 @@ int usrsock_event(FAR struct usrsock_conn_s *conn, uint16_t events)
conn->state = USRSOCK_CONN_STATE_ABORTED;
}
- if (events & USRSOCK_EVENT_REMOTE_CLOSED)
- {
- /* After reception of remote close event, clear input/output flags. */
-
- conn->flags &= ~(USRSOCK_EVENT_SENDTO_READY |
- USRSOCK_EVENT_RECVFROM_AVAIL);
-
- conn->flags |= USRSOCK_EVENT_REMOTE_CLOSED;
- }
-
if ((conn->state == USRSOCK_CONN_STATE_READY ||
conn->state == USRSOCK_CONN_STATE_CONNECTING) &&
!(conn->flags & USRSOCK_EVENT_REMOTE_CLOSED))
@@ -124,6 +114,15 @@ int usrsock_event(FAR struct usrsock_conn_s *conn, uint16_t events)
}
}
+ if (events & USRSOCK_EVENT_REMOTE_CLOSED)
+ {
+ /* After reception of remote close event, clear input flags. */
+
+ conn->flags &= ~USRSOCK_EVENT_SENDTO_READY;
+
+ conn->flags |= USRSOCK_EVENT_REMOTE_CLOSED;
+ }
+
/* Send events to callbacks */
devif_conn_event(NULL, conn, events, conn->list);
diff --git a/net/usrsock/usrsock_recvmsg.c b/net/usrsock/usrsock_recvmsg.c
index b237287..2d895cb 100644
--- a/net/usrsock/usrsock_recvmsg.c
+++ b/net/usrsock/usrsock_recvmsg.c
@@ -119,11 +119,11 @@ static uint16_t recvfrom_event(FAR struct net_driver_s *dev,
nxsem_post(&pstate->reqstate.recvsem);
}
- else if (flags & USRSOCK_EVENT_REMOTE_CLOSED)
+ else if (flags & USRSOCK_EVENT_RECVFROM_AVAIL)
{
- ninfo("remote closed.\n");
+ ninfo("recvfrom avail.\n");
- pstate->reqstate.result = -EPIPE;
+ flags &= ~USRSOCK_EVENT_RECVFROM_AVAIL;
/* Stop further callbacks */
@@ -135,11 +135,11 @@ static uint16_t recvfrom_event(FAR struct net_driver_s *dev,
nxsem_post(&pstate->reqstate.recvsem);
}
- else if (flags & USRSOCK_EVENT_RECVFROM_AVAIL)
+ else if (flags & USRSOCK_EVENT_REMOTE_CLOSED)
{
- ninfo("recvfrom avail.\n");
+ ninfo("remote closed.\n");
- flags &= ~USRSOCK_EVENT_RECVFROM_AVAIL;
+ pstate->reqstate.result = -EPIPE;
/* Stop further callbacks */
@@ -304,7 +304,8 @@ ssize_t usrsock_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
{
/* Check if remote end has closed connection. */
- if (conn->flags & USRSOCK_EVENT_REMOTE_CLOSED)
+ if (conn->flags & USRSOCK_EVENT_REMOTE_CLOSED &&
+ !(conn->flags & USRSOCK_EVENT_RECVFROM_AVAIL))
{
ninfo("usockid=%d; remote closed (EOF).\n", conn->usockid);
@@ -378,7 +379,8 @@ ssize_t usrsock_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
/* Did remote disconnect? */
- if (conn->flags & USRSOCK_EVENT_REMOTE_CLOSED)
+ if (conn->flags & USRSOCK_EVENT_REMOTE_CLOSED &&
+ !(conn->flags & USRSOCK_EVENT_RECVFROM_AVAIL))
{
ret = 0;
goto errout_unlock;