SDL  2.0
SDL_poll.c File Reference
#include "../../SDL_internal.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

◆ SDL_IOReady()

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

Definition at line 37 of file SDL_poll.c.

38 {
39  int result;
40 
41  /* Note: We don't bother to account for elapsed time if we get EINTR */
42  do
43  {
44 #ifdef HAVE_POLL
45  struct pollfd info;
46 
47  info.fd = fd;
48  if (forWrite) {
49  info.events = POLLOUT;
50  } else {
51  info.events = POLLIN | POLLPRI;
52  }
53  result = poll(&info, 1, timeoutMS);
54 #else
55  fd_set rfdset, *rfdp = NULL;
56  fd_set wfdset, *wfdp = NULL;
57  struct timeval tv, *tvp = NULL;
58 
59  /* If this assert triggers we'll corrupt memory here */
60  SDL_assert(fd >= 0 && fd < FD_SETSIZE);
61 
62  if (forWrite) {
63  FD_ZERO(&wfdset);
64  FD_SET(fd, &wfdset);
65  wfdp = &wfdset;
66  } else {
67  FD_ZERO(&rfdset);
68  FD_SET(fd, &rfdset);
69  rfdp = &rfdset;
70  }
71 
72  if (timeoutMS >= 0) {
73  tv.tv_sec = timeoutMS / 1000;
74  tv.tv_usec = (timeoutMS % 1000) * 1000;
75  tvp = &tv;
76  }
77 
78  result = select(fd + 1, rfdp, wfdp, NULL, tvp);
79 #endif /* HAVE_POLL */
80 
81  } while ( result < 0 && errno == EINTR );
82 
83  return result;
84 }
#define SDL_assert(condition)
Definition: SDL_assert.h:171
GLuint64EXT * result
#define NULL
Definition: begin_code.h:163
GLuint64 GLenum GLint fd
Definition: gl2ext.h:1508

References NULL, and SDL_assert.