blob: 948c0c77e9f419ea08853bf1967aa0c2b994f898 [file] [log] [blame]
Asim Shankar89fdae82014-10-10 16:13:24 -07001// +build !linux,!darwin,!dragonfly,!freebsd,!netbsd,!openbsd
Benjamin Prosnitza375b912014-10-07 14:53:42 -07002// TODO(bprosnitz) Should change for nacl?
David Why Use Two When One Will Do Presottof6813ec2014-07-11 16:12:54 -07003
4package netconfig
5
6// Code to signal a network change every 2 minutes. We use
7// this for systems where we don't yet have a good way to
8// watch for network changes.
9
10import (
11 "time"
12)
13
14type timerNetConfigWatcher struct {
15 c chan struct{} // channel to signal confg changes
16 stop chan struct{} // channel to tell the watcher to stop
17}
18
19// Stop any waiter
20func (w *timerNetConfigWatcher) Stop() {
21 w.stop <- struct{}{}
22}
23
24func (w *timerNetConfigWatcher) Channel() chan struct{} {
25 return w.c
26}
27
28func (w *timerNetConfigWatcher) watcher() {
29 for {
30 select {
31 case <-w.stop:
32 close(w.c)
33 return
34 case <-time.NewTimer(2 * time.Minute).C:
35 select {
36 case w.c <- struct{}{}:
37 default:
38 }
39 }
40 }
41}
42
43func NewNetConfigWatcher() (NetConfigWatcher, error) {
Benjamin Prosnitza375b912014-10-07 14:53:42 -070044 w := &timerNetConfigWatcher{}
David Why Use Two When One Will Do Presottof6813ec2014-07-11 16:12:54 -070045 w.c = make(chan struct{})
46 w.stop = make(chan struct{}, 1)
47 go w.watcher()
48 return w, nil
49}
Benjamin Prosnitza375b912014-10-07 14:53:42 -070050
51func GetIPRoutes(defaultOnly bool) []*IPRoute {
Nicolas LaCassefea49162014-11-17 15:41:03 -080052 // TODO(nlacasse,bprosnitz): Consider implementing? For now return
53 // empty array, since that seems to keep things working.
54 return []*IPRoute{}
Benjamin Prosnitza375b912014-10-07 14:53:42 -070055}