forked from Terry-Mao/gopush-cluster
/
pubsub.go
67 lines (59 loc) · 1.93 KB
/
pubsub.go
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
64
65
66
67
// Copyright © 2014 Terry Mao, LiuDing All rights reserved.
// This file is part of gopush-cluster.
// gopush-cluster is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// gopush-cluster is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with gopush-cluster. If not, see <http://www.gnu.org/licenses/>.
package main
import (
"errors"
"github.com/golang/glog"
"time"
)
const (
TCPProto = uint8(0)
WebsocketProto = uint8(1)
WebsocketProtoStr = "websocket"
TCPProtoStr = "tcp"
Heartbeat = "h"
minHearbeatSec = 30
delayHeartbeatSec = 5
fitstPacketTimedoutSec = time.Second * 5
Second = int64(time.Second)
)
var (
// Exceed the max subscriber per key
ErrMaxConn = errors.New("Exceed the max subscriber connection per key")
// Assection type failed
ErrAssertType = errors.New("Subscriber assert type failed")
// Heartbeat
// HeartbeatLen = len(Heartbeat)
// hearbeat
HeartbeatReply = []byte("+h\r\n")
// auth failed reply
AuthReply = []byte("-a\r\n")
// channle not found reply
ChannelReply = []byte("-c\r\n")
// param error reply
ParamReply = []byte("-p\r\n")
)
// StartListen start accept client.
func StartComet() {
for _, proto := range Conf.Proto {
if proto == WebsocketProtoStr {
// Start http push service
StartHttp()
} else if proto == TCPProtoStr {
// Start tcp push service
StartTCP()
} else {
glog.Warningf("unknown gopush-cluster protocol %s, (\"websocket\" or \"tcp\")", proto)
}
}
}