Skip to content

Commit 58ac671

Browse files
committed
Add a few more comments.
1 parent 4af0796 commit 58ac671

File tree

5 files changed

+12
-0
lines changed

5 files changed

+12
-0
lines changed

Sources/SwiftGRPCNIO/GRPCChannelHandler.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,22 @@ import SwiftGRPC
44
import NIO
55
import NIOHTTP1
66

7+
// Processes individual gRPC messages and stream-close events on a HTTP2 channel.
78
public protocol GRPCCallHandler {
89
func messageReceived(_ message: inout NIO.ByteBuffer)
910
func endOfStreamReceived()
1011
}
1112

13+
// Provides `GRPCCallHandler` objects for the methods on a particular service name.
1214
public protocol CallHandlerProvider {
1315
var serviceName: String { get }
1416

1517
func handleMethod(_ methodName: String, headers: HTTPHeaders, serverHandler: GRPCChannelHandler, ctx: ChannelHandlerContext) -> GRPCCallHandler?
1618
}
1719

20+
// Listens on a newly-opened HTTP2 channel and waits for the request headers to become available.
21+
// Once those are available, asks the `CallHandlerProvider` corresponding to the request's service name for an
22+
// `GRPCCallHandler` object. That object is then forwarded the individual gRPC messages.
1823
public final class GRPCChannelHandler: ChannelInboundHandler {
1924
public typealias InboundIn = RawGRPCServerRequestPart
2025
public typealias OutboundOut = RawGRPCServerResponsePart

Sources/SwiftGRPCNIO/GRPCServer.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import NIO
33
import NIOHTTP1
44
import NIOHTTP2
55

6+
// Wrapper object to manage the lifecycle of a gRPC server.
67
public final class GRPCServer {
78
public static func start(
89
hostname: String,
@@ -17,6 +18,7 @@ public final class GRPCServer {
1718

1819
// Set the handlers that are applied to the accepted Channels
1920
.childChannelInitializer { channel in
21+
//! FIXME: Add an option for gRPC-via-HTTP1 (pPRC).
2022
return channel.pipeline.add(handler: HTTP2Parser(mode: .server)).then {
2123
let multiplexer = HTTP2StreamMultiplexer { (channel, streamID) -> EventLoopFuture<Void> in
2224
return channel.pipeline.add(handler: HTTP2ToHTTP1ServerCodec(streamID: streamID))

Sources/SwiftGRPCNIO/GRPCServerCodec.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public enum GRPCServerResponsePart<MessageType: Message> {
1717

1818
/// A simple channel handler that translates raw gRPC packets into decoded protobuf messages,
1919
/// and vice versa.
20+
/// **Currently unused, as we do not yet know the request's method name (and thus message types) when this object is instantiated.**
2021
public final class GRPCServerCodec<RequestMessage: Message, ResponseMessage: Message>: ChannelInboundHandler, ChannelOutboundHandler {
2122
public typealias InboundIn = RawGRPCServerRequestPart
2223
public typealias InboundOut = GRPCServerRequestPart<RequestMessage>

Sources/SwiftGRPCNIO/StatusSendingHandler.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import SwiftGRPC
44
import NIO
55
import NIOHTTP1
66

7+
// Provides a means for decoding incoming gRPC messages into protobuf objects, and exposes a promise that should be
8+
// fulfilled when it is time to return a status to the client.
79
public class StatusSendingHandler<RequestMessage: Message>: GRPCCallHandler {
810
let statusPromise: EventLoopPromise<ServerStatus>
911

Sources/SwiftGRPCNIO/UnaryResponseHandler.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import SwiftGRPC
44
import NIO
55
import NIOHTTP1
66

7+
// Exposes a promise that should be fulfilled when it is time to return a unary response (for unary and client-streaming
8+
// calls) to the client. Also see `StatusSendingHandler`.
79
public class UnaryResponseHandler<RequestMessage: Message, ResponseMessage: Message>: StatusSendingHandler<RequestMessage> {
810
let responsePromise: EventLoopPromise<ResponseMessage>
911

0 commit comments

Comments
 (0)