ServerHandlerStateMachine+Finished.swift 2.5 KB

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