tracker: Pass listen address into tracker.Server.Serve()

This commit is contained in:
Justin Li 2015-02-21 13:16:21 -05:00
parent f98c675bc7
commit 669128c83a
4 changed files with 12 additions and 12 deletions

View file

@ -91,7 +91,7 @@ func Boot() {
go func() {
defer wg.Done()
srv.Serve()
srv.Serve(cfg.HTTPListenAddr)
}()
}
@ -102,7 +102,7 @@ func Boot() {
go func() {
defer wg.Done()
srv.Serve()
srv.Serve(cfg.UDPListenAddr)
}()
}

View file

@ -121,8 +121,8 @@ func (s *Server) connState(conn net.Conn, state http.ConnState) {
}
// Serve runs an HTTP server, blocking until the server has shut down.
func (s *Server) Serve() {
glog.V(0).Info("Starting HTTP on ", s.config.HTTPListenAddr)
func (s *Server) Serve(addr string) {
glog.V(0).Info("Starting HTTP on ", addr)
if s.config.HTTPListenLimit != 0 {
glog.V(0).Info("Limiting connections to ", s.config.HTTPListenLimit)
@ -133,7 +133,7 @@ func (s *Server) Serve() {
ConnState: s.connState,
ListenLimit: s.config.HTTPListenLimit,
Server: &http.Server{
Addr: s.config.HTTPListenAddr,
Addr: addr,
Handler: newRouter(s),
ReadTimeout: s.config.HTTPReadTimeout.Duration,
WriteTimeout: s.config.HTTPWriteTimeout.Duration,

View file

@ -27,7 +27,7 @@ type Tracker struct {
// Server represents a server for a given BitTorrent tracker protocol.
type Server interface {
// Serve runs the server and blocks until the server has shut down.
Serve()
Serve(addr string)
// Stop cleanly shuts down the server in a non-blocking manner.
Stop()

View file

@ -25,13 +25,13 @@ type Server struct {
done bool
}
func (s *Server) serve() error {
listenAddr, err := net.ResolveUDPAddr("udp", s.config.UDPListenAddr)
func (s *Server) serve(listenAddr string) error {
udpAddr, err := net.ResolveUDPAddr("udp", listenAddr)
if err != nil {
return err
}
sock, err := net.ListenUDP("udp", listenAddr)
sock, err := net.ListenUDP("udp", udpAddr)
defer sock.Close()
if err != nil {
return err
@ -75,8 +75,8 @@ func (s *Server) serve() error {
}
// Serve runs a UDP server, blocking until the server has shut down.
func (s *Server) Serve() {
glog.V(0).Info("Starting UDP on ", s.config.UDPListenAddr)
func (s *Server) Serve(addr string) {
glog.V(0).Info("Starting UDP on ", addr)
go func() {
// Generate a new IV every hour.
@ -85,7 +85,7 @@ func (s *Server) Serve() {
}
}()
if err := s.serve(); err != nil {
if err := s.serve(addr); err != nil {
glog.Errorf("Failed to run UDP server: %s", err.Error())
} else {
glog.Info("UDP server shut down cleanly")