init(type:fileDescriptor:queue:cleanupHandler:)
Creates a new I/O channel that accesses the specified file descriptor.
Declaration
convenience init(type: DispatchIO.StreamType, fileDescriptor: Int32, queue: DispatchQueue, cleanupHandler: @escaping (Int32) -> Void)Parameters
- type:
The access semantics for the channel. For a list of possible values, see Streamtype.
- fileDescriptor:
The file descriptor from which to read or write data.
- queue:
The dispatch queue on which to perform work.
- cleanupHandler:
The handler to execute once the channel is closed. This block has no return value and takes the following parameter:
- error
An
errnocondition if creating or opening the channel failed; otherwise, the value is0.
Discussion
The channel takes control of the specified file descriptor until the channel closes, either deliberately on your part or because an error occurred. While the channel owns the file descriptor, the system modifies flags such as O_NONBLOCK automatically. It is a programmer error for you to modify the file descriptor while the channel owns it. However, you may create additional channels based on the same file descriptor.