diff options
Diffstat (limited to 'src/os/file_unix.go')
-rw-r--r-- | src/os/file_unix.go | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/os/file_unix.go b/src/os/file_unix.go index f7f942f5f5..3d3a8b2056 100644 --- a/src/os/file_unix.go +++ b/src/os/file_unix.go @@ -116,12 +116,12 @@ const ( // kindNewFile means that the descriptor was passed to us via NewFile. kindNewFile newFileKind = iota // kindOpenFile means that the descriptor was opened using - // Open, Create, or OpenFile. + // Open, Create, or OpenFile (without O_NONBLOCK). kindOpenFile // kindPipe means that the descriptor was opened using Pipe. kindPipe - // kindNonBlock means that the descriptor was passed to us via NewFile, - // and the descriptor is already in non-blocking mode. + // kindNonBlock means that the descriptor is already in + // non-blocking mode. kindNonBlock // kindNoPoll means that we should not put the descriptor into // 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 { clearNonBlock := false if pollable { if kind == kindNonBlock { - f.nonblock = true + // The descriptor is already in non-blocking mode. + // We only set f.nonblock if we put the file into + // non-blocking mode. } else if err := syscall.SetNonblock(fdi, true); err == nil { f.nonblock = true clearNonBlock = true @@ -263,7 +265,12 @@ func openFileNolog(name string, flag int, perm FileMode) (*File, error) { syscall.CloseOnExec(r) } - f := newFile(uintptr(r), name, kindOpenFile) + kind := kindOpenFile + if unix.HasNonblockFlag(flag) { + kind = kindNonBlock + } + + f := newFile(uintptr(r), name, kind) f.pfd.SysFile = s return f, nil } |