You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2020/08/18 04:41:27 UTC

[incubator-nuttx] 03/03: vfs/epoll: add epoll_create1(2) implement

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/incubator-nuttx.git

commit b89737395b8a6ff96ac21991cbb4b9012a2bc972
Author: chao.an <an...@xiaomi.com>
AuthorDate: Mon Aug 17 10:58:27 2020 +0800

    vfs/epoll: add epoll_create1(2) implement
    
    Linux Programmer's Manual
    
    NAME
           epoll_create, epoll_create1 - open an epoll file descriptor
    
    ...
    SYNOPSIS
           #include <sys/epoll.h>
    
           int epoll_create1(int flags);
    ...
    
       epoll_create1()
           If flags is 0, then, other than the fact that the obsolete
           size argument is dropped, epoll_create1() is the same as
           epoll_create(). The following value can be included in flags
           to obtain different behavior:
    
           EPOLL_CLOEXEC
                  Set the close-on-exec (FD_CLOEXEC) flag on the new file
                  descriptor. See the description of the O_CLOEXEC flag in
                  open(2) for reasons why this may be useful.
    
    https://man7.org/linux/man-pages/man7/epoll.7.html
---
 fs/Kconfig          |  6 ++++++
 fs/vfs/fs_epoll.c   | 25 +++++++++++++++++++++++++
 include/sys/epoll.h | 12 +++++++++++-
 3 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/fs/Kconfig b/fs/Kconfig
index cce2d2a..34d9884 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -30,6 +30,12 @@ config FS_AUTOMOUNTER_DEBUG
 		system debug is not enable.  This is useful primarily for in vivo
 		unit testing of the auto-mount feature.
 
+config FS_NEPOLL_DESCRIPTORS
+	int "Maximum number of default epoll descriptors for epoll_create1(2)"
+	default 8
+	---help---
+		The maximum number of default epoll descriptors for epoll_create1(2)
+
 config DISABLE_PSEUDOFS_OPERATIONS
 	bool "Disable pseudo-filesystem operations"
 	default y if DEFAULT_SMALL
diff --git a/fs/vfs/fs_epoll.c b/fs/vfs/fs_epoll.c
index 35547f4..f6f9bdf 100644
--- a/fs/vfs/fs_epoll.c
+++ b/fs/vfs/fs_epoll.c
@@ -81,6 +81,31 @@ int epoll_create(int size)
 }
 
 /****************************************************************************
+ * Name: epoll_create1
+ *
+ * Description:
+ *
+ * Input Parameters:
+ *
+ * Returned Value:
+ *
+ ****************************************************************************/
+
+int epoll_create1(int flags)
+{
+  /* For current implementation, Close-on-exec is a default behavior,
+   * the handle of epoll(2) is not a real file handle.
+   */
+
+  if (flags != EPOLL_CLOEXEC)
+    {
+      return EINVAL;
+    }
+
+  return epoll_create(CONFIG_FS_NEPOLL_DESCRIPTORS);
+}
+
+/****************************************************************************
  * Name: epoll_close
  *
  * Description:
diff --git a/include/sys/epoll.h b/include/sys/epoll.h
index b94ef0a..d8f2219 100644
--- a/include/sys/epoll.h
+++ b/include/sys/epoll.h
@@ -76,6 +76,14 @@ enum EPOLL_EVENTS
 #define EPOLLHUP EPOLLHUP
   };
 
+/* Flags to be passed to epoll_create1.  */
+
+enum
+{
+    EPOLL_CLOEXEC = 02000000
+#define EPOLL_CLOEXEC EPOLL_CLOEXEC
+};
+
 typedef union poll_data
 {
   void        *ptr;
@@ -108,8 +116,10 @@ struct epoll_head
  ****************************************************************************/
 
 int epoll_create(int size);
+int epoll_create1(int flags);
 int epoll_ctl(int epfd, int op, int fd, struct epoll_event *ev);
-int epoll_wait(int epfd, struct epoll_event *evs, int maxevents, int timeout);
+int epoll_wait(int epfd, struct epoll_event *evs,
+               int maxevents, int timeout);
 
 void epoll_close(int epfd);