FileDescriptor
public final class FileDescriptor
A handle used to access a file or other input/output resource, such as a pipe or network socket.
-
File descriptor handle.
Declaration
Swift
public private(set) var fileDescriptor: Int32
-
Creates a
FileDescriptor
from a file descriptor handle and configures it as non-blocking.Throws
The following errors might be thrown:
VeniceError.invalidFileDescriptor
Thrown when
fileDescriptor
is not an open file descriptor.Declaration
Swift
public init(_ fileDescriptor: Int32) throws
Parameters
fileDescriptor
Previously opened file descriptor.
-
Waits for the file descriptor to become either readable/writable or to get into an error state. Either case leads to a successful return from the function. To distinguish the two outcomes, follow up with a read/write operation on the file descriptor.
Throws
The following errors might be thrown:
VeniceError.invalidFileDescriptor
Thrown when the operation is performed on an invalid file descriptor.
VeniceError.canceled
Thrown when the operation is performed within a closed coroutine.
VeniceError.fileDescriptorBlockedInAnotherCoroutine
Thrown when another coroutine is already blocked on
poll
with this file descriptor.VeniceError.deadlineReached
Thrown when the operation reaches the deadline.
VeniceError.unexpectedError
Thrown when an unexpected error occurs. This should never happen in the regular flow of an application.
Parameters
event
Use
.read
to wait for the file descriptor to become readable. Use.write
to wait for the file descriptor to become writable.deadline
deadline
is a point in time when the operation should timeout. Use the.fromNow()
function to get the current point in time. Use.immediate
if the operation needs to be performed without blocking. Use.never
to allow the operation to block forever if needed. -
Erases cached info about a file descriptor.
This function drops any state that Venice associates with the file descriptor.
Warning
clean
has to be called with file descriptors provided by third-party libraries, just before returning them back to their original owners. Otherwise the behavior is undefined.Declaration
Swift
public func clean()
-
Closes a file descriptor, so that it no longer refers to any file and may be reused. Any record locks held on the file it was associated with, and owned by the process, are removed (regardless of the file descriptor that was used to obtain the lock).
Warning
If
fileDescriptor
is the last file descriptor referring to the underlying open file description, the resources associated with the open file description are freed; if the file descriptor was the last reference to a file which has been removed usingunlink
, the file is deleted.Throws
The following errors might be thrown:
VeniceError.invalidFileDescriptor
Thrown when
fileDescriptor
is not an open file descriptor.Declaration
Swift
public func close() throws
-
Detaches the underlying
fileDescriptor
. Afterdetach
any operation will throw an error.Declaration
Swift
@discardableResult public func detach() -> Int32
Return Value
The underlying file descriptor.
-
Event used to poll file descriptors for reading or writing.
See moreDeclaration
Swift
public enum PollEvent