Joyit 1 месяц назад
Родитель
Сommit
2d05d7c302
2 измененных файлов с 10 добавлено и 4 удалено
  1. 4 2
      hub.go
  2. 6 2
      line.go

+ 4 - 2
hub.go

@@ -764,8 +764,10 @@ func (h *Hub) ConnectToServer(channel string, force bool, host *HostInfo) (err e
 
 // 重试方式连接服务
 // 将会一直阻塞直到连接成功
-func (h *Hub) ConnectToServerX(channel string, force bool) {
-	host, _ := h.connectHostFunc(channel, Direct)
+func (h *Hub) ConnectToServerX(channel string, force bool, host *HostInfo) {
+	if host == nil {
+		host, _ = h.connectHostFunc(channel, Direct)
+	}
 	for {
 		err := h.ConnectToServer(channel, force, host)
 		if err == nil {

+ 6 - 2
line.go

@@ -158,8 +158,12 @@ func (c *Line) writePump() {
 				c.host.Errors++
 				c.host.Updated = time.Now()
 
-				time.Sleep(time.Second)
-				c.hub.ConnectToServerX(c.channel, false)
+				time.Sleep(5 * time.Second)
+				if c.host.Errors < 2 {
+					c.hub.ConnectToServerX(c.channel, false, c.host)
+				} else {
+					c.hub.ConnectToServerX(c.channel, false, nil)
+				}
 			}()
 		}
 	}()