Skip to content

Commit 3186707

Browse files
committed
darwin: implemented 'stop' in start_sync mode
1 parent 49985f3 commit 3186707

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

sync_darwin.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ func startSync() (chan<- bool, error) {
4747
Udata: nil,
4848
}
4949

50-
closeChan := make(chan bool)
51-
go func() {
52-
<-closeChan
53-
}()
54-
5550
// Ouput initial port state: get the current port list to send as initial "add" events
5651
current, err := enumerator.GetDetailedPortsList()
5752
if err != nil {
@@ -83,6 +78,8 @@ func startSync() (chan<- bool, error) {
8378
}
8479

8580
// Run synchronous event emitter
81+
closeChan := make(chan bool)
82+
8683
go func() {
8784
// wait for events
8885
events := make([]syscall.Kevent_t, 10)
@@ -92,6 +89,13 @@ func startSync() (chan<- bool, error) {
9289
for {
9390
t100ms := syscall.Timespec{Nsec: 100000000, Sec: 0}
9491
n, err := syscall.Kevent(kq, []syscall.Kevent_t{ev1}, events, &t100ms)
92+
select {
93+
case <-closeChan:
94+
syscall.Close(kq)
95+
syscall.Close(fd)
96+
return
97+
default:
98+
}
9599
if err == syscall.EINTR {
96100
continue
97101
}

0 commit comments

Comments
 (0)