summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRolland Dudemaine <rolland ghs com>2015-08-06 14:01:06 +0100
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2015-08-06 14:03:16 +0100
commitd0e9d8e7bad9280f03e9389eef220d219f84dd16 (patch)
tree2f505914c4bf1ffedff6d5b209b3e3dbe7520942
parent4bc250f96add57d14149e1328af0ba60364eee95 (diff)
downloaddbus-d0e9d8e7bad9280f03e9389eef220d219f84dd16.tar.gz
Use poll's data types directly, where used at all
[smcv: added commit message; moved fallback implementation below definition of DBusPollable; more comments; removed unnecessary cast] Bug: https://bugs.freedesktop.org/show_bug.cgi?id=90314 Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
-rw-r--r--dbus/dbus-sysdeps-unix.c42
-rw-r--r--dbus/dbus-sysdeps.h94
2 files changed, 44 insertions, 92 deletions
diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c
index dc0418cb..50ca60a2 100644
--- a/dbus/dbus-sysdeps-unix.c
+++ b/dbus/dbus-sysdeps-unix.c
@@ -2752,43 +2752,17 @@ _dbus_poll (DBusPollFD *fds,
int timeout_milliseconds)
{
#if defined(HAVE_POLL) && !defined(BROKEN_POLL)
- /* This big thing is a constant expression and should get optimized
- * out of existence. So it's more robust than a configure check at
- * no cost.
- */
- if (_DBUS_POLLIN == POLLIN &&
- _DBUS_POLLPRI == POLLPRI &&
- _DBUS_POLLOUT == POLLOUT &&
- _DBUS_POLLERR == POLLERR &&
- _DBUS_POLLHUP == POLLHUP &&
- _DBUS_POLLNVAL == POLLNVAL &&
- sizeof (DBusPollFD) == sizeof (struct pollfd) &&
- _DBUS_STRUCT_OFFSET (DBusPollFD, fd) ==
- _DBUS_STRUCT_OFFSET (struct pollfd, fd) &&
- _DBUS_STRUCT_OFFSET (DBusPollFD, events) ==
- _DBUS_STRUCT_OFFSET (struct pollfd, events) &&
- _DBUS_STRUCT_OFFSET (DBusPollFD, revents) ==
- _DBUS_STRUCT_OFFSET (struct pollfd, revents))
+ /* DBusPollFD is a struct pollfd in this code path, so we can just poll() */
+ if (timeout_milliseconds < -1)
{
- if (timeout_milliseconds < -1)
- {
- timeout_milliseconds = -1;
- }
-
- return poll ((struct pollfd*) fds,
- n_fds,
- timeout_milliseconds);
+ timeout_milliseconds = -1;
}
- else
- {
- /* We have to convert the DBusPollFD to an array of
- * struct pollfd, poll, and convert back.
- */
- _dbus_warn ("didn't implement poll() properly for this system yet\n");
- return -1;
- }
-#else /* ! HAVE_POLL */
+ return poll (fds,
+ n_fds,
+ timeout_milliseconds);
+#else /* ! HAVE_POLL */
+ /* Emulate poll() in terms of select() */
fd_set read_set, write_set, err_set;
int max_fd = 0;
int i;
diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h
index 7043a452..79a6cc7c 100644
--- a/dbus/dbus-sysdeps.h
+++ b/dbus/dbus-sysdeps.h
@@ -299,63 +299,6 @@ dbus_int32_t _dbus_atomic_inc (DBusAtomic *atomic);
dbus_int32_t _dbus_atomic_dec (DBusAtomic *atomic);
dbus_int32_t _dbus_atomic_get (DBusAtomic *atomic);
-
-/* AIX uses different values for poll */
-
-#ifdef _AIX
-/** There is data to read */
-#define _DBUS_POLLIN 0x0001
-/** There is urgent data to read */
-#define _DBUS_POLLPRI 0x0004
-/** Writing now will not block */
-#define _DBUS_POLLOUT 0x0002
-/** Error condition */
-#define _DBUS_POLLERR 0x4000
-/** Hung up */
-#define _DBUS_POLLHUP 0x2000
-/** Invalid request: fd not open */
-#define _DBUS_POLLNVAL 0x8000
-#elif defined(__HAIKU__)
-/** There is data to read */
-#define _DBUS_POLLIN 0x0001
-/** Writing now will not block */
-#define _DBUS_POLLOUT 0x0002
-/** Error condition */
-#define _DBUS_POLLERR 0x0004
-/** There is urgent data to read */
-#define _DBUS_POLLPRI 0x0020
-/** Hung up */
-#define _DBUS_POLLHUP 0x0080
-/** Invalid request: fd not open */
-#define _DBUS_POLLNVAL 0x1000
-#elif defined(__QNX__)
-/** Writing now will not block */
-#define _DBUS_POLLOUT 0x0002
-/** There is data to read */
-#define _DBUS_POLLIN 0x0005
-/** There is urgent data to read */
-#define _DBUS_POLLPRI 0x0008
-/** Error condition */
-#define _DBUS_POLLERR 0x0020
-/** Hung up */
-#define _DBUS_POLLHUP 0x0040
-/** Invalid request: fd not open */
-#define _DBUS_POLLNVAL 0x1000
-#else
-/** There is data to read */
-#define _DBUS_POLLIN 0x0001
-/** There is urgent data to read */
-#define _DBUS_POLLPRI 0x0002
-/** Writing now will not block */
-#define _DBUS_POLLOUT 0x0004
-/** Error condition */
-#define _DBUS_POLLERR 0x0008
-/** Hung up */
-#define _DBUS_POLLHUP 0x0010
-/** Invalid request: fd not open */
-#define _DBUS_POLLNVAL 0x0020
-#endif
-
#ifdef DBUS_WIN
/* On Windows, you can only poll sockets. We emulate Unix poll() using
@@ -407,9 +350,30 @@ _dbus_pollable_equals (DBusPollable a, DBusPollable b) { return a == b; }
#endif /* !DBUS_WIN */
+#if defined(HAVE_POLL) && !defined(BROKEN_POLL)
/**
- * A portable struct pollfd wrapper.
+ * A portable struct pollfd wrapper, or an emulation of struct pollfd
+ * on platforms where poll() is missing or broken.
*/
+typedef struct pollfd DBusPollFD;
+
+/** There is data to read */
+#define _DBUS_POLLIN POLLIN
+/** There is urgent data to read */
+#define _DBUS_POLLPRI POLLPRI
+/** Writing now will not block */
+#define _DBUS_POLLOUT POLLOUT
+/** Error condition */
+#define _DBUS_POLLERR POLLERR
+/** Hung up */
+#define _DBUS_POLLHUP POLLHUP
+/** Invalid request: fd not open */
+#define _DBUS_POLLNVAL POLLNVAL
+#else
+/* Emulate poll() via select(). Because we aren't really going to call
+ * poll(), any similarly-shaped struct is acceptable, and any power of 2
+ * will do for the events/revents; these values happen to match Linux
+ * and *BSD. */
typedef struct
{
DBusPollable fd; /**< File descriptor */
@@ -417,6 +381,20 @@ typedef struct
short revents; /**< Events that occurred */
} DBusPollFD;
+/** There is data to read */
+#define _DBUS_POLLIN 0x0001
+/** There is urgent data to read */
+#define _DBUS_POLLPRI 0x0002
+/** Writing now will not block */
+#define _DBUS_POLLOUT 0x0004
+/** Error condition */
+#define _DBUS_POLLERR 0x0008
+/** Hung up */
+#define _DBUS_POLLHUP 0x0010
+/** Invalid request: fd not open */
+#define _DBUS_POLLNVAL 0x0020
+#endif
+
DBUS_PRIVATE_EXPORT
int _dbus_poll (DBusPollFD *fds,
int n_fds,