]> The Tcpdump Group git mirrors - libpcap/commitdiff
Reduce the noise level with non-selectable devices.
authorGuy Harris <[email protected]>
Sat, 20 Jan 2018 09:43:11 +0000 (01:43 -0800)
committerGuy Harris <[email protected]>
Sat, 20 Jan 2018 09:43:11 +0000 (01:43 -0800)
tests/selpolltest.c

index 3e48447a3901e0dc94f34fb42491b5c8eeaf4c76..614056d9a09c5d4319ef2ce8559ecdc405872f80 100644 (file)
@@ -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 {