This commit is contained in:
zhouyuyan
2017-08-23 21:10:38 +08:00
parent 922a10fd66
commit e73776d670
6 changed files with 101 additions and 56 deletions

View File

@@ -14,7 +14,6 @@ type client struct {
info info
localIP string
remoteIP string
msgPool *MessagePool
woker Worker
}
@@ -26,33 +25,26 @@ type info struct {
willMsg *message.PublishMessage
}
type Worker struct {
WorkerPool chan chan Message
MsgChannel chan Message
quit chan bool
}
func (c *client) init() {
c.localIP = strings.Split(c.conn.LocalAddr().String(), ":")[0]
c.remoteIP = strings.Split(c.conn.RemoteAddr().String(), ":")[0]
}
func (c *client) readLoop() {
func (c *client) readLoop(idx int) {
nc := c.conn
msgPool := c.msgPool
msgPool := MSGPool[idx%MessagePoolNum].GetPool()
if nc == nil || msgPool == nil {
return
}
cid := c.info.clientID
for {
msg := msgPool.Pop()
buf, err := ReadPacket(nc)
if err != nil {
log.Error("read packet error: ", err)
return
}
msg.user = cid
msg.client = c
msg.buf = buf
msgPool.Push(msg)
}
msgPool.Reduce()
}