From 1f14841bc0e0123b966e81e35201c8e6691cf0f1 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Mon, 6 Jul 2009 11:35:52 -0700 Subject: 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. --- pcap-linux.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'pcap-linux.c') 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; } -- cgit v1.2.3