Documentation ¶
Overview ¶
Package rc provides reference counted file descriptors.
FD is a low level construct, and is useful only under very specific circumstances. In most use cases, managing file descriptors using the standard library os or net packages is a better choice.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUninitializedFD is the error returned by FD methods when called // on a file descriptor which has not been initialized. ErrUninitializedFD = errors.New("rc: use of uninitialized file descriptor") // ErrClosedFD is the error returned by FD methods when called on // a file descriptor which has been closed. ErrClosedFD = errors.New("rc: use of closed file descriptor") // ErrMultipleInit is the error returned by (*FD).Init when called // Init was already called on FD. ErrMultipleInit = errors.New("rc: multiple calls to (*FD).Init") )
Functions ¶
func WrapSyscallError ¶ added in v2.1.0
WrapSyscallError wraps an error from a call to (*FD).Do or (*FD).Close, with a few special cases taken into consideration:
The sentinel error values ErrUninitializedFD and ErrClosedFD are returned without wrapping. If err is nil, WrapSyscallError returns nil. Any other error is wrapped using os.NewSyscallError.
Types ¶
type FD ¶
type FD struct {
// contains filtered or unexported fields
}
FD is a reference counted file descriptor.
The zero value for FD is not usable. Values of type FD must be initialized by calling the Init method, and must not be copied.
Once initialized, it is safe to call methods on an FD from multiple goroutines.
FD is not suitable for use with blocking system calls: its internal locking scheme assumes that calls to Do do not block for very long.
Once an FD is closed, its methods return errors, and it may not be re-initialized.
func (*FD) Close ¶
Close waits for the reference count associated with the FD to reach zero, unsets the finalizer associated with fd, then closes the file descriptor.
Calling Close from inside a Do block causes a deadlock, so it is forbidden.