加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-0002-posix-Add-npth_poll-npth_ppoll.patch 3.81 KB
一键复制 编辑 原始数据 按行查看 历史
EulerOSWander 提交于 2022-03-10 16:28 . posix: Add npth_poll/npth_ppoll
From b5ecd8d2c6fdb988f6139c5157c124ebea293bd7 Mon Sep 17 00:00:00 2001
From: NIIBE Yutaka <gniibe@fsij.org>
Date: Wed, 22 Dec 2021 09:52:44 +0900
Subject: [PATCH 1/2] posix: Add npth_poll/npth_ppoll.
* configure.ac: Add checks for poll.h and ppoll.
--
GnuPG-bug-id: 5748
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
Signed-off-by: EulerOSWander <314264452@qq.com>
---
configure.ac | 6 ++---
src/npth.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/npth.h.in | 5 +++++
3 files changed, 78 insertions(+), 3 deletions(-)
diff --git a/configure.ac b/configure.ac
index 3d76661..cf8bb0e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -18,7 +18,7 @@
# Process this file with autoconf to produce a configure script.
-AC_PREREQ([2.67])
+AC_PREREQ([2.69])
min_automake_version="1.14"
# To build a release you need to create a tag with the version number
@@ -198,7 +198,7 @@ AC_DEFINE_UNQUOTED(BUILD_TIMESTAMP, "$BUILD_TIMESTAMP",
#
# fixme: For what do we need the sys/socket test?
AC_CHECK_HEADERS([sys/socket.h sys/select.h unistd.h sys/time.h time.h \
- signal.h])
+ signal.h poll.h])
INSERT_SYS_SELECT_H=
if test x"$ac_cv_header_sys_select_h" = xyes; then
INSERT_SYS_SELECT_H="include <sys/select.h>"
@@ -277,7 +277,7 @@ if test "$have_w32_system" = no; then
fi
fi
-AC_CHECK_FUNCS([select pselect gettimeofday])
+AC_CHECK_FUNCS([select pselect gettimeofday ppoll])
npth_LIBSOCKET
config_libs="$config_libs $LIBSOCKET"
diff --git a/src/npth.c b/src/npth.c
index 45ca7ee..22314a6 100644
--- a/src/npth.c
+++ b/src/npth.c
@@ -71,6 +71,9 @@ sem_wait (sem_t *sem)
#ifndef HAVE_PSELECT
# include <signal.h>
#endif
+#ifdef HAVE_POLL_H
+#include <poll.h>
+#endif
#include "npth.h"
@@ -675,6 +678,73 @@ npth_pselect(int nfd, fd_set *rfds, fd_set *wfds, fd_set *efds,
}
+int
+npth_poll (struct pollfd *fds, unsigned long nfds, int timeout)
+{
+ int res;
+
+ ENTER();
+#ifdef HAVE_POLL_H
+ res = poll (fds, (nfds_t)nfds, timeout);
+#endif
+ LEAVE();
+ return res;
+}
+
+
+int
+npth_ppoll (struct pollfd *fds, unsigned long nfds,
+ const struct timespec *timeout, const sigset_t *sigmask)
+{
+ int res;
+
+ ENTER();
+#ifdef HAVE_POLL_H
+#ifdef HAVE_PPOLL
+ res = ppoll (fds, (nfds_t)nfds, timeout, sigmask);
+#else /*!HAVE_PPOLL*/
+ {
+# ifdef __GNUC__
+# warning Using a non race free ppoll emulation.
+# endif
+
+ int t;
+
+ if (!timeout)
+ t = -1;
+ else if (timeout->tv_nsec >= 0 && timeout->tv_nsec < 1000000000)
+ t = timeout->tv_sec * 1000 + (timeout->tv_nsec + 999999) / 1000000;
+ else
+ {
+ errno = EINVAL;
+ res = -1;
+ goto leave;
+ }
+
+ if (sigmask)
+ {
+ int save_errno;
+ sigset_t savemask;
+
+ pthread_sigmask (SIG_SETMASK, sigmask, &savemask);
+ res = poll (fds, (nfds_t)nfds, timeout);
+ save_errno = errno;
+ pthread_sigmask (SIG_SETMASK, &savemask, NULL);
+ errno = save_errno;
+ }
+ else
+ res = poll (fds, (nfds_t)nfds, timeout);
+
+ leave:
+ ;
+ }
+#endif
+#endif
+ LEAVE();
+ return res;
+}
+
+
ssize_t
npth_read(int fd, void *buf, size_t nbytes)
{
diff --git a/src/npth.h.in b/src/npth.h.in
index 39dcf32..db57935 100644
--- a/src/npth.h.in
+++ b/src/npth.h.in
@@ -345,6 +345,11 @@ ssize_t npth_write(int fd, const void *buf, size_t nbytes);
int npth_recvmsg (int fd, struct msghdr *msg, int flags);
int npth_sendmsg (int fd, const struct msghdr *msg, int flags);
+struct pollfd;
+int npth_poll (struct pollfd *fds, unsigned long nfds, int timeout);
+int npth_ppoll (struct pollfd *fds, unsigned long nfds,
+ const struct timespec *timeout, const sigset_t *sigmask);
+
/* For anything not covered here, you can enter/leave manually at your
own risk. */
void npth_unprotect (void);
--
1.8.3.1
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化