tun2: loop forever at the foot of HandleConn

This commit is contained in:
Cadey Ratio 2017-04-05 14:48:08 -07:00
parent 1827d19e84
commit 56fc4f89ba
1 changed files with 44 additions and 42 deletions

View File

@ -361,52 +361,54 @@ func (s *Server) HandleConn(c net.Conn, isKCP bool) {
ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()
select {
case <-ticker.C:
err := connection.Ping()
if err != nil {
cancel()
}
case <-ctx.Done():
s.connlock.Lock()
delete(s.conns, c)
s.connlock.Unlock()
var conns []*Connection
val, ok := s.domains.Get(auth.Domain)
if ok {
conns, ok = val.([]*Connection)
if !ok {
ln.Error(err, connection.F(), ln.F{
"action": "looking_up_for_disconnect_removal",
})
return
for {
select {
case <-ticker.C:
err := connection.Ping()
if err != nil {
cancel()
}
}
case <-ctx.Done():
s.connlock.Lock()
delete(s.conns, c)
s.connlock.Unlock()
for i, cntn := range conns {
if cntn.id == connection.id {
conns[i] = conns[len(conns)-1]
conns = conns[:len(conns)-1]
var conns []*Connection
val, ok := s.domains.Get(auth.Domain)
if ok {
conns, ok = val.([]*Connection)
if !ok {
ln.Error(err, connection.F(), ln.F{
"action": "looking_up_for_disconnect_removal",
})
return
}
}
for i, cntn := range conns {
if cntn.id == connection.id {
conns[i] = conns[len(conns)-1]
conns = conns[:len(conns)-1]
}
}
if len(conns) != 0 {
s.domains.Set(auth.Domain, conns)
} else {
s.domains.Remove(auth.Domain)
}
ln.Log(connection.F(), ln.F{
"action": "client_disconnecting",
})
controlStream.Close()
session.Close()
c.Close()
return
}
if len(conns) != 0 {
s.domains.Set(auth.Domain, conns)
} else {
s.domains.Remove(auth.Domain)
}
ln.Log(connection.F(), ln.F{
"action": "client_disconnecting",
})
controlStream.Close()
session.Close()
c.Close()
return
}
}