handlep->device = NULL;
}
- close(handlep->poll_breakloop_fd);
+ if (handlep->poll_breakloop_fd != -1) {
+ close(handlep->poll_breakloop_fd);
+ handlep->poll_breakloop_fd = -1;
+ }
pcap_cleanup_live_common(handle);
}
uint64_t value = 1;
/* XXX - what if this fails? */
- (void)write(handlep->poll_breakloop_fd, &value, sizeof(value));
+ if (handlep->poll_breakloop_fd != -1)
+ (void)write(handlep->poll_breakloop_fd, &value, sizeof(value));
}
/*
* capture on them, "why do no interfaces show up?" - when the
* real problem is a permissions problem. Error reports of that
* type require a lot more back-and-forth to debug, as evidenced
- * by many Wireshark bugs/mailing list questions/Q&A questoins.)
+ * by many Wireshark bugs/mailing list questions/Q&A questions.)
*
* So:
*
*/
handlep->timeout = ~handlep->timeout;
}
+ if (handlep->poll_breakloop_fd != -1) {
+ /* Close the eventfd; we do not need it in nonblock mode. */
+ close(handlep->poll_breakloop_fd);
+ handlep->poll_breakloop_fd = -1;
+ }
} else {
+ if (handlep->poll_breakloop_fd == -1) {
+ /* If we did not have an eventfd, open one now that we are blocking. */
+ if ( ( handlep->poll_breakloop_fd = eventfd(0, EFD_NONBLOCK) ) == -1 ) {
+ int save_errno = errno;
+ snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
+ "Could not open eventfd: %s",
+ strerror(errno));
+ errno = save_errno;
+ return -1;
+ }
+ }
if (handlep->timeout < 0) {
handlep->timeout = ~handlep->timeout;
}
struct ifreq ifr;
int ret;
struct pollfd pollinfo[2];
+ int numpollinfo;
pollinfo[0].fd = handle->fd;
pollinfo[0].events = POLLIN;
- pollinfo[1].fd = handlep->poll_breakloop_fd;
- pollinfo[1].events = POLLIN;
+ if ( handlep->poll_breakloop_fd == -1 ) {
+ numpollinfo = 1;
+ pollinfo[1].revents = 0;
+ /*
+ * We set pollinfo[1].revents to zero, even though
+ * numpollinfo = 1 meaning that poll() doesn't see
+ * pollinfo[1], so that we do not have to add a
+ * conditional of numpollinfo > 1 below when we
+ * test pollinfo[1].revents.
+ */
+ } else {
+ pollinfo[1].fd = handlep->poll_breakloop_fd;
+ pollinfo[1].events = POLLIN;
+ numpollinfo = 2;
+ }
/*
* Keep polling until we either get some packets to read, see
if (timeout != 0)
timeout = 1;
}
- ret = poll(pollinfo, 2, timeout);
+ ret = poll(pollinfo, numpollinfo, timeout);
if (ret < 0) {
/*
* Error. If it's not EINTR, report it.
} else {
/*
* Clear CANFD_FDF if it's set (probably
- * again meaning that that field is
+ * again meaning that this field is
* uninitialized junk).
*/
canhdr->fd_flags &= ~CANFD_FDF;
findalldevstest-perf.c \
findalldevstest.c \
opentest.c \
+ nonblocktest.c \
reactivatetest.c \
selpolltest.c \
threadsignaltest.c \
capturetest: $(srcdir)/capturetest.c ../libpcap.a
$(CC) $(FULL_CFLAGS) -I. -L. -o capturetest $(srcdir)/capturetest.c \
- ../libpcap.a $(LIBS)
+ ../libpcap.a $(LIBS)
can_set_rfmon_test: $(srcdir)/can_set_rfmon_test.c ../libpcap.a
$(CC) $(FULL_CFLAGS) -I. -L. -o can_set_rfmon_test \
$(CC) $(FULL_CFLAGS) -I. -L. -o opentest $(srcdir)/opentest.c \
../libpcap.a $(LIBS)
+ nonblocktest: $(srcdir)/nonblocktest.c ../libpcap.a
+ $(CC) $(FULL_CFLAGS) -I. -L. -o nonblocktest $(srcdir)/nonblocktest.c \
+ ../libpcap.a $(LIBS)
+
reactivatetest: $(srcdir)/reactivatetest.c ../libpcap.a
$(CC) $(FULL_CFLAGS) -I. -L. -o reactivatetest \
$(srcdir)/reactivatetest.c ../libpcap.a $(LIBS)