drivers/pipe: Change to the block mode by file_ioctl(FIONBIO)

it's simpler and safer than file_fcntl(F_SETFL)

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2024-02-27 04:31:20 +08:00 committed by Alan Carvalho de Assis
parent 64ea027b1a
commit 1ba065db87
2 changed files with 9 additions and 10 deletions

View File

@ -31,6 +31,7 @@
#include <fcntl.h>
#include <assert.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <nuttx/fs/fs.h>
#include <nuttx/mutex.h>
@ -207,8 +208,8 @@ static int pipe_register(size_t bufsize, int flags,
int file_pipe(FAR struct file *filep[2], size_t bufsize, int flags)
{
char devname[32];
int nonblock = !!(flags & O_NONBLOCK);
int ret;
bool blocking;
/* Register a new pipe device */
@ -218,10 +219,6 @@ int file_pipe(FAR struct file *filep[2], size_t bufsize, int flags)
return ret;
}
/* Check for the O_NONBLOCK bit on flags */
blocking = (flags & O_NONBLOCK) == 0;
/* Get a write file descriptor */
ret = file_open(filep[1], devname, O_WRONLY | O_NONBLOCK | flags);
@ -232,9 +229,9 @@ int file_pipe(FAR struct file *filep[2], size_t bufsize, int flags)
/* Clear O_NONBLOCK if it was set previously */
if (blocking)
if (!nonblock)
{
ret = file_fcntl(filep[1], F_SETFL, flags & (~O_NONBLOCK));
ret = file_ioctl(filep[1], FIONBIO, &nonblock);
if (ret < 0)
{
goto errout_with_driver;
@ -284,6 +281,7 @@ errout_with_driver:
int pipe2(int fd[2], int flags)
{
char devname[32];
int nonblock = !!(flags & O_NONBLOCK);
int ret;
/* Register a new pipe device */
@ -305,9 +303,9 @@ int pipe2(int fd[2], int flags)
/* Clear O_NONBLOCK if it was set previously */
if ((flags & O_NONBLOCK) == 0)
if (!nonblock)
{
ret = fcntl(fd[1], F_SETFL, flags & (~O_NONBLOCK));
ret = ioctl(fd[1], FIONBIO, &nonblock);
if (ret < 0)
{
goto errout_with_driver;

View File

@ -294,7 +294,8 @@ static int local_tx_open(FAR struct local_conn_s *conn, FAR const char *path,
if (nonblock == false)
{
ret = file_fcntl(&conn->lc_outfile, F_SETFL, O_WRONLY);
ret = nonblock;
ret = file_ioctl(&conn->lc_outfile, FIONBIO, &ret);
if (ret < 0)
{
return ret;