ConnectionFactory.swift 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright 2024, gRPC Authors All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import NIOCore
  17. import NIOHTTP2
  18. import NIOPosix
  19. @_spi(Package)
  20. @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
  21. public protocol HTTP2Connector: Sendable {
  22. func establishConnection(to address: SocketAddress) async throws -> HTTP2Connection
  23. }
  24. @_spi(Package)
  25. @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
  26. public struct HTTP2Connection {
  27. /// The underlying TCP connection wrapped up for use with gRPC.
  28. var channel: NIOAsyncChannel<ClientConnectionEvent, Void>
  29. /// An HTTP/2 stream multiplexer.
  30. var multiplexer: NIOHTTP2Handler.AsyncStreamMultiplexer<Void>
  31. /// Whether the connection is insecure (i.e. plaintext).
  32. var isPlaintext: Bool
  33. public init(
  34. channel: NIOAsyncChannel<ClientConnectionEvent, Void>,
  35. multiplexer: NIOHTTP2Handler.AsyncStreamMultiplexer<Void>,
  36. isPlaintext: Bool
  37. ) {
  38. self.channel = channel
  39. self.multiplexer = multiplexer
  40. self.isPlaintext = isPlaintext
  41. }
  42. }