Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix listener problems #540

Merged
merged 6 commits into from
Jan 11, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
p2p/net/swarm/listener: consume peerstream listeners
  • Loading branch information
jbenet committed Jan 11, 2015
commit 4e2431a0e45b71cae77f31b6d379b772abd2c50c
26 changes: 24 additions & 2 deletions p2p/net/swarm/swarm_listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,30 @@ func (s *Swarm) setupListener(maddr ma.Multiaddr) error {

// AddListener to the peerstream Listener. this will begin accepting connections
// and streams!
_, err = s.swarm.AddListener(list)
return err
sl, err := s.swarm.AddListener(list)
if err != nil {
return err
}

// go consume peerstream's listen accept errors. note, these ARE errors.
// they may be killing the listener, and if we get _any_ we should be
// fixing this in our conn.Listener (to ignore them or handle them
// differently.)
go func(ctx context.Context, sl *ps.Listener) {
for {
select {
case err, more := <-sl.AcceptErrors():
if !more {
return
}
log.Info(err)
case <-ctx.Done():
return
}
}
}(s.cg.Context(), sl)

return nil
}

// connHandler is called by the StreamSwarm whenever a new connection is added
Expand Down