core: Convert SDL_IOReady()'s 2nd parameter to flags

This commit is contained in:
Cameron Gutman 2021-10-30 15:56:54 -05:00 committed by Sam Lantinga
parent 81fe2ccb9c
commit c97c46877f
9 changed files with 30 additions and 21 deletions

View file

@ -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

View file

@ -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));

View file

@ -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
}

View file

@ -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;

View file

@ -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_ */

View file

@ -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");

View file

@ -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);

View file

@ -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;

View file

@ -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;