aboutsummaryrefslogtreecommitdiffstats
path: root/pcap-linux.c
diff options
context:
space:
mode:
authorGuy Harris <gharris@steve.local>2009-07-06 11:35:52 -0700
committerGuy Harris <gharris@steve.local>2009-07-06 11:35:52 -0700
commit1f14841bc0e0123b966e81e35201c8e6691cf0f1 (patch)
tree682de7b599d9c11fc4a52bdef81fafeb68a53309 /pcap-linux.c
parentffe20c46cbd4496ef17636186470d395272b4d30 (diff)
In memory-mapped mode, when turning non-blocking mode on when it's off,
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.
Diffstat (limited to 'pcap-linux.c')
-rw-r--r--pcap-linux.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/pcap-linux.c b/pcap-linux.c
index 6fe7a24..4165eba 100644
--- a/pcap-linux.c
+++ b/pcap-linux.c
@@ -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;
}