diff --git a/broker/client.go b/broker/client.go index f479489..fb16241 100644 --- a/broker/client.go +++ b/broker/client.go @@ -6,6 +6,7 @@ import ( "net" "strings" "sync" + "time" log "github.com/cihub/seelog" ) @@ -70,15 +71,24 @@ func (c *client) readLoop(msgPool *MessagePool) { if nc == nil || msgPool == nil { return } + msg := &Message{} + lastIn := uint16(time.Now().Unix()) + var nowTime uint16 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) - // buf, err := ReadPacket(nc) if err != nil { log.Error("read packet error: ", err) c.Close() return } + lastIn = uint16(time.Now().Unix()) msg.client = c msg.packet = packet msgPool.queue <- msg diff --git a/broker/config.go b/broker/config.go index 8ad9171..485237f 100644 --- a/broker/config.go +++ b/broker/config.go @@ -11,7 +11,7 @@ import ( ) const ( - CONFIGFILE = "broker.config" + CONFIGFILE = "hmq.config" ) type Config struct { diff --git a/broker/dispatcher.go b/broker/dispatcher.go index bbf341d..b6a0833 100644 --- a/broker/dispatcher.go +++ b/broker/dispatcher.go @@ -1,7 +1,7 @@ package broker const ( - WorkNum = 2048 + WorkNum = 4096 ) type Dispatcher struct { diff --git a/hmq b/hmq index b0711ad..1bd929f 100755 Binary files a/hmq and b/hmq differ diff --git a/broker.config b/hmq.config similarity index 100% rename from broker.config rename to hmq.config