]> The Tcpdump Group git mirrors - libpcap/commitdiff
In memory-mapped mode, when turning non-blocking mode on when it's off,
authorGuy Harris <[email protected]>
Mon, 6 Jul 2009 18:35:52 +0000 (11:35 -0700)
committerGuy Harris <[email protected]>
Mon, 6 Jul 2009 18:35:52 +0000 (11:35 -0700)
map all non-negative timeouts, including 0, to negative values, so that,
even with no timeout set, non-blocking mode will skip the poll() call.

pcap-linux.c

index 6fe7a24f349f0076fcd7fb806f101667a7a96b85..4165eba0826f7d1c72ec5aadd4e96b78a5219a44 100644 (file)
@@ -2714,11 +2714,26 @@ pcap_setnonblock_mmap(pcap_t *p, int nonblock, char *errbuf)
        /* map each value to the corresponding 2's complement, to 
         * preserve the timeout value provided with pcap_set_timeout */
        if (nonblock) {
-               if (p->md.timeout > 0)
+               if (p->md.timeout >= 0) {
+                       /*
+                        * Timeout is non-negative, so we're not already
+                        * in non-blocking mode; set it to the 2's
+                        * complement, to make it negative, as an
+                        * indication that we're in non-blocking mode.
+                        */
                        p->md.timeout = p->md.timeout*-1 - 1;
-       } else 
-               if (p->md.timeout < 0)
+               }
+       } else {
+               if (p->md.timeout < 0) {
+                       /*
+                        * Timeout is negative, so we're not already
+                        * in blocking mode; reverse the previous
+                        * operation, to make the timeout non-negative
+                        * again.
+                        */
                        p->md.timeout = (p->md.timeout+1)*-1;
+               }
+       }
        return 0;
 }