-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotifier_impl_linux.go
65 lines (56 loc) · 1006 Bytes
/
notifier_impl_linux.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//+build !windows,!darwin
package networkchangenotifier
import (
"sync"
"time"
"github.com/vishvananda/netlink"
)
type nullstruct struct {
}
func ncnInit() error {
var err error
stopped = false
done = make(chan struct{})
return err
}
var done chan struct{}
var once sync.Once
var stopped bool
func ncnRegisterCallback() {
once.Do(func() {
go func() {
ch := make(chan netlink.RouteUpdate)
if err := netlink.RouteSubscribeWithOptions(ch, done, netlink.RouteSubscribeOptions{
ErrorCallback: func(err error) {
if err != nil {
stopped = true
return
}
},
}); err != nil {
return
}
for {
timeout := time.After(time.Second)
select {
case update := <-ch:
callback_linux(&update)
case <-timeout:
if stopped {
break
}
continue
}
}
}()
})
}
func ncnUnregisterCallback() {
}
func ncnCleanup() error {
var err error
// ncnUnregisterCallback()
// done <- nullstruct{}
// close(done)
return err
}