mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-24 17:41:29 +00:00
34 lines
606 B
Go
34 lines
606 B
Go
package libbox
|
|
|
|
import (
|
|
"sync"
|
|
"time"
|
|
)
|
|
|
|
type servicePauseFields struct {
|
|
pauseAccess sync.Mutex
|
|
pauseTimer *time.Timer
|
|
}
|
|
|
|
func (s *BoxService) Pause() {
|
|
s.pauseAccess.Lock()
|
|
defer s.pauseAccess.Unlock()
|
|
if s.pauseTimer != nil {
|
|
s.pauseTimer.Stop()
|
|
}
|
|
s.pauseTimer = time.AfterFunc(3*time.Second, s.ResetNetwork)
|
|
}
|
|
|
|
func (s *BoxService) Wake() {
|
|
s.pauseAccess.Lock()
|
|
defer s.pauseAccess.Unlock()
|
|
if s.pauseTimer != nil {
|
|
s.pauseTimer.Stop()
|
|
}
|
|
s.pauseTimer = time.AfterFunc(3*time.Minute, s.ResetNetwork)
|
|
}
|
|
|
|
func (s *BoxService) ResetNetwork() {
|
|
_ = s.instance.Router().ResetNetwork()
|
|
}
|