提交原始齿轮泵代码
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
#ifndef SERVER_THREAD_H
|
||||
#define SERVER_THREAD_H
|
||||
|
||||
#include <QThread>
|
||||
#include <QMutex>
|
||||
#include <QWaitCondition>
|
||||
#include <QQueue>
|
||||
#include <QByteArray>
|
||||
|
||||
// 工作任务结构体
|
||||
struct WorkTask {
|
||||
quint64 socketId;
|
||||
QByteArray data;
|
||||
int taskType; // 0: 处理数据, 1: 发送数据
|
||||
|
||||
WorkTask() : socketId(0), taskType(0) {}
|
||||
WorkTask(quint64 id, const QByteArray &d, int type = 0)
|
||||
: socketId(id), data(d), taskType(type) {}
|
||||
};
|
||||
|
||||
class ServerThread : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ServerThread(QObject *parent = 0);
|
||||
~ServerThread();
|
||||
|
||||
// 线程控制
|
||||
void stopThread();
|
||||
void addTask(const WorkTask &task);
|
||||
|
||||
// 状态查询
|
||||
int pendingTasks() const;
|
||||
quint64 processedCount() const;
|
||||
quint64 totalProcessedBytes() const;
|
||||
bool isProcessing() const;
|
||||
|
||||
signals:
|
||||
// 处理结果信号
|
||||
void sig_taskProcessed(quint64 socketId, const QByteArray &processedData);
|
||||
void sig_taskError(quint64 socketId, const QString &error);
|
||||
|
||||
protected:
|
||||
void run() override;
|
||||
|
||||
private:
|
||||
// 核心处理函数
|
||||
QByteArray processReceivedData(const QByteArray &data);
|
||||
QByteArray packSendData(const QByteArray &data);
|
||||
|
||||
// 线程控制
|
||||
volatile bool m_running;
|
||||
mutable QMutex m_mutex;
|
||||
QWaitCondition m_condition;
|
||||
QQueue<WorkTask> m_taskQueue;
|
||||
|
||||
// 统计信息
|
||||
quint64 m_processedCount;
|
||||
quint64 m_totalProcessedBytes;
|
||||
};
|
||||
|
||||
#endif // SERVER_THREAD_H
|
||||
Reference in New Issue
Block a user