core: Convert SDL_IOReady()'s 2nd parameter to flags
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
diff --git a/src/audio/paudio/SDL_paudio.c b/src/audio/paudio/SDL_paudio.c
index c139182..d518aa6 100644
--- a/src/audio/paudio/SDL_paudio.c
+++ b/src/audio/paudio/SDL_paudio.c
@@ -156,7 +156,7 @@ PAUDIO_WaitDevice(_THIS)
#ifdef DEBUG_AUDIO
fprintf(stderr, "Waiting for audio to get ready\n");
#endif
- if (SDL_IOReady(this->hidden->audio_fd, SDL_TRUE, timeoutMS) <= 0) {
+ if (SDL_IOReady(this->hidden->audio_fd, SDL_IOR_WRITE, timeoutMS) <= 0) {
/*
* In general we should never print to the screen,
* but in this case we have no other way of letting
diff --git a/src/audio/qsa/SDL_qsa_audio.c b/src/audio/qsa/SDL_qsa_audio.c
index cb95551..f951bc3 100644
--- a/src/audio/qsa/SDL_qsa_audio.c
+++ b/src/audio/qsa/SDL_qsa_audio.c
@@ -120,7 +120,9 @@ QSA_WaitDevice(_THIS)
/* If timeout occured than something wrong with hardware or driver */
/* For example, Vortex 8820 audio driver stucks on second DAC because */
/* it doesn't exist ! */
- result = SDL_IOReady(this->hidden->audio_fd, !this->hidden->iscapture, 2 * 1000);
+ result = SDL_IOReady(this->hidden->audio_fd,
+ this->hidden->iscapture ? SDL_IOR_READ : SDL_IOR_WRITE,
+ 2 * 1000);
switch (result) {
case -1:
SDL_SetError("QSA: SDL_IOReady() failed: %s", strerror(errno));
diff --git a/src/audio/sun/SDL_sunaudio.c b/src/audio/sun/SDL_sunaudio.c
index c9147e4..cae17ed 100644
--- a/src/audio/sun/SDL_sunaudio.c
+++ b/src/audio/sun/SDL_sunaudio.c
@@ -98,7 +98,7 @@ SUNAUDIO_WaitDevice(_THIS)
}
}
#else
- SDL_IOReady(this->hidden->audio_fd, SDL_TRUE, -1);
+ SDL_IOReady(this->hidden->audio_fd, SDL_IOR_WRITE, -1);
#endif
}
diff --git a/src/core/unix/SDL_poll.c b/src/core/unix/SDL_poll.c
index 2670b04..ec0a533 100644
--- a/src/core/unix/SDL_poll.c
+++ b/src/core/unix/SDL_poll.c
@@ -34,10 +34,12 @@
int
-SDL_IOReady(int fd, SDL_bool forWrite, int timeoutMS)
+SDL_IOReady(int fd, int flags, int timeoutMS)
{
int result;
+ SDL_assert(flags & (SDL_IOR_READ | SDL_IOR_WRITE));
+
/* Note: We don't bother to account for elapsed time if we get EINTR */
do
{
@@ -45,10 +47,12 @@ SDL_IOReady(int fd, SDL_bool forWrite, int timeoutMS)
struct pollfd info;
info.fd = fd;
- if (forWrite) {
- info.events = POLLOUT;
- } else {
- info.events = POLLIN | POLLPRI;
+ info.events = 0;
+ if (flags & SDL_IOR_READ) {
+ info.events |= POLLIN | POLLPRI;
+ }
+ if (flags & SDL_IOR_WRITE) {
+ info.events |= POLLOUT;
}
result = poll(&info, 1, timeoutMS);
#else
@@ -59,15 +63,16 @@ SDL_IOReady(int fd, SDL_bool forWrite, int timeoutMS)
/* If this assert triggers we'll corrupt memory here */
SDL_assert(fd >= 0 && fd < FD_SETSIZE);
- if (forWrite) {
- FD_ZERO(&wfdset);
- FD_SET(fd, &wfdset);
- wfdp = &wfdset;
- } else {
+ 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 (timeoutMS >= 0) {
tv.tv_sec = timeoutMS / 1000;
diff --git a/src/core/unix/SDL_poll.h b/src/core/unix/SDL_poll.h
index f8abc24..10497d1 100644
--- a/src/core/unix/SDL_poll.h
+++ b/src/core/unix/SDL_poll.h
@@ -26,8 +26,10 @@
#include "SDL_stdinc.h"
+#define SDL_IOR_READ 0x1
+#define SDL_IOR_WRITE 0x2
-extern int SDL_IOReady(int fd, SDL_bool forWrite, int timeoutMS);
+extern int SDL_IOReady(int fd, int flags, int timeoutMS);
#endif /* SDL_poll_h_ */
diff --git a/src/video/wayland/SDL_waylanddatamanager.c b/src/video/wayland/SDL_waylanddatamanager.c
index 8dca704..8de4cdd 100644
--- a/src/video/wayland/SDL_waylanddatamanager.c
+++ b/src/video/wayland/SDL_waylanddatamanager.c
@@ -50,7 +50,7 @@ write_pipe(int fd, const void* buffer, size_t total_length, size_t *pos)
sigset_t old_sig_set;
struct timespec zerotime = {0};
- ready = SDL_IOReady(fd, SDL_TRUE, PIPE_MS_TIMEOUT);
+ ready = SDL_IOReady(fd, SDL_IOR_WRITE, PIPE_MS_TIMEOUT);
sigemptyset(&sig_set);
sigaddset(&sig_set, SIGPIPE);
@@ -96,7 +96,7 @@ read_pipe(int fd, void** buffer, size_t* total_length, SDL_bool null_terminate)
ssize_t bytes_read = 0;
size_t pos = 0;
- ready = SDL_IOReady(fd, SDL_FALSE, PIPE_MS_TIMEOUT);
+ ready = SDL_IOReady(fd, SDL_IOR_READ, PIPE_MS_TIMEOUT);
if (ready == 0) {
bytes_read = SDL_SetError("Pipe timeout");
diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c
index 9a17b0a..607c6a2 100644
--- a/src/video/wayland/SDL_waylandevents.c
+++ b/src/video/wayland/SDL_waylandevents.c
@@ -259,7 +259,7 @@ Wayland_WaitEventTimeout(_THIS, int timeout)
/* wl_display_prepare_read() will return -1 if the default queue is not empty.
* If the default queue is empty, it will prepare us for our SDL_IOReady() call. */
if (WAYLAND_wl_display_prepare_read(d->display) == 0) {
- if (SDL_IOReady(WAYLAND_wl_display_get_fd(d->display), SDL_FALSE, timeout) > 0) {
+ if (SDL_IOReady(WAYLAND_wl_display_get_fd(d->display), SDL_IOR_READ, timeout) > 0) {
/* There are new events available to read */
WAYLAND_wl_display_read_events(d->display);
WAYLAND_wl_display_dispatch_pending(d->display);
@@ -308,7 +308,7 @@ Wayland_PumpEvents(_THIS)
/* wl_display_prepare_read() will return -1 if the default queue is not empty.
* If the default queue is empty, it will prepare us for our SDL_IOReady() call. */
if (WAYLAND_wl_display_prepare_read(d->display) == 0) {
- if (SDL_IOReady(WAYLAND_wl_display_get_fd(d->display), SDL_FALSE, 0) > 0) {
+ if (SDL_IOReady(WAYLAND_wl_display_get_fd(d->display), SDL_IOR_READ, 0) > 0) {
WAYLAND_wl_display_read_events(d->display);
} else {
WAYLAND_wl_display_cancel_read(d->display);
diff --git a/src/video/wayland/SDL_waylandopengles.c b/src/video/wayland/SDL_waylandopengles.c
index 934406f..ff11d16 100644
--- a/src/video/wayland/SDL_waylandopengles.c
+++ b/src/video/wayland/SDL_waylandopengles.c
@@ -155,7 +155,7 @@ Wayland_GLES_SwapWindow(_THIS, SDL_Window *window)
break;
}
- if (SDL_IOReady(WAYLAND_wl_display_get_fd(display), SDL_FALSE, max_wait - now) <= 0) {
+ if (SDL_IOReady(WAYLAND_wl_display_get_fd(display), SDL_IOR_READ, max_wait - now) <= 0) {
/* Error or timeout expired without any events for us. Cancel the read. */
WAYLAND_wl_display_cancel_read(display);
break;
diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c
index fd52092..ccab1fb 100644
--- a/src/video/x11/SDL_x11events.c
+++ b/src/video/x11/SDL_x11events.c
@@ -1536,7 +1536,7 @@ X11_Pending(Display * display)
}
/* More drastic measures are required -- see if X is ready to talk */
- if (SDL_IOReady(ConnectionNumber(display), SDL_FALSE, 0)) {
+ if (SDL_IOReady(ConnectionNumber(display), SDL_IOR_READ, 0)) {
return (X11_XPending(display));
}
@@ -1586,7 +1586,7 @@ X11_WaitEventTimeout(_THIS, int timeout)
return 0;
}
} else if (timeout > 0) {
- if (SDL_IOReady(ConnectionNumber(display), SDL_FALSE, timeout) > 0) {
+ if (SDL_IOReady(ConnectionNumber(display), SDL_IOR_READ, timeout) > 0) {
X11_XNextEvent(display, &xevent);
} else {
return 0;