face: put the pcap handle in non-blocking mode
This prevents NFD from getting stuck in pcap_next_ex() when the network interface goes down Change-Id: I5760fcc7c950b46aecb7619bd889508ee24133aa
This commit is contained in:
1 parent
6b78a53cf7
commit
0b0156887b
2 files changed
+6
-2
No files matched your search
@@ -167,7 +167,7 @@ EthernetTransport::handleRead(const boost::system::error_code& error)
|
||||
|
||||
auto [pkt, readErr] = m_pcap.readNextPacket();
|
||||
if (pkt.empty()) {
|
||||
NFD_LOG_FACE_WARN("Read error: " << readErr);
|
||||
NFD_LOG_FACE_DEBUG("Read error: " << readErr);
|
||||
}
|
||||
else {
|
||||
auto [eh, frameErr] = ethernet::checkFrameHeader(pkt, m_srcAddress,
|
||||
|
||||
@@ -69,6 +69,10 @@ PcapHelper::activate(int dlt)
|
||||
NDN_THROW(Error("pcap_activate: " + std::string(pcap_statustostr(ret))));
|
||||
});
|
||||
|
||||
char errbuf[PCAP_ERRBUF_SIZE] = {};
|
||||
if (pcap_setnonblock(m_pcap, 1, errbuf) < 0)
|
||||
NDN_THROW(Error("pcap_setnonblock: " + std::string(errbuf)));
|
||||
|
||||
if (pcap_set_datalink(m_pcap, dlt) < 0)
|
||||
NDN_THROW(Error("pcap_set_datalink: " + getLastError()));
|
||||
|
||||
@@ -136,7 +140,7 @@ PcapHelper::readNextPacket() const noexcept
|
||||
if (ret < 0)
|
||||
return {span<uint8_t>{}, getLastError()};
|
||||
else if (ret == 0)
|
||||
return {span<uint8_t>{}, "timed out"};
|
||||
return {span<uint8_t>{}, "Nothing to read"};
|
||||
else
|
||||
return {{packet, header->caplen}, ""};
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user