mirror of
https://gitee.com/willfree/http_vpn.git
synced 2026-06-05 23:49:40 +08:00
59 lines
1.9 KiB
C++
59 lines
1.9 KiB
C++
#ifndef _PRIOR_QUEUE_POOL_H_
|
|
#define _PRIOR_QUEUE_POOL_H_
|
|
// 解析数据段,存放数据段进序号优先队列
|
|
// 当要接收到的下一个数据包全部到达时,
|
|
// 将该队列的数据包缓存入顺序缓冲队列.
|
|
#include<string.h>
|
|
#include<pthread.h>
|
|
#include<map>
|
|
#include "PriorQueue.h"
|
|
#include "r_queue.h"
|
|
|
|
class QueuePool{
|
|
public:
|
|
QueuePool();
|
|
~QueuePool();
|
|
// 放入一个数据段
|
|
void pushDataSegment(const char *data,int len);
|
|
void pushDataSegment(char *data,int len);
|
|
// 更新头部缓存队列
|
|
void updateHeadQueue();
|
|
// 将某一级缓存队列设置成头部缓存队列
|
|
void setHeadQueue(PriorQueue pq);
|
|
// 弹出头部缓存队列的数据
|
|
void moveDataPacket();
|
|
// 重置wantSeq为0
|
|
void initSelf();
|
|
|
|
// 打印二级缓存队列的数据。用于测试
|
|
void printRQueue();
|
|
// 打印当前QueuePool的状态信息。用于测试
|
|
void printQueuePool();
|
|
|
|
public:
|
|
// 二级缓存队列。能够直接读取数据的缓存区
|
|
R_Queue r_queue;
|
|
|
|
protected:
|
|
// 当前想要拿到的数据包的首序列号
|
|
unsigned int wantSeq;
|
|
// 头部缓存队列是否为空的标志
|
|
int flag_head;
|
|
//头部缓存队列(headSeq等于want_seq的一级缓存队列)
|
|
PriorQueue headQueue;
|
|
// 一级缓存队列池
|
|
map<unsigned int,PriorQueue> waitQueues;
|
|
// 数据锁
|
|
// pthread_cond_t _cond ; //条件锁
|
|
// pthread_mutex_t _mutex ; //互斥锁
|
|
|
|
private:
|
|
void setWantSeq(unsigned int wantSeq);
|
|
void setWantSeq(unsigned int lastSeq, unsigned int seq_n);
|
|
unsigned int getWantSeq();
|
|
};
|
|
// 设置头部缓存队列的目的是:
|
|
// 只要它满了,就可以弹出数据到二级缓存,
|
|
// 而不需要每次在队列池先找到want_seq,再判断
|
|
|
|
#endif |