Changeset 202 in code for trunk/user.go
- Timestamp:
- Apr 1, 2020, 1:40:20 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/user.go
r201 r202 38 38 type network struct { 39 39 Network 40 user *user 41 ring *Ring 40 user *user 41 ring *Ring 42 stopped chan struct{} 42 43 43 44 lock sync.Mutex … … 51 52 user: user, 52 53 ring: NewRing(user.srv.RingCap), 54 stopped: make(chan struct{}), 53 55 history: make(map[string]uint64), 54 56 } … … 58 60 var lastTry time.Time 59 61 for { 62 select { 63 case <-net.stopped: 64 return 65 default: 66 // This space is intentionally left blank 67 } 68 60 69 if dur := time.Now().Sub(lastTry); dur < retryConnectMinDelay { 61 70 delay := retryConnectMinDelay - dur … … 91 100 defer net.lock.Unlock() 92 101 return net.conn 102 } 103 104 func (net *network) Stop() { 105 select { 106 case <-net.stopped: 107 return 108 default: 109 close(net.stopped) 110 } 111 112 if uc := net.upstream(); uc != nil { 113 uc.Close() 114 } 93 115 } 94 116 … … 266 288 return network, nil 267 289 } 290 291 func (u *user) deleteNetwork(id int64) error { 292 for i, net := range u.networks { 293 if net.ID != id { 294 continue 295 } 296 297 if err := u.srv.db.DeleteNetwork(net.ID); err != nil { 298 return err 299 } 300 301 u.forEachDownstream(func(dc *downstreamConn) { 302 if dc.network != nil && dc.network == net { 303 dc.Close() 304 } 305 }) 306 307 net.Stop() 308 u.networks = append(u.networks[:i], u.networks[i+1:]...) 309 return nil 310 } 311 312 panic("tried deleting a non-existing network") 313 }
Note:
See TracChangeset
for help on using the changeset viewer.