mirror of
https://github.com/fhmq/hmq.git
synced 2026-09-01 15:24:53 +00:00
keepalive
This commit is contained in:
+11
-1
@@ -6,6 +6,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
log "github.com/cihub/seelog"
|
log "github.com/cihub/seelog"
|
||||||
)
|
)
|
||||||
@@ -70,15 +71,24 @@ func (c *client) readLoop(msgPool *MessagePool) {
|
|||||||
if nc == nil || msgPool == nil {
|
if nc == nil || msgPool == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := &Message{}
|
msg := &Message{}
|
||||||
|
lastIn := uint16(time.Now().Unix())
|
||||||
|
var nowTime uint16
|
||||||
for {
|
for {
|
||||||
|
nowTime = uint16(time.Now().Unix())
|
||||||
|
if 0 != c.info.keepalive && nowTime-lastIn > c.info.keepalive*3/2 {
|
||||||
|
log.Errorf("Client %s has exceeded timeout, disconnecting.\n", c.info.clientID)
|
||||||
|
c.Close()
|
||||||
|
return
|
||||||
|
}
|
||||||
packet, err := packets.ReadPacket(nc)
|
packet, err := packets.ReadPacket(nc)
|
||||||
// buf, err := ReadPacket(nc)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("read packet error: ", err)
|
log.Error("read packet error: ", err)
|
||||||
c.Close()
|
c.Close()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
lastIn = uint16(time.Now().Unix())
|
||||||
msg.client = c
|
msg.client = c
|
||||||
msg.packet = packet
|
msg.packet = packet
|
||||||
msgPool.queue <- msg
|
msgPool.queue <- msg
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
CONFIGFILE = "broker.config"
|
CONFIGFILE = "hmq.config"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package broker
|
package broker
|
||||||
|
|
||||||
const (
|
const (
|
||||||
WorkNum = 2048
|
WorkNum = 4096
|
||||||
)
|
)
|
||||||
|
|
||||||
type Dispatcher struct {
|
type Dispatcher struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user