udp: Add UDP configuration, move tracker shutdown to the main package
This commit is contained in:
parent
1698f0017b
commit
778b64defa
3 changed files with 33 additions and 21 deletions
|
@ -78,5 +78,10 @@ func Boot() {
|
||||||
}
|
}
|
||||||
|
|
||||||
http.Serve(cfg, tkr)
|
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")
|
glog.Info("Gracefully shut down")
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,17 +89,24 @@ type TrackerConfig struct {
|
||||||
|
|
||||||
// HTTPConfig is the configuration for HTTP functionality.
|
// HTTPConfig is the configuration for HTTP functionality.
|
||||||
type HTTPConfig struct {
|
type HTTPConfig struct {
|
||||||
ListenAddr string `json:"http_listen_addr"`
|
HTTPListenAddr string `json:"http_listen_addr"`
|
||||||
RequestTimeout Duration `json:"http_request_timeout"`
|
HTTPRequestTimeout Duration `json:"http_request_timeout"`
|
||||||
HttpReadTimeout Duration `json:"http_read_timeout"`
|
HTTPReadTimeout Duration `json:"http_read_timeout"`
|
||||||
HttpWriteTimeout Duration `json:"http_write_timeout"`
|
HTTPWriteTimeout Duration `json:"http_write_timeout"`
|
||||||
HttpListenLimit int `json:"http_listen_limit"`
|
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.
|
// Config is the global configuration for an instance of Chihaya.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
TrackerConfig
|
TrackerConfig
|
||||||
HTTPConfig
|
HTTPConfig
|
||||||
|
UDPConfig
|
||||||
DriverConfig
|
DriverConfig
|
||||||
StatsConfig
|
StatsConfig
|
||||||
}
|
}
|
||||||
|
@ -127,10 +134,14 @@ var DefaultConfig = Config{
|
||||||
},
|
},
|
||||||
|
|
||||||
HTTPConfig: HTTPConfig{
|
HTTPConfig: HTTPConfig{
|
||||||
ListenAddr: ":6881",
|
HTTPListenAddr: ":6881",
|
||||||
RequestTimeout: Duration{10 * time.Second},
|
HTTPRequestTimeout: Duration{10 * time.Second},
|
||||||
HttpReadTimeout: Duration{10 * time.Second},
|
HTTPReadTimeout: Duration{10 * time.Second},
|
||||||
HttpWriteTimeout: Duration{10 * time.Second},
|
HTTPWriteTimeout: Duration{10 * time.Second},
|
||||||
|
},
|
||||||
|
|
||||||
|
UDPConfig: UDPConfig{
|
||||||
|
UDPListenAddr: ":6881",
|
||||||
},
|
},
|
||||||
|
|
||||||
DriverConfig: DriverConfig{
|
DriverConfig: DriverConfig{
|
||||||
|
|
20
http/http.go
20
http/http.go
|
@ -126,20 +126,20 @@ func Serve(cfg *config.Config, tkr *tracker.Tracker) {
|
||||||
tracker: tkr,
|
tracker: tkr,
|
||||||
}
|
}
|
||||||
|
|
||||||
glog.V(0).Info("Starting on ", cfg.ListenAddr)
|
glog.V(0).Info("Starting HTTP on ", cfg.HTTPListenAddr)
|
||||||
if cfg.HttpListenLimit != 0 {
|
if cfg.HTTPListenLimit != 0 {
|
||||||
glog.V(0).Info("Limiting connections to ", cfg.HttpListenLimit)
|
glog.V(0).Info("Limiting connections to ", cfg.HTTPListenLimit)
|
||||||
}
|
}
|
||||||
|
|
||||||
grace := &graceful.Server{
|
grace := &graceful.Server{
|
||||||
Timeout: cfg.RequestTimeout.Duration,
|
Timeout: cfg.HTTPRequestTimeout.Duration,
|
||||||
ConnState: srv.connState,
|
ConnState: srv.connState,
|
||||||
ListenLimit: cfg.HttpListenLimit,
|
ListenLimit: cfg.HTTPListenLimit,
|
||||||
Server: &http.Server{
|
Server: &http.Server{
|
||||||
Addr: cfg.ListenAddr,
|
Addr: cfg.HTTPListenAddr,
|
||||||
Handler: newRouter(srv),
|
Handler: newRouter(srv),
|
||||||
ReadTimeout: cfg.HttpReadTimeout.Duration,
|
ReadTimeout: cfg.HTTPReadTimeout.Duration,
|
||||||
WriteTimeout: cfg.HttpWriteTimeout.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())
|
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())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue