You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/02/19 18:01:34 UTC
[incubator-nuttx] branch pr312 updated: net/ioctl: add FIONBIO
support
This is an automated email from the ASF dual-hosted git repository.
gnutt pushed a commit to branch pr312
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/pr312 by this push:
new 95ca5eb net/ioctl: add FIONBIO support
95ca5eb is described below
commit 95ca5ebb81abab490979a4c7b38871f34756c292
Author: chao.an <an...@xiaomi.com>
AuthorDate: Tue Feb 4 13:23:50 2020 +0800
net/ioctl: add FIONBIO support
Change-Id: Ic04eaaa2a134a050ad5a8379561a733ae7891d8a
Signed-off-by: chao.an <an...@xiaomi.com>
---
fs/vfs/fs_ioctl.c | 69 +++++++++++++++++++++++++++++-------------------
include/nuttx/fs/ioctl.h | 4 +++
2 files changed, 46 insertions(+), 27 deletions(-)
diff --git a/fs/vfs/fs_ioctl.c b/fs/vfs/fs_ioctl.c
index 28d006d..65bf53c 100644
--- a/fs/vfs/fs_ioctl.c
+++ b/fs/vfs/fs_ioctl.c
@@ -43,6 +43,7 @@
#include <sys/ioctl.h>
#include <sched.h>
#include <errno.h>
+#include <fcntl.h>
#include <assert.h>
#include <net/if.h>
@@ -136,7 +137,6 @@ int fs_ioctl(int fd, int req, unsigned long arg)
int ioctl(int fd, int req, unsigned long arg)
#endif
{
- int errcode;
FAR struct file *filep;
int ret;
@@ -147,50 +147,65 @@ int ioctl(int fd, int req, unsigned long arg)
/* Perform the socket ioctl */
#ifdef CONFIG_NET
- if ((unsigned int)fd < (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS))
+ if ((unsigned int)fd <
+ (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS))
{
ret = netdev_ioctl(fd, req, arg);
- if (ret < 0)
- {
- errcode = -ret;
- goto errout;
- }
-
- return ret;
}
else
#endif
{
- errcode = EBADF;
+ ret = -EBADF;
goto errout;
}
}
+ else
+ {
+ /* Get the file structure corresponding to the file descriptor. */
- /* Get the file structure corresponding to the file descriptor. */
+ ret = fs_getfilep(fd, &filep);
+ if (ret < 0)
+ {
+ goto errout;
+ }
- ret = fs_getfilep(fd, &filep);
- if (ret < 0)
- {
- errcode = -ret;
- goto errout;
+ DEBUGASSERT(filep != NULL);
+
+ /* Perform the file ioctl. */
+
+ ret = file_ioctl(filep, req, arg);
}
- DEBUGASSERT(filep != NULL);
+ /* Check for File system IOCTL commands */
- /* Perform the file ioctl. If file_ioctl() fails, it will set the errno
- * value appropriately.
- */
+ if (ret == -ENOTTY)
+ {
+ switch (req)
+ {
+ case FIONBIO:
+ {
+ if (*(FAR int *)((uintptr_t)arg))
+ {
+ return fcntl(fd, F_SETFL,
+ fcntl(fd, F_GETFL) | O_NONBLOCK);
+ }
+ else
+ {
+ return fcntl(fd, F_SETFL,
+ fcntl(fd, F_GETFL) & ~O_NONBLOCK);
+ }
+ }
+ break;
+ }
+ }
+
+errout:
- ret = file_ioctl(filep, req, arg);
if (ret < 0)
{
- errcode = -ret;
- goto errout;
+ set_errno(-ret);
+ ret = ERROR;
}
return ret;
-
-errout:
- set_errno(errcode);
- return ERROR;
}
diff --git a/include/nuttx/fs/ioctl.h b/include/nuttx/fs/ioctl.h
index 31809d6..a685599 100644
--- a/include/nuttx/fs/ioctl.h
+++ b/include/nuttx/fs/ioctl.h
@@ -172,6 +172,10 @@
* OUT: Instance number is returned on
* success.
*/
+#define FIONBIO _FIOC(0x000b) /* IN: Boolean option takes an
+ * int value.
+ * OUT: Origin option.
+ */
/* NuttX file system ioctl definitions **************************************/