Files
netbird/keepalive/monitor.go
2023-06-28 02:08:09 +02:00

36 lines
548 B
Go

package keepalive
import (
"sync"
"time"
"google.golang.org/grpc"
)
type ioMonitor struct {
mu sync.Mutex
streamLock sync.Mutex
grpc.ServerStream
lastSeen time.Time
}
func (l *ioMonitor) sendMsg(m interface{}) error {
l.updateLastSeen()
l.streamLock.Lock()
defer l.streamLock.Unlock()
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
}