From cd5ab80f2ffcd0c29ea72afaad7d329033f02520 Mon Sep 17 00:00:00 2001 From: ligd Date: Sat, 28 May 2022 00:24:35 +0800 Subject: [PATCH] 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 --- 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;