udp: Add UDP configuration, move tracker shutdown to the main package

This commit is contained in:
Justin Li 2015-02-19 23:46:28 -05:00
parent 1698f0017b
commit 778b64defa
3 changed files with 33 additions and 21 deletions

View file

@ -78,5 +78,10 @@ func Boot() {
}
http.Serve(cfg, tkr)
if err := tkr.Close(); err != nil {
glog.Errorf("Failed to shut down tracker cleanly: %s", err.Error())
}
glog.Info("Gracefully shut down")
}

View file

@ -89,17 +89,24 @@ type TrackerConfig struct {
// HTTPConfig is the configuration for HTTP functionality.
type HTTPConfig struct {
ListenAddr string `json:"http_listen_addr"`
RequestTimeout Duration `json:"http_request_timeout"`
HttpReadTimeout Duration `json:"http_read_timeout"`
HttpWriteTimeout Duration `json:"http_write_timeout"`
HttpListenLimit int `json:"http_listen_limit"`
HTTPListenAddr string `json:"http_listen_addr"`
HTTPRequestTimeout Duration `json:"http_request_timeout"`
HTTPReadTimeout Duration `json:"http_read_timeout"`
HTTPWriteTimeout Duration `json:"http_write_timeout"`
HTTPListenLimit int `json:"http_listen_limit"`
}
// UDPConfig is the configuration for HTTP functionality.
type UDPConfig struct {
UDPListenAddr string `json:"udp_listen_addr"`
UDPReadBufferSize int `json:"udp_read_buffer_size"`
}
// Config is the global configuration for an instance of Chihaya.
type Config struct {
TrackerConfig
HTTPConfig
UDPConfig
DriverConfig
StatsConfig
}
@ -127,10 +134,14 @@ var DefaultConfig = Config{
},
HTTPConfig: HTTPConfig{
ListenAddr: ":6881",
RequestTimeout: Duration{10 * time.Second},
HttpReadTimeout: Duration{10 * time.Second},
HttpWriteTimeout: Duration{10 * time.Second},
HTTPListenAddr: ":6881",
HTTPRequestTimeout: Duration{10 * time.Second},
HTTPReadTimeout: Duration{10 * time.Second},
HTTPWriteTimeout: Duration{10 * time.Second},
},
UDPConfig: UDPConfig{
UDPListenAddr: ":6881",
},
DriverConfig: DriverConfig{

View file

@ -126,20 +126,20 @@ func Serve(cfg *config.Config, tkr *tracker.Tracker) {
tracker: tkr,
}
glog.V(0).Info("Starting on ", cfg.ListenAddr)
if cfg.HttpListenLimit != 0 {
glog.V(0).Info("Limiting connections to ", cfg.HttpListenLimit)
glog.V(0).Info("Starting HTTP on ", cfg.HTTPListenAddr)
if cfg.HTTPListenLimit != 0 {
glog.V(0).Info("Limiting connections to ", cfg.HTTPListenLimit)
}
grace := &graceful.Server{
Timeout: cfg.RequestTimeout.Duration,
Timeout: cfg.HTTPRequestTimeout.Duration,
ConnState: srv.connState,
ListenLimit: cfg.HttpListenLimit,
ListenLimit: cfg.HTTPListenLimit,
Server: &http.Server{
Addr: cfg.ListenAddr,
Addr: cfg.HTTPListenAddr,
Handler: newRouter(srv),
ReadTimeout: cfg.HttpReadTimeout.Duration,
WriteTimeout: cfg.HttpWriteTimeout.Duration,
ReadTimeout: cfg.HTTPReadTimeout.Duration,
WriteTimeout: cfg.HTTPWriteTimeout.Duration,
},
}
@ -150,8 +150,4 @@ func Serve(cfg *config.Config, tkr *tracker.Tracker) {
glog.Errorf("Failed to gracefully run HTTP server: %s", err.Error())
}
}
if err := srv.tracker.Close(); err != nil {
glog.Errorf("Failed to shutdown tracker cleanly: %s", err.Error())
}
}