Skip to content

Commit 2f53768

Browse files
committed
Fix darwin batch read not exit on stop
1 parent 9d97d95 commit 2f53768

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

tun_darwin.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,10 @@ func (t *NativeTun) Close() error {
158158
return t.tunFile.Close()
159159
}
160160
defer flushDNSCache()
161-
return E.Errors(t.unsetRoutes(), t.tunFile.Close())
161+
t.stopFd.Stop()
162+
err := E.Errors(t.unsetRoutes(), t.tunFile.Close())
163+
t.stopFd.Close()
164+
return err
162165
}
163166

164167
func (t *NativeTun) Read(p []byte) (n int, err error) {
@@ -356,6 +359,9 @@ func (t *NativeTun) BatchRead() ([]*buf.Buffer, error) {
356359
t.buffers = t.buffers[:0]
357360
return nil, errno
358361
}
362+
if n < 0 {
363+
return nil, os.ErrClosed
364+
}
359365
if n < 1 {
360366
return nil, nil
361367
}

0 commit comments

Comments
 (0)