Added error checking and removed some redundancy from device isOpen()

This commit is contained in:
EricLiu2000
2019-06-13 16:01:35 -04:00
parent 2806c935f1
commit 965679c370
8 changed files with 73 additions and 35 deletions
+12 -4
View File
@@ -194,14 +194,20 @@ PCAP::PCAP(const device_errorhandler_t& err, neodevice_t& forDevice) : ICommunic
}
bool PCAP::open() {
if(!openable)
if(!openable) {
err(APIError::InvalidNeoDevice);
return false;
}
if(!pcap.ok())
if(!pcap.ok()) {
err(APIError::DriverFailedToOpen);
return false;
}
if(isOpen())
if(isOpen()) {
err(APIError::DeviceCurrentlyOpen);
return false;
}
// Open the interface
interface.fp = pcap.open(interface.nameFromWinPCAP.c_str(), 100, PCAP_OPENFLAG_PROMISCUOUS | PCAP_OPENFLAG_MAX_RESPONSIVENESS, 1, nullptr, errbuf);
@@ -222,8 +228,10 @@ bool PCAP::isOpen() {
}
bool PCAP::close() {
if(!isOpen())
if(!isOpen()) {
err(APIError::DeviceCurrentlyClosed);
return false;
}
closing = true; // Signal the threads that we are closing
readThread.join();