Fixed crash on drone exit (on Windows) - now we do cleanup
This commit is contained in:
parent
763219e153
commit
c9a7523ef9
@ -127,10 +127,22 @@ void PcapPort::init()
|
|||||||
PcapPort::~PcapPort()
|
PcapPort::~PcapPort()
|
||||||
{
|
{
|
||||||
qDebug("In %s", __FUNCTION__);
|
qDebug("In %s", __FUNCTION__);
|
||||||
|
|
||||||
|
if (monitorRx_)
|
||||||
|
monitorRx_->stop();
|
||||||
|
if (monitorTx_)
|
||||||
|
monitorTx_->stop();
|
||||||
|
|
||||||
delete capturer_;
|
delete capturer_;
|
||||||
delete transmitter_;
|
delete transmitter_;
|
||||||
delete monitorTx_;
|
|
||||||
|
if (monitorRx_)
|
||||||
|
monitorRx_->wait();
|
||||||
delete monitorRx_;
|
delete monitorRx_;
|
||||||
|
|
||||||
|
if (monitorTx_)
|
||||||
|
monitorTx_->wait();
|
||||||
|
delete monitorTx_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PcapPort::updateNotes()
|
void PcapPort::updateNotes()
|
||||||
@ -167,6 +179,7 @@ PcapPort::PortMonitor::PortMonitor(const char *device, Direction direction,
|
|||||||
isPromisc_ = true;
|
isPromisc_ = true;
|
||||||
noLocalCapture = true;
|
noLocalCapture = true;
|
||||||
stats_ = stats;
|
stats_ = stats;
|
||||||
|
stop_ = false;
|
||||||
|
|
||||||
_retry:
|
_retry:
|
||||||
#ifdef Q_OS_WIN32
|
#ifdef Q_OS_WIN32
|
||||||
@ -244,7 +257,7 @@ PcapPort::PortMonitor::~PortMonitor()
|
|||||||
|
|
||||||
void PcapPort::PortMonitor::run()
|
void PcapPort::PortMonitor::run()
|
||||||
{
|
{
|
||||||
while (1)
|
while (!stop_)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct pcap_pkthdr *hdr;
|
struct pcap_pkthdr *hdr;
|
||||||
@ -283,12 +296,21 @@ void PcapPort::PortMonitor::run()
|
|||||||
__PRETTY_FUNCTION__, ret, pcap_geterr(handle_));
|
__PRETTY_FUNCTION__, ret, pcap_geterr(handle_));
|
||||||
break;
|
break;
|
||||||
case -2:
|
case -2:
|
||||||
|
qWarning("%s: error reading packet (%d): %s",
|
||||||
|
__PRETTY_FUNCTION__, ret, pcap_geterr(handle_));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
qFatal("%s: Unexpected return value %d", __PRETTY_FUNCTION__, ret);
|
qFatal("%s: Unexpected return value %d", __PRETTY_FUNCTION__, ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PcapPort::PortMonitor::stop()
|
||||||
|
{
|
||||||
|
stop_ = true;
|
||||||
|
pcap_breakloop(handle());
|
||||||
|
}
|
||||||
|
|
||||||
PcapPort::PortTransmitter::PortTransmitter(const char *device)
|
PcapPort::PortTransmitter::PortTransmitter(const char *device)
|
||||||
{
|
{
|
||||||
char errbuf[PCAP_ERRBUF_SIZE] = "";
|
char errbuf[PCAP_ERRBUF_SIZE] = "";
|
||||||
@ -434,7 +456,7 @@ void PcapPort::PortTransmitter::setHandle(pcap_t *handle)
|
|||||||
if (usingInternalHandle_)
|
if (usingInternalHandle_)
|
||||||
pcap_close(handle_);
|
pcap_close(handle_);
|
||||||
handle_ = handle;
|
handle_ = handle;
|
||||||
usingInternalStats_ = false;
|
usingInternalHandle_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PcapPort::PortTransmitter::useExternalStats(AbstractPort::PortStats *stats)
|
void PcapPort::PortTransmitter::useExternalStats(AbstractPort::PortStats *stats)
|
||||||
|
@ -82,12 +82,14 @@ protected:
|
|||||||
AbstractPort::PortStats *stats);
|
AbstractPort::PortStats *stats);
|
||||||
~PortMonitor();
|
~PortMonitor();
|
||||||
void run();
|
void run();
|
||||||
|
void stop();
|
||||||
pcap_t* handle() { return handle_; }
|
pcap_t* handle() { return handle_; }
|
||||||
Direction direction() { return direction_; }
|
Direction direction() { return direction_; }
|
||||||
bool isDirectional() { return isDirectional_; }
|
bool isDirectional() { return isDirectional_; }
|
||||||
bool isPromiscuous() { return isPromisc_; }
|
bool isPromiscuous() { return isPromisc_; }
|
||||||
protected:
|
protected:
|
||||||
AbstractPort::PortStats *stats_;
|
AbstractPort::PortStats *stats_;
|
||||||
|
bool stop_;
|
||||||
private:
|
private:
|
||||||
pcap_t *handle_;
|
pcap_t *handle_;
|
||||||
Direction direction_;
|
Direction direction_;
|
||||||
|
@ -29,6 +29,11 @@ const uint OID_GEN_MEDIA_CONNECT_STATUS = 0x00010114;
|
|||||||
WinPcapPort::WinPcapPort(int id, const char *device)
|
WinPcapPort::WinPcapPort(int id, const char *device)
|
||||||
: PcapPort(id, device)
|
: PcapPort(id, device)
|
||||||
{
|
{
|
||||||
|
monitorRx_->stop();
|
||||||
|
monitorTx_->stop();
|
||||||
|
monitorRx_->wait();
|
||||||
|
monitorTx_->wait();
|
||||||
|
|
||||||
delete monitorRx_;
|
delete monitorRx_;
|
||||||
delete monitorTx_;
|
delete monitorTx_;
|
||||||
|
|
||||||
@ -140,7 +145,7 @@ void WinPcapPort::PortMonitor::run()
|
|||||||
lastTs.tv_sec = 0;
|
lastTs.tv_sec = 0;
|
||||||
lastTs.tv_usec = 0;
|
lastTs.tv_usec = 0;
|
||||||
|
|
||||||
while (1)
|
while (!stop_)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct pcap_pkthdr *hdr;
|
struct pcap_pkthdr *hdr;
|
||||||
@ -205,12 +210,16 @@ void WinPcapPort::PortMonitor::run()
|
|||||||
__PRETTY_FUNCTION__, ret, pcap_geterr(handle()));
|
__PRETTY_FUNCTION__, ret, pcap_geterr(handle()));
|
||||||
break;
|
break;
|
||||||
case -2:
|
case -2:
|
||||||
|
qWarning("%s: error reading packet (%d): %s",
|
||||||
|
__PRETTY_FUNCTION__, ret, pcap_geterr(handle()));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
qFatal("%s: Unexpected return value %d", __PRETTY_FUNCTION__, ret);
|
qFatal("%s: Unexpected return value %d", __PRETTY_FUNCTION__, ret);
|
||||||
}
|
}
|
||||||
lastTs.tv_sec = hdr->ts.tv_sec;
|
lastTs.tv_sec = hdr->ts.tv_sec;
|
||||||
lastTs.tv_usec = hdr->ts.tv_usec;
|
lastTs.tv_usec = hdr->ts.tv_usec;
|
||||||
QThread::msleep(1000);
|
if (!stop_)
|
||||||
|
QThread::msleep(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user