Browse Source

重启时重设状态和通道

huangrf 5 years ago
parent
commit
7dd7576f05
1 changed files with 10 additions and 5 deletions
  1. 10 5
      engine/auth/auth_client.go

+ 10 - 5
engine/auth/auth_client.go

@@ -47,11 +47,11 @@ func (ap *authPackage)toBytes()[]byte{
 }
 }
 
 
 type TcpClient struct {
 type TcpClient struct {
-	conn    net.Conn
-	pchan   chan *authPackage
-	done    chan bool
-	exited bool
-	verified   bool
+	conn     net.Conn           // 连接
+	pchan    chan *authPackage  // 包chan
+	done     chan bool          // 是否done
+	exited   bool               // 退出
+	verified bool               // 验证是否
 }
 }
 
 
 // 创建client
 // 创建client
@@ -72,6 +72,7 @@ func(c *TcpClient)Start() {
 			if p := recover(); p != nil {
 			if p := recover(); p != nil {
 				fmt.Println("ecover", p)
 				fmt.Println("ecover", p)
 			}
 			}
+			c.conn.Close()
 			c.restart()
 			c.restart()
 		}()
 		}()
 
 
@@ -114,6 +115,7 @@ func(c *TcpClient)Start() {
 						return
 						return
 					}
 					}
 				case <-c.done:
 				case <-c.done:
+					glog.Infoln("发送数据done退出")
 					return
 					return
 				}
 				}
 			}
 			}
@@ -162,6 +164,9 @@ func(c *TcpClient)restart(){
 	go func(){
 	go func(){
 		time.Sleep(3 * time.Second)
 		time.Sleep(3 * time.Second)
 		c.verified = false
 		c.verified = false
+		c.done = make(chan bool)
+		c.pchan = make(chan *authPackage, 100)
+		c.exited = false
 		c.Start()
 		c.Start()
 	}()
 	}()
 }
 }