@cryptotaxi247 / kubo / commits / 31dc65b96

clean up after listeners on shutdown

Jeromy committed Aug 1, 2014 at 18:07 UTC 31dc65b96b681c2565245a7c76d4b8e06e8fd88e
1 file changed +8
swarm/swarm.go
+8
@@ -81,6 +81,7 @@ type Swarm struct {
81 connsLock sync.RWMutex
82
83 local *peer.Peer
84 + listeners []net.Listener
85 }
86
87 // NewSwarm constructs a Swarm, with a Chan.
@@ -126,6 +127,9 @@ func (s *Swarm) connListen(maddr *ma.Multiaddr) error {
127 return err
128 }
129
130 + // NOTE: this may require a lock around it later. currently, only run on setup
131 + s.listeners = append(s.listeners, list)
132 +
133 // Accept and handle new connections on this listener until it errors
134 go func() {
135 for {
@@ -172,6 +176,10 @@ func (s *Swarm) Close() {
176 }
177 s.Chan.Close <- true // fan out
178 s.Chan.Close <- true // listener
179 +
180 + for _,list := range s.listeners {
181 + list.Close()
182 + }
183 }
184
185 // Dial connects to a peer.