Asim Shankar | 89fdae8 | 2014-10-10 16:13:24 -0700 | [diff] [blame] | 1 | // +build !linux,!darwin,!dragonfly,!freebsd,!netbsd,!openbsd |
Benjamin Prosnitz | a375b91 | 2014-10-07 14:53:42 -0700 | [diff] [blame] | 2 | // TODO(bprosnitz) Should change for nacl? |
David Why Use Two When One Will Do Presotto | f6813ec | 2014-07-11 16:12:54 -0700 | [diff] [blame] | 3 | |
| 4 | package 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 | |
| 10 | import ( |
| 11 | "time" |
| 12 | ) |
| 13 | |
| 14 | type 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 |
| 20 | func (w *timerNetConfigWatcher) Stop() { |
| 21 | w.stop <- struct{}{} |
| 22 | } |
| 23 | |
| 24 | func (w *timerNetConfigWatcher) Channel() chan struct{} { |
| 25 | return w.c |
| 26 | } |
| 27 | |
| 28 | func (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 | |
| 43 | func NewNetConfigWatcher() (NetConfigWatcher, error) { |
Benjamin Prosnitz | a375b91 | 2014-10-07 14:53:42 -0700 | [diff] [blame] | 44 | w := &timerNetConfigWatcher{} |
David Why Use Two When One Will Do Presotto | f6813ec | 2014-07-11 16:12:54 -0700 | [diff] [blame] | 45 | w.c = make(chan struct{}) |
| 46 | w.stop = make(chan struct{}, 1) |
| 47 | go w.watcher() |
| 48 | return w, nil |
| 49 | } |
Benjamin Prosnitz | a375b91 | 2014-10-07 14:53:42 -0700 | [diff] [blame] | 50 | |
| 51 | func GetIPRoutes(defaultOnly bool) []*IPRoute { |
| 52 | panic("Not yet implemented") |
| 53 | } |