|
|
@@ -23,15 +23,13 @@
|
|
|
|
|
|
#include "SDL_poll.h"
|
|
|
|
|
|
-#ifdef HAVE_POLL
|
|
|
#include <poll.h>
|
|
|
-#else
|
|
|
-#include <sys/time.h>
|
|
|
-#include <sys/types.h>
|
|
|
-#include <unistd.h>
|
|
|
-#endif
|
|
|
#include <errno.h>
|
|
|
|
|
|
+#ifdef HAVE_PPOLL
|
|
|
+#include <time.h>
|
|
|
+#endif
|
|
|
+
|
|
|
int SDL_IOReady(int fd, int flags, Sint64 timeoutNS)
|
|
|
{
|
|
|
int result;
|
|
|
@@ -40,9 +38,7 @@ int SDL_IOReady(int fd, int flags, Sint64 timeoutNS)
|
|
|
|
|
|
// Note: We don't bother to account for elapsed time if we get EINTR
|
|
|
do {
|
|
|
-#ifdef HAVE_POLL
|
|
|
struct pollfd info;
|
|
|
- int timeoutMS;
|
|
|
|
|
|
info.fd = fd;
|
|
|
info.events = 0;
|
|
|
@@ -52,7 +48,21 @@ int SDL_IOReady(int fd, int flags, Sint64 timeoutNS)
|
|
|
if (flags & SDL_IOR_WRITE) {
|
|
|
info.events |= POLLOUT;
|
|
|
}
|
|
|
- // FIXME: Add support for ppoll() for nanosecond precision
|
|
|
+
|
|
|
+#ifdef HAVE_PPOLL
|
|
|
+ struct timespec *timeout = NULL;
|
|
|
+ struct timespec ts;
|
|
|
+
|
|
|
+ if (timeoutNS >= 0) {
|
|
|
+ ts.tv_sec = SDL_NS_TO_SECONDS(timeoutNS);
|
|
|
+ ts.tv_nsec = timeoutNS - SDL_SECONDS_TO_NS(ts.tv_sec);
|
|
|
+ timeout = &ts;
|
|
|
+ }
|
|
|
+
|
|
|
+ result = ppoll(&info, 1, timeout, NULL);
|
|
|
+#else
|
|
|
+ int timeoutMS;
|
|
|
+
|
|
|
if (timeoutNS > 0) {
|
|
|
timeoutMS = (int)SDL_NS_TO_MS(timeoutNS + (SDL_NS_PER_MS - 1));
|
|
|
} else if (timeoutNS == 0) {
|
|
|
@@ -61,34 +71,7 @@ int SDL_IOReady(int fd, int flags, Sint64 timeoutNS)
|
|
|
timeoutMS = -1;
|
|
|
}
|
|
|
result = poll(&info, 1, timeoutMS);
|
|
|
-#else
|
|
|
- fd_set rfdset, *rfdp = NULL;
|
|
|
- fd_set wfdset, *wfdp = NULL;
|
|
|
- struct timeval tv, *tvp = NULL;
|
|
|
-
|
|
|
- // If this assert triggers we'll corrupt memory here
|
|
|
- SDL_assert(fd >= 0 && fd < FD_SETSIZE);
|
|
|
-
|
|
|
- if (flags & SDL_IOR_READ) {
|
|
|
- FD_ZERO(&rfdset);
|
|
|
- FD_SET(fd, &rfdset);
|
|
|
- rfdp = &rfdset;
|
|
|
- }
|
|
|
- if (flags & SDL_IOR_WRITE) {
|
|
|
- FD_ZERO(&wfdset);
|
|
|
- FD_SET(fd, &wfdset);
|
|
|
- wfdp = &wfdset;
|
|
|
- }
|
|
|
-
|
|
|
- if (timeoutNS >= 0) {
|
|
|
- tv.tv_sec = (timeoutNS / SDL_NS_PER_SECOND);
|
|
|
- tv.tv_usec = SDL_NS_TO_US((timeoutNS % SDL_NS_PER_SECOND) + (SDL_NS_PER_US - 1));
|
|
|
- tvp = &tv;
|
|
|
- }
|
|
|
-
|
|
|
- result = select(fd + 1, rfdp, wfdp, NULL, tvp);
|
|
|
-#endif // HAVE_POLL
|
|
|
-
|
|
|
+#endif
|
|
|
} while (result < 0 && errno == EINTR && !(flags & SDL_IOR_NO_RETRY));
|
|
|
|
|
|
return result;
|