ServerHandlerStateMachine+Finished.swift 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright 2022, 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. #if compiler(>=5.6)
  17. import NIOHPACK
  18. @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
  19. extension ServerHandlerStateMachine {
  20. @usableFromInline
  21. internal struct Finished {
  22. @usableFromInline
  23. typealias NextStateAndOutput<Output> = ServerHandlerStateMachine.NextStateAndOutput<
  24. ServerHandlerStateMachine.Finished.NextState,
  25. Output
  26. >
  27. @inlinable
  28. internal init(from state: ServerHandlerStateMachine.Idle) {}
  29. @inlinable
  30. internal init(from state: ServerHandlerStateMachine.Handling) {}
  31. @inlinable
  32. internal init(from state: ServerHandlerStateMachine.Draining) {}
  33. @inlinable
  34. mutating func setResponseHeaders(
  35. _ headers: HPACKHeaders
  36. ) -> Self.NextStateAndOutput<Void> {
  37. return .init(nextState: .finished(self))
  38. }
  39. @inlinable
  40. mutating func setResponseTrailers(
  41. _ metadata: HPACKHeaders
  42. ) -> Self.NextStateAndOutput<Void> {
  43. return .init(nextState: .finished(self))
  44. }
  45. @inlinable
  46. mutating func handleMetadata() -> Self.NextStateAndOutput<HandleMetadataAction> {
  47. return .init(nextState: .finished(self), output: .cancel)
  48. }
  49. @inlinable
  50. mutating func handleMessage() -> Self.NextStateAndOutput<HandleMessageAction> {
  51. return .init(nextState: .finished(self), output: .cancel)
  52. }
  53. @inlinable
  54. mutating func handleEnd() -> Self.NextStateAndOutput<HandleEndAction> {
  55. return .init(nextState: .finished(self), output: .cancel)
  56. }
  57. @inlinable
  58. mutating func sendMessage() -> Self.NextStateAndOutput<SendMessageAction> {
  59. return .init(nextState: .finished(self), output: .drop)
  60. }
  61. @inlinable
  62. mutating func sendStatus() -> Self.NextStateAndOutput<SendStatusAction> {
  63. return .init(nextState: .finished(self), output: .drop)
  64. }
  65. @inlinable
  66. mutating func cancel() -> Self.NextStateAndOutput<CancelAction> {
  67. return .init(nextState: .finished(self), output: .cancelAndNilOutHandlerComponents)
  68. }
  69. }
  70. }
  71. #endif // compiler(>=5.6)