ServerTransport.swift 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * Copyright 2023, 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. @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
  17. public protocol ServerTransport: Sendable {
  18. typealias Inbound = RPCAsyncSequence<RPCRequestPart>
  19. typealias Outbound = RPCWriter<RPCResponsePart>.Closable
  20. /// Starts the transport and returns a sequence of accepted streams to handle.
  21. ///
  22. /// Implementations will typically bind to a listening port when this function is called
  23. /// and start accepting new connections. Each accepted inbound RPC stream should be published
  24. /// to the async sequence returned by the function.
  25. ///
  26. /// You can call ``stopListening()`` to stop the transport from accepting new streams. Existing
  27. /// streams must be allowed to complete naturally. However, transports may also enforce a grace
  28. /// period after which any open streams may be cancelled. You can also cancel the task running
  29. /// ``listen()`` to abruptly close connections and streams.
  30. func listen() async throws -> RPCAsyncSequence<RPCStream<Inbound, Outbound>>
  31. /// Indicates to the transport that no new streams should be accepted.
  32. ///
  33. /// Existing streams are permitted to run to completion. However, the transport may also enforce
  34. /// a grace period, after which remaining streams are cancelled.
  35. func stopListening()
  36. }