@@ -122,25 +122,27 @@ func newFile(fd uintptr, name string, kind newFileKind) *File {
122
122
// we assume they know what they are doing so we allow it to be
123
123
// used with kqueue.
124
124
if kind == kindOpenFile {
125
- var st syscall.Stat_t
126
125
switch runtime .GOOS {
127
- case "dragonfly" , "freebsd" , "netbsd" , "openbsd" :
126
+ case "darwin" , "dragonfly" , "freebsd" , "netbsd" , "openbsd" :
127
+ var st syscall.Stat_t
128
+ err := syscall .Fstat (fdi , & st )
129
+ typ := st .Mode & syscall .S_IFMT
128
130
// Don't try to use kqueue with regular files on *BSDs.
129
131
// On FreeBSD a regular file is always
130
132
// reported as ready for writing.
131
133
// On Dragonfly, NetBSD and OpenBSD the fd is signaled
132
134
// only once as ready (both read and write).
133
135
// Issue 19093.
134
- if err := syscall .Fstat (fdi , & st ); err == nil && st .Mode & syscall .S_IFMT == syscall .S_IFREG {
136
+ // Also don't add directories to the netpoller.
137
+ if err == nil && (typ == syscall .S_IFREG || typ == syscall .S_IFDIR ) {
135
138
pollable = false
136
139
}
137
140
138
- case "darwin" :
139
141
// In addition to the behavior described above for regular files,
140
142
// on Darwin, kqueue does not work properly with fifos:
141
143
// closing the last writer does not cause a kqueue event
142
144
// for any readers. See issue #24164.
143
- if err := syscall . Fstat ( fdi , & st ); err == nil && ( st . Mode & syscall . S_IFMT == syscall .S_IFIFO || st . Mode & syscall . S_IFMT == syscall . S_IFREG ) {
145
+ if runtime . GOOS == "darwin" && typ == syscall .S_IFIFO {
144
146
pollable = false
145
147
}
146
148
}
0 commit comments