init(type:path:oflag:mode:queue:cleanupHandler:)
Creates a new I/O channel that accesses the file at the specified path, potentially creating that file in the process.
Declaration
convenience init?(type: DispatchIO.StreamType, path: UnsafePointer<Int8>, oflag: Int32, mode: mode_t, queue: DispatchQueue, cleanupHandler: @escaping (Int32) -> Void)Parameters
- type:
The access semantics for the channel. For a list of possible values, see Streamtype.
- path:
The absolute path of the file you want to open.
- oflag:
The flags to pass to
open(2)when opening the file at the specified path. - mode:
The mode flags to pass to
open(2). SpecifyO_CREATto create the file at the specified path; otherwise, specify 0. - 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
This method opens the channel by passing the path, oflag, and mode parameters to the low-level open(2) function. The file descriptor returned by that function remains open and under system control until you close the channel, or until an error occurs that causes the channel to release the file descriptor. After closing the file descriptor, the channel executes the specified cleanupHandler block on queue.