Commit d0e9d8e7 authored by Rolland Dudemaine's avatar Rolland Dudemaine Committed by Simon McVittie

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=90314Signed-off-by: default avatarSimon McVittie <simon.mcvittie@collabora.co.uk>
parent 4bc250f9
......@@ -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;
......
......@@ -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,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment