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

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