From 105fc117b70635dbeb921a5a74be75e44ac98fe2 Mon Sep 17 00:00:00 2001 From: Louai Al-Khanji Date: Thu, 15 Oct 2015 16:04:17 +0300 Subject: Add qt_safe_poll This function is introduced to safely provide poll(2)-like semantics for socket multiplexing on Unix-like platforms. For platforms where no poll system call is available, an implementation based on select(2) is provided. Change-Id: I320e97dae5924316675a74d1897c48cae292ac6d Reviewed-by: Oswald Buddenhagen Reviewed-by: Thiago Macieira --- src/corelib/kernel/qcore_unix_p.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/corelib/kernel/qcore_unix_p.h') diff --git a/src/corelib/kernel/qcore_unix_p.h b/src/corelib/kernel/qcore_unix_p.h index d82b2651e7..d5434888d0 100644 --- a/src/corelib/kernel/qcore_unix_p.h +++ b/src/corelib/kernel/qcore_unix_p.h @@ -66,6 +66,28 @@ # include #endif +#ifndef QT_NO_NATIVE_POLL +# include +#else +struct pollfd { + int fd; + short events, revents; +}; + +typedef unsigned long int nfds_t; + +# define POLLIN 0x001 +# define POLLPRI 0x002 +# define POLLOUT 0x004 +# define POLLERR 0x008 +# define POLLHUP 0x010 +# define POLLNVAL 0x020 +# define POLLRDNORM 0x040 +# define POLLRDBAND 0x080 +# define POLLWRNORM 0x100 +# define POLLWRBAND 0x200 +#endif + struct sockaddr; #define EINTR_LOOP(var, cmd) \ @@ -303,6 +325,8 @@ static inline pid_t qt_safe_waitpid(pid_t pid, int *status, int options) timespec qt_gettime() Q_DECL_NOTHROW; void qt_nanosleep(timespec amount); +Q_CORE_EXPORT int qt_safe_poll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout_ts); + Q_CORE_EXPORT int qt_safe_select(int nfds, fd_set *fdread, fd_set *fdwrite, fd_set *fdexcept, const struct timespec *tv); -- cgit v1.2.3