mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 01:57:12 -05:00
45 lines
594 B
Go
45 lines
594 B
Go
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()
|
|
}
|
|
|
|
func (c *syncCommander) Close() error {
|
|
c.RLock()
|
|
defer c.RUnlock()
|
|
|
|
if c.Commander == nil {
|
|
return nil
|
|
}
|
|
|
|
return c.Commander.Close()
|
|
}
|
|
|
|
func (c *syncCommander) Set(commander Commander) {
|
|
c.Lock()
|
|
defer c.Unlock()
|
|
|
|
c.Commander = commander
|
|
}
|