Skip to content

Commit

Permalink
Merge branch 'iwanbk-listen-address'
Browse files Browse the repository at this point in the history
  • Loading branch information
tidwall committed Feb 28, 2018
2 parents b6e65d4 + 75d62f9 commit 56b0161
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions redcon.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ func (s *Server) ListenAndServe() error {
return s.ListenServeAndSignal(nil)
}

// Addr returns server's listen address
func (s *Server) Addr() net.Addr {
return s.ln.Addr()
}

// Close stops listening on the TCP address.
// Already Accepted connections will be closed.
func (s *TLSServer) Close() error {
Expand Down Expand Up @@ -247,10 +252,11 @@ func (s *Server) ListenServeAndSignal(signal chan error) error {
}
return err
}
s.ln = ln
if signal != nil {
signal <- nil
}
return serve(s, ln)
return serve(s)
}

// ListenServeAndSignal serves incoming connections and passes nil or error
Expand All @@ -263,18 +269,16 @@ func (s *TLSServer) ListenServeAndSignal(signal chan error) error {
}
return err
}
s.ln = ln
if signal != nil {
signal <- nil
}
return serve(s.Server, ln)
return serve(s.Server)
}

func serve(s *Server, ln net.Listener) error {
s.mu.Lock()
s.ln = ln
s.mu.Unlock()
func serve(s *Server) error {
defer func() {
ln.Close()
s.ln.Close()
func() {
s.mu.Lock()
defer s.mu.Unlock()
Expand All @@ -285,7 +289,7 @@ func serve(s *Server, ln net.Listener) error {
}()
}()
for {
lnconn, err := ln.Accept()
lnconn, err := s.ln.Accept()
if err != nil {
s.mu.Lock()
done := s.done
Expand Down

0 comments on commit 56b0161

Please sign in to comment.