Selaa lähdekoodia

fix connect update time bug

Joyit 1 kuukausi sitten
vanhempi
sitoutus
173a79e59c
4 muutettua tiedostoa jossa 5 lisäystä ja 4 poistoa
  1. 1 1
      examples/client-tcp2.go
  2. 1 1
      examples/client-ws2.go
  3. 2 1
      examples/server.go
  4. 1 1
      line.go

+ 1 - 1
examples/client-tcp2.go

@@ -37,7 +37,7 @@ func main() {
 	}, func(proto string, version uint8, channel string, auth []byte) bool {
 		return true
 	}, func(conn *tinymq.Line) {
-		log.Println("connect state", conn.State())
+		log.Println("connect state", conn.Channel(), conn.State(), time.Since(conn.Updated()))
 	})
 
 	// 订阅频道

+ 1 - 1
examples/client-ws2.go

@@ -40,7 +40,7 @@ func main() {
 	}, func(proto string, cversion uint8, hannel string, auth []byte) bool {
 		return true
 	}, func(conn *tinymq.Line) {
-		log.Println("connect state", conn.Channel(), conn.State())
+		log.Println("connect state", conn.Channel(), conn.State(), time.Since(conn.Updated()))
 	})
 
 	// 订阅频道

+ 2 - 1
examples/server.go

@@ -10,6 +10,7 @@ import (
 	"os/signal"
 	"regexp"
 	"syscall"
+	"time"
 
 	"git.me9.top/git/tinymq"
 	"git.me9.top/git/tinymq/config"
@@ -37,7 +38,7 @@ func main() {
 		}, func(proto string, version uint8, channel string, auth []byte) bool {
 			return string(auth) == "tinymq"
 		}, func(conn *tinymq.Line) {
-			log.Println("[Connect state change]", conn.Channel(), conn.State(), conn.Started(), conn.Updated())
+			log.Println("[Connect state change]", conn.Channel(), conn.State(), time.Since(conn.Updated()))
 			if conn.State() == tinymq.Connected {
 				go hub.Get(regexp.MustCompile(remoteChannel), "hello", []byte("hello from server push"),
 					func(response *tinymq.ResponseData) (ok bool) {

+ 1 - 1
line.go

@@ -247,7 +247,6 @@ func (c *Line) Close(quick bool) {
 	defer recover() //避免管道已经关闭而引起panic
 	c.conn.Close()
 	c.closeConnect <- quick
-	c.updated = time.Now()
 	if quick {
 		if c.state != Closed {
 			c.state = Closed
@@ -261,6 +260,7 @@ func (c *Line) Close(quick bool) {
 			go c.hub.cleanDeadConnect()
 		}
 	}
+	c.updated = time.Now()
 }
 
 // 清空余留下来的管道消息