mirror of
https://github.com/apple/swift-nio
synced 2026-11-26 04:57:49 +00:00
Motivation: This is the next stage of our move of common interchange objects to NIOCore and out of the NIO module. This time around we need SocketAddress, which is part of the Channel API. Sadly, SocketAddress is not as clean as some of the other ports, because it leaks a number of POSIX-y concepts. This also forces us to bring along NIOBSDSocket, which ideally we would not move, but we foolishly exposed as API on SocketAddress. Modifications: - Move NIOBSDSocket API components into NIOCore. - Split out the internal abstractions for NIOBSDSocket and leave those in NIO. - Move SocketAddress into NIOCore. Result: SocketAddress will be sitting in NIOCore.
35 lines
1.0 KiB
Swift
35 lines
1.0 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the SwiftNIO open source project
|
|
//
|
|
// Copyright (c) 2017-2021 Apple Inc. and the SwiftNIO project authors
|
|
// Licensed under Apache License v2.0
|
|
//
|
|
// See LICENSE.txt for license information
|
|
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
internal extension IOResult where T: FixedWidthInteger {
|
|
var result: T {
|
|
switch self {
|
|
case .processed(let value):
|
|
return value
|
|
case .wouldBlock(_):
|
|
fatalError("cannot unwrap IOResult")
|
|
}
|
|
}
|
|
}
|
|
|
|
/// An result for an IO operation that was done on a non-blocking resource.
|
|
enum IOResult<T: Equatable>: Equatable {
|
|
|
|
/// Signals that the IO operation could not be completed as otherwise we would need to block.
|
|
case wouldBlock(T)
|
|
|
|
/// Signals that the IO operation was completed.
|
|
case processed(T)
|
|
}
|