forked from joyieldInc/predixy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSubscribe.h
63 lines (57 loc) · 1.06 KB
/
Subscribe.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* predixy - A high performance and full features proxy for redis.
* Copyright (C) 2017 Joyield, Inc. <[email protected]>
* All rights reserved.
*/
#ifndef _PREDIXY_SUBSCRIBE_H_
#define _PREDIXY_SUBSCRIBE_H_
#include "Predixy.h"
class Subscribe
{
public:
static const int16_t MaxSub = 32000;
public:
Subscribe();
int incrPendSub()
{
return mPendSub < MaxSub ? ++mPendSub : 0;
}
int decrPendSub()
{
return mPendSub > 0 ? --mPendSub : 0;
}
bool inPendSub() const
{
return mPendSub > 0;
}
void setSub(int chs)
{
mSub = chs;
}
bool inSub(bool includePend) const
{
return mSub > 0 || (includePend && mPendSub > 0);
}
private:
int16_t mPendSub;
int16_t mSub;
};
class SubscribeParser
{
public:
enum Status
{
Unknown,
Subscribe,
Psubscribe,
Unsubscribe,
Punsubscribe,
Message,
Pmessage,
Error,
String
};
public:
static Status parse(const Segment& body, int& chs);
};
#endif