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