@@ -116,12 +116,12 @@ const (
116116 // kindNewFile means that the descriptor was passed to us via NewFile.
117117 kindNewFile newFileKind = iota
118118 // kindOpenFile means that the descriptor was opened using
119- // Open, Create, or OpenFile.
119+ // Open, Create, or OpenFile (without O_NONBLOCK) .
120120 kindOpenFile
121121 // kindPipe means that the descriptor was opened using Pipe.
122122 kindPipe
123- // kindNonBlock means that the descriptor was passed to us via NewFile,
124- // and the descriptor is already in non-blocking mode.
123+ // kindNonBlock means that the descriptor is already in
124+ // non-blocking mode.
125125 kindNonBlock
126126 // kindNoPoll means that we should not put the descriptor into
127127 // non-blocking mode, because we know it is not a pipe or FIFO.
@@ -184,7 +184,9 @@ func newFile(fd uintptr, name string, kind newFileKind) *File {
184184 clearNonBlock := false
185185 if pollable {
186186 if kind == kindNonBlock {
187- f .nonblock = true
187+ // The descriptor is already in non-blocking mode.
188+ // We only set f.nonblock if we put the file into
189+ // non-blocking mode.
188190 } else if err := syscall .SetNonblock (fdi , true ); err == nil {
189191 f .nonblock = true
190192 clearNonBlock = true
@@ -263,7 +265,12 @@ func openFileNolog(name string, flag int, perm FileMode) (*File, error) {
263265 syscall .CloseOnExec (r )
264266 }
265267
266- f := newFile (uintptr (r ), name , kindOpenFile )
268+ kind := kindOpenFile
269+ if unix .HasNonblockFlag (flag ) {
270+ kind = kindNonBlock
271+ }
272+
273+ f := newFile (uintptr (r ), name , kind )
267274 f .pfd .SysFile = s
268275 return f , nil
269276}
0 commit comments