Thu Apr 28 2011 16:57:15

Asterisk developer's documentation


poll.c File Reference

#include "asterisk.h"
#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>
#include <assert.h>
#include <string.h>
#include <errno.h>
#include "asterisk/utils.h"
#include "asterisk/poll-compat.h"
Include dependency graph for poll.c:

Go to the source code of this file.

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.

Variables

unsigned int ast_FD_SETSIZE = FD_SETSIZE

Function Documentation

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 264 of file poll.c.

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

Referenced by do_monitor().

{
#if !defined(AST_POLL_COMPAT)
   struct timeval start = ast_tvnow();
#if defined(HAVE_PPOLL)
   struct timespec ts = { tv ? tv->tv_sec : 0, tv ? tv->tv_usec * 1000 : 0 };
   int res = ppoll(pArray, n_fds, tv ? &ts : NULL, NULL);
#else
   int res = poll(pArray, n_fds, tv ? tv->tv_sec * 1000 + tv->tv_usec / 1000 : -1);
#endif
   struct timeval after = ast_tvnow();
   if (res > 0 && tv && ast_tvdiff_ms(ast_tvadd(*tv, start), after) > 0) {
      *tv = ast_tvsub(*tv, ast_tvsub(after, start));
   } else if (res > 0 && tv) {
      *tv = ast_tv(0, 0);
   }
   return res;
#else
   ast_fdset read_descs, write_descs, except_descs;
   int ready_descriptors, max_fd = 0;

   FD_ZERO(&read_descs);
   FD_ZERO(&write_descs);
   FD_ZERO(&except_descs);

   if (pArray) {
      max_fd = map_poll_spec(pArray, n_fds, &read_descs, &write_descs, &except_descs);
   }

   ready_descriptors = ast_select(max_fd + 1, &read_descs, &write_descs, &except_descs, tv);

   if (ready_descriptors >= 0) {
      map_select_results(pArray, n_fds, &read_descs, &write_descs, &except_descs);
   }

   return ready_descriptors;
#endif
}

Variable Documentation

unsigned int ast_FD_SETSIZE = FD_SETSIZE

Definition at line 86 of file poll.c.

Referenced by main().