class UniqueFD
Swift
final class UniqueFD
An owned file descriptor: closed when the last reference goes away.
The Swift type of the IDL fd wherever the descriptor changes hands: a
proxy returns one for an out or return value, and a servant receives
one for an in argument and returns one for its outputs. An in
argument on the proxy side is a plain Int32 borrowed for the call —
the runtime sends a duplicate, so a descriptor that came from C++ stays
C++'s.
To hand a received descriptor on to C++, take it with release(); from
then on it is the caller's to close.
Only a transport that can carry descriptors between processes can send one (shared memory, on Linux); over anything else such a call throws before it is sent.
nprpc_swift/Sources/NPRPC/UniqueFD.swift:22
Constructors
init(adopting fd: Int32)
Takes ownership of fd; -1 for none.
nprpc_swift/Sources/NPRPC/UniqueFD.swift:27
convenience init(duplicating fd: Int32) throws
Owns a close-on-exec duplicate of fd, which stays the caller's.
nprpc_swift/Sources/NPRPC/UniqueFD.swift:32
Properties
var isValid: Bool { get }
Whether there is a descriptor.
nprpc_swift/Sources/NPRPC/UniqueFD.swift:53
var rawValue: Int32 { get }
The descriptor, still owned; -1 if none.
nprpc_swift/Sources/NPRPC/UniqueFD.swift:47
Methods
func close()
Closes the descriptor now rather than on deinit.
nprpc_swift/Sources/NPRPC/UniqueFD.swift:64
func release() -> Int32
Gives up ownership without closing; -1 if there was none.
nprpc_swift/Sources/NPRPC/UniqueFD.swift:56