<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "Dispatch",
  "identifier" : "/documentation/Dispatch/DispatchIO/init(type:fileDescriptor:queue:cleanupHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Dispatch"
    ],
    "preciseIdentifier" : "s:So14OS_dispatch_ioC8DispatchE4type14fileDescriptor5queue14cleanupHandlerA2bCE10StreamTypeO_s5Int32VSo0a1_b1_H0CyAKctcfc"
  },
  "title" : "init(type:fileDescriptor:queue:cleanupHandler:)"
}
-->

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

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

```
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 [`DispatchIO.StreamType`](/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:

- error: An `errno` condition if creating or opening the channel failed; otherwise, the value is `0`.

## 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.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)