Asterisk - The Open Source Telephony Project  18.5.0
Macros | Functions
poll-compat.h File Reference
#include "asterisk/select.h"
#include <poll.h>
Include dependency graph for poll-compat.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ast_poll(a, b, c)   poll(a, b, c)
 

Functions

int ast_poll2 (struct pollfd *pArray, unsigned long n_fds, struct timeval *tv)
 Same as poll(2), except the time is specified in microseconds and the tv argument is modified to indicate the time remaining. More...
 
static int ast_poll_fd_index (struct pollfd *haystack, int nfds, int needle)
 Shortcut for conversion of FD_ISSET to poll(2)-based. More...
 

Macro Definition Documentation

◆ ast_poll

#define ast_poll (   a,
  b,
  c 
)    poll(a, b, c)

Function Documentation

◆ ast_poll2()

int ast_poll2 ( struct pollfd *  pArray,
unsigned long  n_fds,
struct timeval *  tv 
)

Same as poll(2), except the time is specified in microseconds and the tv argument is modified to indicate the time remaining.

Definition at line 268 of file poll.c.

References ast_select(), ast_tv(), ast_tvadd(), ast_tvdiff_ms(), ast_tvnow(), ast_tvsub(), FD_ZERO, and NULL.

Referenced by AST_TEST_DEFINE(), and do_monitor().

269 {
270 #if !defined(AST_POLL_COMPAT)
271  struct timeval start = ast_tvnow();
272 #if defined(HAVE_PPOLL)
273  struct timespec ts = { tv ? tv->tv_sec : 0, tv ? tv->tv_usec * 1000 : 0 };
274  int res = ppoll(pArray, n_fds, tv ? &ts : NULL, NULL);
275 #else
276  int res = poll(pArray, n_fds, tv ? tv->tv_sec * 1000 + tv->tv_usec / 1000 : -1);
277 #endif
278  struct timeval after = ast_tvnow();
279  if (res > 0 && tv && ast_tvdiff_ms(ast_tvadd(*tv, start), after) > 0) {
280  *tv = ast_tvsub(*tv, ast_tvsub(after, start));
281  } else if (res > 0 && tv) {
282  *tv = ast_tv(0, 0);
283  }
284  return res;
285 #else
286  ast_fdset read_descs, write_descs, except_descs;
287  int ready_descriptors, max_fd = 0;
288 
289  FD_ZERO(&read_descs);
290  FD_ZERO(&write_descs);
291  FD_ZERO(&except_descs);
292 
293  if (pArray) {
294  max_fd = map_poll_spec(pArray, n_fds, &read_descs, &write_descs, &except_descs);
295  }
296 
297  ready_descriptors = ast_select(max_fd + 1, &read_descs, &write_descs, &except_descs, tv);
298 
299  if (ready_descriptors >= 0) {
300  map_select_results(pArray, n_fds, &read_descs, &write_descs, &except_descs);
301  }
302 
303  return ready_descriptors;
304 #endif
305 }
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition: time.h:98
#define NULL
Definition: resample.c:96
#define FD_ZERO(a)
Definition: select.h:49
static int ast_select(int nfds, ast_fdset *rfds, ast_fdset *wfds, ast_fdset *efds, struct timeval *tvp)
Waits for activity on a group of channels.
Definition: select.h:79
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
Definition: extconf.c:2283
struct timeval ast_tv(ast_time_t sec, ast_suseconds_t usec)
Returns a timeval from sec, usec.
Definition: time.h:226
struct timeval ast_tvsub(struct timeval a, struct timeval b)
Returns the difference of two timevals a - b.
Definition: extconf.c:2298

◆ ast_poll_fd_index()

static int ast_poll_fd_index ( struct pollfd *  haystack,
int  nfds,
int  needle 
)
inlinestatic

Shortcut for conversion of FD_ISSET to poll(2)-based.

Definition at line 128 of file poll-compat.h.

Referenced by do_pktccops().

129 {
130  int i;
131  for (i = 0; i < nfds; i++) {
132  if (haystack[i].fd == needle) {
133  return i;
134  }
135  }
136  return -1;
137 }