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 <liguiding1@xiaomi.com>
This commit is contained in:
ligd 2022-05-28 00:24:35 +08:00 committed by Petro Karashchenko
parent e489a308c8
commit cd5ab80f2f
4 changed files with 14 additions and 0 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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 */

View File

@ -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;