mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 22:34:02 +03:00
Cap max time in cloak mode
This commit is contained in:
+15
-6
@@ -9,7 +9,10 @@ import (
|
|||||||
"github.com/9seconds/mtg/wrappers/rwc"
|
"github.com/9seconds/mtg/wrappers/rwc"
|
||||||
)
|
)
|
||||||
|
|
||||||
const cloakTimeout = 5 * time.Second
|
const (
|
||||||
|
cloakLastActivityTimeout = 5 * time.Second
|
||||||
|
cloakMaxTimeout = 30 * time.Second
|
||||||
|
)
|
||||||
|
|
||||||
func cloak(one, another io.ReadWriteCloser) {
|
func cloak(one, another io.ReadWriteCloser) {
|
||||||
defer func() {
|
defer func() {
|
||||||
@@ -41,17 +44,23 @@ func cloak(one, another io.ReadWriteCloser) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
timer := time.NewTimer(cloakTimeout)
|
lastActivityTimer := time.NewTimer(cloakLastActivityTimeout)
|
||||||
defer timer.Stop()
|
defer lastActivityTimer.Stop()
|
||||||
|
|
||||||
|
maxTimer := time.NewTimer(cloakMaxTimeout)
|
||||||
|
defer maxTimer.Stop()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-channelPing:
|
case <-channelPing:
|
||||||
timer.Stop()
|
lastActivityTimer.Stop()
|
||||||
timer = time.NewTimer(cloakTimeout)
|
lastActivityTimer = time.NewTimer(cloakLastActivityTimeout)
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
case <-timer.C:
|
case <-lastActivityTimer.C:
|
||||||
|
cancel()
|
||||||
|
return
|
||||||
|
case <-maxTimer.C:
|
||||||
cancel()
|
cancel()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user