SDL  2.0
SDL_poll.h File Reference
#include "../../SDL_internal.h"
#include "SDL_stdinc.h"
+ Include dependency graph for SDL_poll.h:
+ This graph shows which files directly or indirectly include this file:

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 38 of file SDL_poll.c.

References NULL, and SDL_assert.

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