77 #include <sys/types.h> 89 #define MAX(a,b) a > b ? a : b 96 #if defined(AST_POLL_COMPAT) 97 static int map_poll_spec(
struct pollfd *pArray,
unsigned long n_fds,
100 register unsigned long i;
101 register struct pollfd *pCur;
102 register int max_fd = -1;
108 for (i = 0, pCur = pArray; i < n_fds; i++, pCur++) {
115 if (pCur->events & POLLIN) {
117 FD_SET(pCur->fd, pReadSet);
120 if (pCur->events & POLLOUT) {
122 FD_SET(pCur->fd, pWriteSet);
125 if (pCur->events & POLLPRI) {
130 FD_SET(pCur->fd, pExceptSet);
133 max_fd =
MAX(max_fd, pCur->fd);
139 #ifdef AST_POLL_COMPAT 140 static struct timeval *map_timeout(
int poll_timeout,
struct timeval *pSelTimeout)
142 struct timeval *pResult;
159 assert(pSelTimeout !=
NULL);
161 switch (poll_timeout) {
166 pResult = (
struct timeval *)
NULL;
174 pSelTimeout->tv_sec = 0;
175 pSelTimeout->tv_usec = 0;
176 pResult = pSelTimeout;
181 pSelTimeout->tv_sec = poll_timeout / 1000;
182 poll_timeout %= 1000;
183 pSelTimeout->tv_usec = poll_timeout * 1000;
184 pResult = pSelTimeout;
192 static void map_select_results(
struct pollfd *pArray,
unsigned long n_fds,
195 register unsigned long i;
196 register struct pollfd *pCur;
198 for (i = 0, pCur = pArray; i < n_fds; i++, pCur++) {
207 if (FD_ISSET(pCur->fd, (fd_set *) pExceptSet)) {
208 pCur->revents |= POLLPRI;
209 }
else if (FD_ISSET(pCur->fd, (fd_set *) pReadSet)) {
210 pCur->revents |= POLLIN;
213 if (FD_ISSET(pCur->fd, (fd_set *) pWriteSet)) {
214 pCur->revents |= POLLOUT;
225 #ifdef AST_POLL_COMPAT 226 int ast_internal_poll(
struct pollfd *pArray,
unsigned long n_fds,
int timeout)
231 struct timeval stime;
232 int ready_descriptors;
234 struct timeval *pTimeout;
244 max_fd = map_poll_spec (pArray, n_fds,
245 &read_descs, &write_descs, &except_descs);
250 pTimeout = map_timeout (timeout, &stime);
254 ready_descriptors =
ast_select(max_fd + 1, &read_descs, &write_descs,
255 &except_descs, pTimeout);
258 if (ready_descriptors >= 0) {
259 map_select_results (pArray, n_fds,
260 &read_descs, &write_descs, &except_descs);
264 return ready_descriptors;
268 int ast_poll2(
struct pollfd *pArray,
unsigned long n_fds,
struct timeval *tv)
270 #if !defined(AST_POLL_COMPAT) 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);
276 int res = poll(pArray, n_fds, tv ? tv->tv_sec * 1000 + tv->tv_usec / 1000 : -1);
281 }
else if (res > 0 && tv) {
286 ast_fdset read_descs, write_descs, except_descs;
287 int ready_descriptors, max_fd = 0;
294 max_fd = map_poll_spec(pArray, n_fds, &read_descs, &write_descs, &except_descs);
297 ready_descriptors =
ast_select(max_fd + 1, &read_descs, &write_descs, &except_descs, tv);
299 if (ready_descriptors >= 0) {
300 map_select_results(pArray, n_fds, &read_descs, &write_descs, &except_descs);
303 return ready_descriptors;
Asterisk main include file. File version handling, generic pbx functions.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
unsigned int ast_FD_SETSIZE
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.
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 indi...
struct timeval ast_tvadd(struct timeval a, struct timeval b)
Returns the sum of two timevals a + b.
struct timeval ast_tv(ast_time_t sec, ast_suseconds_t usec)
Returns a timeval from sec, usec.
struct timeval ast_tvsub(struct timeval a, struct timeval b)
Returns the difference of two timevals a - b.