---
title: "init(type:fileDescriptor:queue:cleanupHandler:)"
framework: dispatch
role: symbol
role_heading: Initializer
path: "dispatch/dispatchio/init(type:filedescriptor:queue:cleanuphandler:)"
---

# init(type:fileDescriptor:queue:cleanupHandler:)

Creates a new I/O channel that accesses the specified file descriptor.

## Declaration

```swift
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 doc://com.apple.dispatch/documentation/Dispatch/DispatchIO/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:

## Discussion

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.

## See Also

### Creating a Dispatch I/O Object

- [init(type:path:oflag:mode:queue:cleanupHandler:)](dispatch/dispatchio/init(type:path:oflag:mode:queue:cleanuphandler:)-50rb0.md)
- [init(type:io:queue:cleanupHandler:)](dispatch/dispatchio/init(type:io:queue:cleanuphandler:).md)
- [DispatchIO.StreamType](dispatch/dispatchio/streamtype.md)
