65{
66#define FDNO 3
68 int rdblocker[2];
69#if FDNO > 3
70 int wrblocker[2], consec_interrupt = 0;
71#endif
72 struct pollfd pfd[4] = { { .events = POLLOUT, }, { .events = POLLIN, }, { .events = POLLIN }, { .events = POLLOUT } };
73 pthread_t failsafe_tid;
74 struct timeval tv = { 0, 0 };
75#if FDNO > 3
76 char garbage[256] =
77 "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ@/"
78 "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ@/"
79 "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ@/"
80 "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ@/";
81#endif
82
83 switch (cmd) {
85 info->name =
"poll_test";
86 info->category =
"/main/poll/";
87 info->summary =
"unit test for the ast_poll() API";
89 "Verifies behavior for the ast_poll() API call";
92 break;
93 }
94
96 if ((fd[0] = open("/dev/null", O_WRONLY)) < 0) {
99 }
100
102 if ((fd[1] = open("/dev/zero", O_RDONLY)) < 0) {
104 close(fd[0]);
106 }
107
109 if (pipe(rdblocker) < 0) {
111 close(fd[0]);
112 close(fd[1]);
114 }
115
116#if FDNO > 3
118 if (pipe(wrblocker) < 0) {
120 close(fd[0]);
121 close(fd[1]);
122 close(rdblocker[0]);
123 close(rdblocker[1]);
125 }
126
130 close(fd[0]);
131 close(fd[1]);
132 close(fd[2]);
133 close(rdblocker[0]);
134 close(rdblocker[1]);
135 close(wrblocker[0]);
136 close(wrblocker[1]);
138 }
139
140
142 for (i = 0; i < 4096; i++) {
144 if (write(wrblocker[1], garbage, sizeof(garbage)) < sizeof(garbage)) {
146 if (
errno == EINTR && ++consec_interrupt > 1) {
147 break;
148 }
149 } else {
150 consec_interrupt = 0;
151 }
152 }
153
155 pthread_cancel(failsafe_tid);
156 pthread_kill(failsafe_tid, SIGURG);
157 pthread_join(failsafe_tid,
NULL);
158#endif
159
160 pfd[0].fd = fd[0];
161 pfd[1].fd = fd[1];
162 pfd[2].fd = rdblocker[0];
163#if FDNO > 3
164 pfd[3].fd = wrblocker[1];
165#endif
166
167
171 close(fd[0]);
172 close(fd[1]);
173 close(rdblocker[0]);
174 close(rdblocker[1]);
175#if FDNO > 3
176 close(wrblocker[0]);
177 close(wrblocker[1]);
178#endif
180 }
181
184 ast_test_status_update(
test,
"ast_poll does not return that only two handles are available (inf timeout): %d, %s\n", res2, res2 == -1 ? strerror(
errno) :
"");
186 }
187
190 ast_test_status_update(
test,
"ast_poll2 does not return that only two handles are available (inf timeout): %d %s\n", res2, res2 == -1 ? strerror(
errno) :
"");
192 }
193
195 pthread_cancel(failsafe_tid);
196 pthread_kill(failsafe_tid, SIGURG);
197 pthread_join(failsafe_tid,
NULL);
198
201 ast_test_status_update(
test,
"ast_poll does not return that only two handles are available (0 timeout): %d, %s\n", res2, res2 == -1 ? strerror(
errno) :
"");
203 }
204
207 ast_test_status_update(
test,
"ast_poll2 does not return that only two handles are available (0 timeout): %d, %s\n", res2, res2 == -1 ? strerror(
errno) :
"");
209 }
210
213 ast_test_status_update(
test,
"ast_poll does not return that only two handles are available (1ms timeout): %d, %s\n", res2, res2 == -1 ? strerror(
errno) :
"");
215 }
216
217 tv.tv_usec = 1000;
219 ast_test_status_update(
test,
"ast_poll2 does not return that only two handles are available (1ms timeout): %d, %s\n", res2, res2 == -1 ? strerror(
errno) :
"");
221 }
222
223 close(fd[0]);
224 close(fd[1]);
225 close(rdblocker[0]);
226 close(rdblocker[1]);
227#if FDNO > 3
228 close(wrblocker[0]);
229 close(wrblocker[1]);
230#endif
231 return res;
232}
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...
#define ast_poll(a, b, c)
#define ast_test_status_update(a, b, c...)
static void * failsafe_cancel(void *vparent)
#define ast_pthread_create_background(a, b, c, d)