From: Guy Harris Date: Sat, 20 Jan 2018 09:43:11 +0000 (-0800) Subject: Reduce the noise level with non-selectable devices. X-Git-Tag: libpcap-1.9-bp~288 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/0f69ec44959452bfa2653361442f07efa3ab927f?ds=inline Reduce the noise level with non-selectable devices. --- diff --git a/tests/selpolltest.c b/tests/selpolltest.c index 3e48447a..614056d9 100644 --- a/tests/selpolltest.c +++ b/tests/selpolltest.c @@ -215,17 +215,18 @@ main(int argc, char **argv) printf("Select returns error (%s)\n", strerror(errno)); } else { - if (status == 0) - printf("Select timed out"); - else - printf("Select returned a descriptor"); - if (selectable_fd == -1) - printf("\n"); - else { + if (selectable_fd == -1) { + if (status != 0) + printf("Select returned a descriptor\n"); + } else { + if (status == 0) + printf("Select timed out: "); + else + printf("Select returned a descriptor: "); if (FD_ISSET(selectable_fd, &setread)) - printf(": readable, "); + printf("readable, "); else - printf(": not readable, "); + printf("not readable, "); if (FD_ISSET(selectable_fd, &setexcept)) printf("exceptional condition\n"); else @@ -236,8 +237,18 @@ main(int argc, char **argv) (u_char *)&packet_count); if (status < 0) break; - printf("%d packets seen, %d packets counted after select returns\n", - status, packet_count); + /* + * Don't report this if we're using a + * required timeout and we got no packets, + * because that could be a very short timeout, + * and we don't want to spam the user with + * a ton of "no packets" reports. + */ + if (status != 0 || packet_count != 0 || + selectable_fd != -1) { + printf("%d packets seen, %d packets counted after select returns\n", + status, packet_count); + } } } } else if (dopoll) { @@ -259,34 +270,49 @@ main(int argc, char **argv) printf("Poll returns error (%s)\n", strerror(errno)); } else { - if (status == 0) - printf("Poll timed out\n"); - else { - printf("Poll returned a descriptor: "); - if (fd.revents & POLLIN) - printf("readable, "); - else - printf("not readable, "); - if (fd.revents & POLLERR) - printf("exceptional condition, "); - else - printf("no exceptional condition, "); - if (fd.revents & POLLHUP) - printf("disconnect, "); - else - printf("no disconnect, "); - if (fd.revents & POLLNVAL) - printf("invalid\n"); - else - printf("not invalid\n"); + if (selectable_fd == -1) { + if (status != 0) + printf("Poll returned a descriptor\n"); + } else { + if (status == 0) + printf("Poll timed out\n"); + else { + printf("Poll returned a descriptor: "); + if (fd.revents & POLLIN) + printf("readable, "); + else + printf("not readable, "); + if (fd.revents & POLLERR) + printf("exceptional condition, "); + else + printf("no exceptional condition, "); + if (fd.revents & POLLHUP) + printf("disconnect, "); + else + printf("no disconnect, "); + if (fd.revents & POLLNVAL) + printf("invalid\n"); + else + printf("not invalid\n"); + } } packet_count = 0; status = pcap_dispatch(pd, -1, countme, (u_char *)&packet_count); if (status < 0) break; - printf("%d packets seen, %d packets counted after poll returns\n", - status, packet_count); + /* + * Don't report this if we're using a + * required timeout and we got no packets, + * because that could be a very short timeout, + * and we don't want to spam the user with + * a ton of "no packets" reports. + */ + if (status != 0 || packet_count != 0 || + selectable_fd != -1) { + printf("%d packets seen, %d packets counted after poll returns\n", + status, packet_count); + } } } } else {