SDL  2.0
SDL_poll.c File Reference
#include "../../SDL_internal.h"
#include "SDL_assert.h"
#include "SDL_poll.h"
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
+ Include dependency graph for SDL_poll.c:

Go to the source code of this file.

Functions

int SDL_IOReady (int fd, SDL_bool forWrite, int timeoutMS)

Function Documentation

int SDL_IOReady ( int  fd,
SDL_bool  forWrite,
int  timeoutMS 
)

Definition at line 38 of file SDL_poll.c.

References NULL, and SDL_assert.

{
int result;
/* Note: We don't bother to account for elapsed time if we get EINTR */
do
{
#ifdef HAVE_POLL
struct pollfd info;
info.fd = fd;
if (forWrite) {
info.events = POLLOUT;
} else {
info.events = POLLIN | POLLPRI;
}
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 (forWrite) {
FD_ZERO(&wfdset);
FD_SET(fd, &wfdset);
wfdp = &wfdset;
} else {
FD_ZERO(&rfdset);
FD_SET(fd, &rfdset);
rfdp = &rfdset;
}
if (timeoutMS >= 0) {
tv.tv_sec = timeoutMS / 1000;
tv.tv_usec = (timeoutMS % 1000) * 1000;
tvp = &tv;
}
result = select(fd + 1, rfdp, wfdp, NULL, tvp);
#endif /* HAVE_POLL */
} while ( result < 0 && errno == EINTR );
return result;
}