net/local: fix blocking local sockets

Commit 4d6a8663fa made pipes and
named pipes block when opening for O_WRONLY or O_RDONLY. Local
sockets, however, require `local_open_client_tx` to be non-blocking
to enable the server side to prevent the server side from blocking.
If set otherwise, it would deadly block. This commit sets the FIFO
as non-blocking temporarily, open the TX side and, if originally
blocking - restores it to that state.
This commit is contained in:
Tiago Medicci Serrano 2023-05-10 21:41:24 -03:00 committed by Xiang Xiao
parent 91e13c47ae
commit 4f4a00ab1f
1 changed files with 12 additions and 2 deletions

View File

@ -275,10 +275,9 @@ static int local_rx_open(FAR struct local_conn_s *conn, FAR const char *path,
static int local_tx_open(FAR struct local_conn_s *conn, FAR const char *path,
bool nonblock)
{
int oflags = nonblock ? O_WRONLY | O_NONBLOCK : O_WRONLY;
int ret;
ret = file_open(&conn->lc_outfile, path, oflags);
ret = file_open(&conn->lc_outfile, path, O_WRONLY | O_NONBLOCK);
if (ret < 0)
{
nerr("ERROR: Failed on open %s for writing: %d\n",
@ -295,6 +294,17 @@ static int local_tx_open(FAR struct local_conn_s *conn, FAR const char *path,
return ret == -ENOENT ? -EFAULT : ret;
}
/* Clear O_NONBLOCK if it's meant to be blocking */
if (nonblock == false)
{
ret = file_fcntl(&conn->lc_outfile, F_SETFL, O_WRONLY);
if (ret < 0)
{
return ret;
}
}
return OK;
}