mirror of
https://github.com/apache/nuttx.git
synced 2026-05-27 19:36:35 +08:00
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:
committed by
Xiang Xiao
parent
91e13c47ae
commit
4f4a00ab1f
+12
-2
@@ -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,
|
static int local_tx_open(FAR struct local_conn_s *conn, FAR const char *path,
|
||||||
bool nonblock)
|
bool nonblock)
|
||||||
{
|
{
|
||||||
int oflags = nonblock ? O_WRONLY | O_NONBLOCK : O_WRONLY;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = file_open(&conn->lc_outfile, path, oflags);
|
ret = file_open(&conn->lc_outfile, path, O_WRONLY | O_NONBLOCK);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
nerr("ERROR: Failed on open %s for writing: %d\n",
|
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;
|
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;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user