diff options
author | Christian Pointner <equinox@spreadspace.org> | 2016-03-26 19:23:34 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2016-03-26 19:23:34 (GMT) |
commit | f27fa7e80e6052ce927b064bf9292dd94a480f39 (patch) | |
tree | 9ce0a440f7bd098cc801df416658e4d96283b3b4 /src | |
parent | 9c3fc8f9fa3f54566286f2e2222ab16f7634c325 (diff) |
add timeout for audioswtich commands to config file
Diffstat (limited to 'src')
-rw-r--r-- | src/rhctl/conf.go | 18 | ||||
-rw-r--r-- | src/rhctl/main.go | 5 |
2 files changed, 21 insertions, 2 deletions
diff --git a/src/rhctl/conf.go b/src/rhctl/conf.go index acd5cd1..7a1aea0 100644 --- a/src/rhctl/conf.go +++ b/src/rhctl/conf.go @@ -23,6 +23,8 @@ package main import ( "os" + "strings" + "time" "github.com/naoina/toml" ) @@ -31,6 +33,7 @@ type Config struct { Audioswitch struct { Device string `toml:"dev"` Baudrate Baudrate `toml:"baud"` + Timeout Duration `toml:"timeout"` } Servers map[string]struct { @@ -47,6 +50,16 @@ type Config struct { } } +type Duration struct { + time.Duration +} + +func (d *Duration) UnmarshalTOML(data []byte) (err error) { + ds := strings.TrimRight(strings.TrimLeft(string(data), "\""), "\"") + d.Duration, err = time.ParseDuration(ds) + return +} + func ReadConfig(configfile string) (conf *Config, err error) { conf = &Config{} @@ -60,5 +73,10 @@ func ReadConfig(configfile string) (conf *Config, err error) { if err = decoder.Decode(conf); err != nil { return } + + if conf.Audioswitch.Timeout.Duration <= time.Duration(0) { + conf.Audioswitch.Timeout.Duration = time.Second + } + return } diff --git a/src/rhctl/main.go b/src/rhctl/main.go index dff1758..e6164a0 100644 --- a/src/rhctl/main.go +++ b/src/rhctl/main.go @@ -77,8 +77,6 @@ func main() { } rhl.Printf("just started...") - stop := make(chan bool) - sw, err := SwitchInit(conf) if err != nil { rhl.Println("error initializing audio switch: ", err) @@ -95,6 +93,9 @@ func main() { servers = append(servers, server) } + // running essential parts + stop := make(chan bool) + go func() { rhl.Printf("starting audioswitch handler") sw.Run() |