2024-02-08 22:14:09 +08:00
|
|
|
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()
|
|
|
|
}
|
2024-06-08 20:27:08 +08:00
|
|
|
s.pauseTimer = time.AfterFunc(3*time.Second, s.ResetNetwork)
|
2024-02-08 22:14:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *BoxService) Wake() {
|
|
|
|
s.pauseAccess.Lock()
|
|
|
|
defer s.pauseAccess.Unlock()
|
|
|
|
if s.pauseTimer != nil {
|
|
|
|
s.pauseTimer.Stop()
|
|
|
|
}
|
2024-06-08 20:27:08 +08:00
|
|
|
s.pauseTimer = time.AfterFunc(3*time.Minute, s.ResetNetwork)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *BoxService) ResetNetwork() {
|
2024-11-10 12:11:21 +08:00
|
|
|
s.instance.Router().ResetNetwork()
|
2024-02-08 22:14:09 +08:00
|
|
|
}
|