v2ray-core/commander.go

45 lines
594 B
Go
Raw Normal View History

2018-01-24 14:05:46 +00:00
package core
import (
"sync"
)
// Commander is a feature that accepts commands from external source.
type Commander interface {
Feature
}
type syncCommander struct {
sync.RWMutex
Commander
}
func (c *syncCommander) Start() error {
c.RLock()
defer c.RUnlock()
if c.Commander == nil {
return nil
}
return c.Commander.Start()
}
2018-02-08 14:39:46 +00:00
func (c *syncCommander) Close() error {
2018-01-24 14:05:46 +00:00
c.RLock()
defer c.RUnlock()
if c.Commander == nil {
2018-02-08 14:39:46 +00:00
return nil
2018-01-24 14:05:46 +00:00
}
2018-02-08 14:39:46 +00:00
return c.Commander.Close()
2018-01-24 14:05:46 +00:00
}
func (c *syncCommander) Set(commander Commander) {
c.Lock()
defer c.Unlock()
c.Commander = commander
}