1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 01:57:12 -05:00
v2fly/commander.go

45 lines
594 B
Go
Raw Normal View History

2018-01-24 09:05:46 -05: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 09:39:46 -05:00
func (c *syncCommander) Close() error {
2018-01-24 09:05:46 -05:00
c.RLock()
defer c.RUnlock()
if c.Commander == nil {
2018-02-08 09:39:46 -05:00
return nil
2018-01-24 09:05:46 -05:00
}
2018-02-08 09:39:46 -05:00
return c.Commander.Close()
2018-01-24 09:05:46 -05:00
}
func (c *syncCommander) Set(commander Commander) {
c.Lock()
defer c.Unlock()
c.Commander = commander
}