ServerContext.swift 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. /// Additional information about an RPC handled by a server.
  17. public struct ServerContext: Sendable {
  18. /// A description of the method being called.
  19. public var descriptor: MethodDescriptor
  20. /// A description of the remote peer.
  21. ///
  22. /// The format of the description should follow the pattern "<transport>:<address>" where
  23. /// "<transport>" indicates the underlying network transport (such as "ipv4", "unix", or
  24. /// "in-process"). This is a guideline for how descriptions should be formatted; different
  25. /// implementations may not follow this format so you shouldn't make assumptions based on it.
  26. ///
  27. /// Some examples include:
  28. /// - "ipv4:127.0.0.1:31415",
  29. /// - "ipv6:[::1]:443",
  30. /// - "in-process:27182".
  31. public var peer: String
  32. /// A handle for checking the cancellation status of an RPC.
  33. public var cancellation: RPCCancellationHandle
  34. /// Create a new server context.
  35. ///
  36. /// - Parameters:
  37. /// - descriptor: A description of the method being called.
  38. /// - peer: A description of the remote peer.
  39. /// - cancellation: A cancellation handle. You can create a cancellation handle
  40. /// using ``withServerContextRPCCancellationHandle(_:)``.
  41. public init(
  42. descriptor: MethodDescriptor,
  43. peer: String,
  44. cancellation: RPCCancellationHandle
  45. ) {
  46. self.descriptor = descriptor
  47. self.peer = peer
  48. self.cancellation = cancellation
  49. }
  50. }