This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 4f4a00ab1f net/local: fix blocking local sockets
4f4a00ab1f is described below
commit 4f4a00ab1ffb19fd666562de3d7e9f480719ac2f
Author: Tiago Medicci Serrano <[email protected]>
AuthorDate: Wed May 10 21:41:24 2023 -0300
net/local: fix blocking local sockets
Commit 4d6a8663fa0932a8c1b40639464f68af670f0808 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.
---
net/local/local_fifo.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/net/local/local_fifo.c b/net/local/local_fifo.c
index d361e1f259..2c49d237a1 100644
--- a/net/local/local_fifo.c
+++ b/net/local/local_fifo.c
@@ -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;
}