mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-22 18:26:41 +00:00
Move keepalive out of mgm pkg
This commit is contained in:
32
keepalive/monitor.go
Normal file
32
keepalive/monitor.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package keepalive
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
type ioMonitor struct {
|
||||
mu sync.Mutex
|
||||
grpc.ServerStream
|
||||
lastSeen time.Time
|
||||
}
|
||||
|
||||
func (l *ioMonitor) sendMsg(m interface{}) error {
|
||||
l.updateLastSeen()
|
||||
return l.ServerStream.SendMsg(m)
|
||||
}
|
||||
|
||||
func (l *ioMonitor) updateLastSeen() {
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
l.lastSeen = time.Now()
|
||||
}
|
||||
|
||||
func (l *ioMonitor) getLastSeen() time.Time {
|
||||
l.mu.Lock()
|
||||
t := l.lastSeen
|
||||
l.mu.Unlock()
|
||||
return t
|
||||
}
|
||||
Reference in New Issue
Block a user