mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
os: document and emphasize a potential misuse of File.Fd
This CL revises the document of File.Fd that explicitly points its user to runtime.SetFinalizer where contains the information that a file descriptor could be closed in a finalizer and therefore causes a failure in syscall.Write if runtime.KeepAlive is not invoked. The CL also suggests an alternative of File.Fd towards File.SyscallConn. Fixes #41505 Change-Id: I6816f0157add48b649bf1fb793cf19dcea6894b5 Reviewed-on: https://go-review.googlesource.com/c/go/+/256899 Reviewed-by: Rob Pike <r@golang.org> Trust: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
6f02578f9c
commit
7bb6fed9b5
4 changed files with 28 additions and 15 deletions
|
|
@ -62,8 +62,13 @@ type file struct {
|
|||
}
|
||||
|
||||
// Fd returns the integer Unix file descriptor referencing the open file.
|
||||
// The file descriptor is valid only until f.Close is called or f is garbage collected.
|
||||
// On Unix systems this will cause the SetDeadline methods to stop working.
|
||||
// If f is closed, the file descriptor becomes invalid.
|
||||
// If f is garbage collected, a finalizer may close the file descriptor,
|
||||
// making it invalid; see runtime.SetFinalizer for more information on when
|
||||
// a finalizer might be run. On Unix systems this will cause the SetDeadline
|
||||
// methods to stop working.
|
||||
//
|
||||
// As an alternative, see the f.SyscallCon method.
|
||||
func (f *File) Fd() uintptr {
|
||||
if f == nil {
|
||||
return ^(uintptr(0))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue