ServerContext.swift 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. @available(*, deprecated, renamed: "remotePeer")
  32. public var peer: String {
  33. get { remotePeer }
  34. set { remotePeer = newValue }
  35. }
  36. /// A description of the remote peer.
  37. ///
  38. /// The format of the description should follow the pattern "<transport>:<address>" where
  39. /// "<transport>" indicates the underlying network transport (such as "ipv4", "unix", or
  40. /// "in-process"). This is a guideline for how descriptions should be formatted; different
  41. /// implementations may not follow this format so you shouldn't make assumptions based on it.
  42. ///
  43. /// Some examples include:
  44. /// - "ipv4:127.0.0.1:31415",
  45. /// - "ipv6:[::1]:443",
  46. /// - "in-process:27182".
  47. public var remotePeer: String
  48. /// A description of the local peer.
  49. ///
  50. /// The format of the description should follow the pattern "<transport>:<address>" where
  51. /// "<transport>" indicates the underlying network transport (such as "ipv4", "unix", or
  52. /// "in-process"). This is a guideline for how descriptions should be formatted; different
  53. /// implementations may not follow this format so you shouldn't make assumptions based on it.
  54. ///
  55. /// Some examples include:
  56. /// - "ipv4:127.0.0.1:31415",
  57. /// - "ipv6:[::1]:443",
  58. /// - "in-process:27182".
  59. public var localPeer: String
  60. /// A handle for checking the cancellation status of an RPC.
  61. public var cancellation: RPCCancellationHandle
  62. /// Create a new server context.
  63. ///
  64. /// - Parameters:
  65. /// - descriptor: A description of the method being called.
  66. /// - remotePeer: A description of the remote peer.
  67. /// - localPeer: A description of the local peer.
  68. /// - cancellation: A cancellation handle. You can create a cancellation handle
  69. /// using ``withServerContextRPCCancellationHandle(_:)``.
  70. public init(
  71. descriptor: MethodDescriptor,
  72. remotePeer: String,
  73. localPeer: String,
  74. cancellation: RPCCancellationHandle
  75. ) {
  76. self.descriptor = descriptor
  77. self.remotePeer = remotePeer
  78. self.localPeer = localPeer
  79. self.cancellation = cancellation
  80. }
  81. }