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() { go func() {
defer wg.Done() defer wg.Done()
srv.Serve() srv.Serve(cfg.HTTPListenAddr)
}() }()
} }
@ -102,7 +102,7 @@ func Boot() {
go func() { go func() {
defer wg.Done() 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. // Serve runs an HTTP server, blocking until the server has shut down.
func (s *Server) Serve() { func (s *Server) Serve(addr string) {
glog.V(0).Info("Starting HTTP on ", s.config.HTTPListenAddr) glog.V(0).Info("Starting HTTP on ", addr)
if s.config.HTTPListenLimit != 0 { if s.config.HTTPListenLimit != 0 {
glog.V(0).Info("Limiting connections to ", s.config.HTTPListenLimit) glog.V(0).Info("Limiting connections to ", s.config.HTTPListenLimit)
@ -133,7 +133,7 @@ func (s *Server) Serve() {
ConnState: s.connState, ConnState: s.connState,
ListenLimit: s.config.HTTPListenLimit, ListenLimit: s.config.HTTPListenLimit,
Server: &http.Server{ Server: &http.Server{
Addr: s.config.HTTPListenAddr, Addr: addr,
Handler: newRouter(s), Handler: newRouter(s),
ReadTimeout: s.config.HTTPReadTimeout.Duration, ReadTimeout: s.config.HTTPReadTimeout.Duration,
WriteTimeout: s.config.HTTPWriteTimeout.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. // Server represents a server for a given BitTorrent tracker protocol.
type Server interface { type Server interface {
// Serve runs the server and blocks until the server has shut down. // 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 cleanly shuts down the server in a non-blocking manner.
Stop() Stop()

View file

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