This commit is contained in:
zhouyuyan
2017-08-23 20:32:19 +08:00
parent 00abbac00f
commit 922a10fd66
2 changed files with 16 additions and 2 deletions

View File

@@ -45,7 +45,6 @@ func (b *Broker) StartListening() {
}
func (b *Broker) handleConnection(conn net.Conn, idx int) {
//process connect packet
buf, err := ReadPacket(conn)
if err != nil {
@@ -74,12 +73,14 @@ func (b *Broker) handleConnection(conn net.Conn, idx int) {
keepalive: connMsg.KeepAlive(),
willMsg: willmsg,
}
pool := MSGPool[idx%MessagePoolNum].GetPool()
c := &client{
broker: b,
conn: conn,
info: info,
msgPool: MSGPool[idx%MessagePoolNum].GetPool(),
msgPool: pool,
}
c.init()
c.readLoop()
pool.Reduce()
}

13
main.go
View File

@@ -13,10 +13,15 @@ const (
MessagePoolNum = 1024
MessagePoolUser = MaxUser / MessagePoolNum
MessagePoolMessageNum = MaxUser / MessagePoolNum * 4
MessageBoxNum = 256
MessageBoxUserNum = MaxUser / MessageBoxNum
MessageBoxMessageLength = MessageBoxUserNum
)
var (
MSGPool []MessagePool
// Messagebox []*Message
)
func init() {
@@ -24,6 +29,14 @@ func init() {
for i := 0; i < (MessagePoolNum + 2); i++ {
MSGPool[i].Init(MessagePoolUser, MessagePoolMessageNum)
}
// Messagebox = make([]MessageProcess, MailBoxNum)
// for i := 0; i < MailBoxNum; i++ {
// gMailbox[i].Init(MailBoxMessageLength, HongBaoBoxMessageLength)
// }
// for i := 0; i < MailBoxNum; i++ {
// go ProcessRequest(i)
// }
}
func main() {
broker := broker.NewBroker()