Asterisk - The Open Source Telephony Project GIT-master-f36a736
poll-compat.h
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * See http://www.asterisk.org for more information about
5 * the Asterisk project. Please do not directly contact
6 * any of the maintainers of this project for assistance;
7 * the project provides a web site, mailing lists and IRC
8 * channels for your use.
9 */
10
11/*---------------------------------------------------------------------------*\
12 $Id$
13
14 NAME
15
16 poll - select(2)-based poll() emulation function for BSD systems.
17
18 SYNOPSIS
19 #include "poll.h"
20
21 struct pollfd
22 {
23 int fd;
24 short events;
25 short revents;
26 }
27
28 int poll (struct pollfd *pArray, unsigned long n_fds, int timeout)
29
30 DESCRIPTION
31
32 This file, and the accompanying "poll.c", implement the System V
33 poll(2) system call for BSD systems (which typically do not provide
34 poll()). Poll() provides a method for multiplexing input and output
35 on multiple open file descriptors; in traditional BSD systems, that
36 capability is provided by select(). While the semantics of select()
37 differ from those of poll(), poll() can be readily emulated in terms
38 of select() -- which is how this function is implemented.
39
40 REFERENCES
41 Stevens, W. Richard. Unix Network Programming. Prentice-Hall, 1990.
42
43 NOTES
44 1. This software requires an ANSI C compiler.
45
46 LICENSE
47
48 This software is released under the following license:
49
50 Copyright (c) 1995-2002 Brian M. Clapper
51 All rights reserved.
52
53 Redistribution and use in source and binary forms are
54 permitted provided that: (1) source distributions retain
55 this entire copyright notice and comment; (2) modifications
56 made to the software are prominently mentioned, and a copy
57 of the original software (or a pointer to its location) are
58 included; and (3) distributions including binaries display
59 the following acknowledgement: "This product includes
60 software developed by Brian M. Clapper <bmc@clapper.org>"
61 in the documentation or other materials provided with the
62 distribution. The name of the author may not be used to
63 endorse or promote products derived from this software
64 without specific prior written permission.
65
66 THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS
67 OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE
68 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
69 PARTICULAR PURPOSE.
70
71 Effectively, this means you can do what you want with the software
72 except remove this notice or take advantage of the author's name.
73 If you modify the software and redistribute your modified version,
74 you must indicate that your version is a modification of the
75 original, and you must provide either a pointer to or a copy of the
76 original.
77\*---------------------------------------------------------------------------*/
78
79#ifndef __AST_POLL_COMPAT_H
80#define __AST_POLL_COMPAT_H
81
82#include "asterisk/select.h"
83
84#ifndef AST_POLL_COMPAT
85
86#include <poll.h>
87
88#define ast_poll(a, b, c) poll(a, b, c)
89
90#else /* AST_POLL_COMPAT */
91
92#define POLLIN 0x01
93#define POLLPRI 0x02
94#define POLLOUT 0x04
95#define POLLERR 0x08
96#define POLLHUP 0x10
97#define POLLNVAL 0x20
98
99struct pollfd {
100 int fd;
101 short events;
102 short revents;
103};
104
105#ifdef __cplusplus
106extern "C" {
107#endif
108
109#define ast_poll(a, b, c) ast_internal_poll(a, b, c)
110
111int ast_internal_poll(struct pollfd *pArray, unsigned long n_fds, int timeout);
112
113#ifdef __cplusplus
114}
115#endif
116
117#endif /* AST_POLL_COMPAT */
118
119/*!
120 * \brief Same as poll(2), except the time is specified in microseconds and
121 * the tv argument is modified to indicate the time remaining.
122 */
123int ast_poll2(struct pollfd *pArray, unsigned long n_fds, struct timeval *tv);
124
125/*!
126 * \brief Shortcut for conversion of FD_ISSET to poll(2)-based
127 */
128static inline int ast_poll_fd_index(struct pollfd *haystack, int nfds, int needle)
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}
138
139#endif /* __AST_POLL_COMPAT_H */
static const struct adsi_event events[]
Definition: app_adsiprog.c:85
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...
Definition: poll.c:268
static int ast_poll_fd_index(struct pollfd *haystack, int nfds, int needle)
Shortcut for conversion of FD_ISSET to poll(2)-based.
Definition: poll-compat.h:128
Bitfield expansions for ast_select.