2023-04-18 14:14:46 +08:00
|
|
|
#ifndef TCPSOCKET_H
|
|
|
|
#define TCPSOCKET_H
|
|
|
|
|
|
|
|
#include <QTcpSocket>
|
|
|
|
#include <condition_variable>
|
|
|
|
|
|
|
|
class TcpSocket : public QTcpSocket {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit TcpSocket(QObject *parent = nullptr);
|
|
|
|
|
|
|
|
bool waitForConnected(int msecs = 30000) override;
|
|
|
|
bool waitForDisconnected(int msecs = 30000) override;
|
|
|
|
bool waitForBytesWritten(int msecs = 30000) override;
|
|
|
|
bool waitForReadyRead(int msecs = 30000) override;
|
|
|
|
qint64 readData(char *data, qint64 maxlen) override;
|
|
|
|
qint64 readLineData(char *data, qint64 maxlen) override;
|
|
|
|
qint64 writeData(const char *data, qint64 len) override;
|
|
|
|
bool hasErr = false;
|
|
|
|
bool isWritten = false;
|
|
|
|
bool isReadyRead = false;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::mutex mtx;
|
|
|
|
std::condition_variable cv;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // TCPSOCKET_H
|