You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by pk...@apache.org on 2022/07/22 11:07:20 UTC
[incubator-nuttx] 02/04: local: server accept should wait client connect done
This is an automated email from the ASF dual-hosted git repository.
pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit cd5ab80f2ffcd0c29ea72afaad7d329033f02520
Author: ligd <li...@xiaomi.com>
AuthorDate: Sat May 28 00:24:35 2022 +0800
local: server accept should wait client connect done
server:
at accept last nxsem_post(&client->lc_waitsem);
client:
connect wait(&client->lc_waitsem) then local_open_client_rx();
But if the server priority is higher then client,
and after server accept return, immediately call send().
At this time the client has no way do local_open_client_rx().
Then server send() return error.
Fix:
add lc_done sem to client
Signed-off-by: ligd <li...@xiaomi.com>
---
net/local/local.h | 1 +
net/local/local_accept.c | 6 ++++++
net/local/local_conn.c | 5 +++++
net/local/local_connect.c | 2 ++
4 files changed, 14 insertions(+)
diff --git a/net/local/local.h b/net/local/local.h
index ca9eab2d16..9af3a5139d 100644
--- a/net/local/local.h
+++ b/net/local/local.h
@@ -145,6 +145,7 @@ struct local_conn_s
/* SOCK_STREAM fields common to both client and server */
sem_t lc_waitsem; /* Use to wait for a connection to be accepted */
+ sem_t lc_donesem; /* Use to wait for client connected done */
FAR struct socket *lc_psock; /* A reference to the socket structure */
/* The following is a list if poll structures of threads waiting for
diff --git a/net/local/local_accept.c b/net/local/local_accept.c
index 5a2bed225d..6cf82c69ca 100644
--- a/net/local/local_accept.c
+++ b/net/local/local_accept.c
@@ -243,6 +243,12 @@ int local_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
}
nxsem_post(&client->lc_waitsem);
+
+ if (ret == OK)
+ {
+ ret = net_lockedwait(&client->lc_donesem);
+ }
+
return ret;
}
diff --git a/net/local/local_conn.c b/net/local/local_conn.c
index 302c7cb848..2e343bb630 100644
--- a/net/local/local_conn.c
+++ b/net/local/local_conn.c
@@ -124,6 +124,10 @@ FAR struct local_conn_s *local_alloc(void)
nxsem_init(&conn->lc_waitsem, 0, 0);
nxsem_set_protocol(&conn->lc_waitsem, SEM_PRIO_NONE);
+
+ nxsem_init(&conn->lc_donesem, 0, 0);
+ nxsem_set_protocol(&conn->lc_donesem, SEM_PRIO_NONE);
+
#endif
/* Add the connection structure to the list of listeners */
@@ -203,6 +207,7 @@ void local_free(FAR struct local_conn_s *conn)
local_release_fifos(conn);
nxsem_destroy(&conn->lc_waitsem);
+ nxsem_destroy(&conn->lc_donesem);
#endif
/* And free the connection structure */
diff --git a/net/local/local_connect.c b/net/local/local_connect.c
index 37181ddd30..74aede5da0 100644
--- a/net/local/local_connect.c
+++ b/net/local/local_connect.c
@@ -178,6 +178,8 @@ static int inline local_stream_connect(FAR struct local_conn_s *client,
DEBUGASSERT(client->lc_infile.f_inode != NULL);
+ nxsem_post(&client->lc_donesem);
+
if (!nonblock)
{
client->lc_state = LOCAL_STATE_CONNECTED;