70 int wrblocker[2], consec_interrupt = 0;
72 struct pollfd pfd[4] = { { .events = POLLOUT, }, { .events = POLLIN, }, { .events = POLLIN }, { .events = POLLOUT } };
73 pthread_t failsafe_tid;
74 struct timeval tv = { 0, 0 };
77 "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ@/" 78 "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ@/" 79 "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ@/" 80 "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ@/";
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";
96 if ((fd[0] = open(
"/dev/null", O_WRONLY)) < 0) {
102 if ((fd[1] = open(
"/dev/zero", O_RDONLY)) < 0) {
109 if (pipe(rdblocker) < 0) {
118 if (pipe(wrblocker) < 0) {
142 for (i = 0; i < 4096; i++) {
144 if (write(wrblocker[1], garbage,
sizeof(garbage)) <
sizeof(garbage)) {
146 if (
errno == EINTR && ++consec_interrupt > 1) {
150 consec_interrupt = 0;
155 pthread_cancel(failsafe_tid);
156 pthread_kill(failsafe_tid, SIGURG);
157 pthread_join(failsafe_tid,
NULL);
162 pfd[2].fd = rdblocker[0];
164 pfd[3].fd = wrblocker[1];
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) :
"");
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) :
"");
195 pthread_cancel(failsafe_tid);
196 pthread_kill(failsafe_tid, SIGURG);
197 pthread_join(failsafe_tid,
NULL);
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) :
"");
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) :
"");
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) :
"");
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) :
"");
#define ast_pthread_create_background(a, b, c, d)
#define ast_test_status_update(a, b, c...)
#define ast_poll(a, b, c)
static void * failsafe_cancel(void *vparent)
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...