42 lines
1.0 KiB
C++
42 lines
1.0 KiB
C++
#ifndef PCAPRETHREAD_H
|
|
#define PCAPRETHREAD_H
|
|
|
|
#include <QThread>
|
|
#define HAVE_REMOTE
|
|
#include "pcap.h"
|
|
|
|
struct Resp {
|
|
Resp() {}
|
|
Resp(int id, qint64 timeout, const std::function<void(const QByteArray)> &callback) : id(id), timeout(timeout), callback(callback) {
|
|
auto now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
|
|
if(this->timeout > 0) this->timeout += now;
|
|
}
|
|
int id;
|
|
qint64 timeout;
|
|
std::function<void(const QByteArray)> callback;
|
|
};
|
|
|
|
class PcapReThread : public QThread {
|
|
Q_OBJECT
|
|
public:
|
|
explicit PcapReThread(pcap *pcap);
|
|
~PcapReThread() {
|
|
pcap_close(pcap);
|
|
}
|
|
void addResp(const Resp &resp) {
|
|
std::lock_guard<std::mutex> lock(mtx);
|
|
resps.append(resp);
|
|
}
|
|
std::atomic<char> status{0};
|
|
QList<Resp> resps;
|
|
std::mutex mtx;
|
|
pcap *pcap;
|
|
signals:
|
|
void onMsg(Resp resp, const QByteArray data);
|
|
void onError(char *);
|
|
protected:
|
|
void run();
|
|
};
|
|
|
|
#endif // PCAPRETHREAD_H
|