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

References NULL, and SDL_assert.

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