Преглед на файлове

Rename GRPCNIO to PlatformSupport (#522)

Motivation:

We were never really satisfied with the name "GRPCNIO" for the
namespace with functions to provide event loop groups
and bootstraps for NIO and NIOTS in a platform-agnostic way.

Modifications:

Rename GRPCNIO to PlatformSupport, add an availability attribute
to GRPCNIO to make it easier for users to update their code after
the renaming.

Result:

Slightly better naming.
George Barnett преди 6 години
родител
ревизия
876ee83395
променени са 6 файла, в които са добавени 14 реда и са изтрити 11 реда
  1. 3 3
      README.md
  2. 1 1
      Sources/GRPC/ClientConnection.swift
  3. 4 4
      Sources/GRPC/PlatformSupport.swift
  4. 1 1
      Sources/GRPC/Server.swift
  5. 3 0
      Sources/GRPC/Shims.swift
  6. 2 2
      Tests/GRPCTests/BasicEchoTestCase.swift

+ 3 - 3
README.md

@@ -205,7 +205,7 @@ logical cores on your system.
 We also `wait` for the server to start before setting up a client.
 We also `wait` for the server to start before setting up a client.
 
 
 ```swift
 ```swift
-let serverEventLoopGroup = GRPCNIO.makeEventLoopGroup(numberOfThreads: 1)
+let serverEventLoopGroup = PlatformSupport.makeEventLoopGroup(numberOfThreads: 1)
 let configuration = Server.Configuration(
 let configuration = Server.Configuration(
   target: .hostAndPort(address, port),
   target: .hostAndPort(address, port),
   eventLoopGroup: serverEventLoopGroup,
   eventLoopGroup: serverEventLoopGroup,
@@ -226,7 +226,7 @@ means to make gRPC calls via a generated client. Note that
 `Echo_EchoServiceClient` is the client we generated from `echo.proto`.
 `Echo_EchoServiceClient` is the client we generated from `echo.proto`.
 
 
 ```swift
 ```swift
-let clientEventLoopGroup = GRPCNIO.makeEventLoopGroup(loopCount: 1)
+let clientEventLoopGroup = PlatformSupport.makeEventLoopGroup(loopCount: 1)
 let configuration = ClientConnection.Configuration(
 let configuration = ClientConnection.Configuration(
   target: .hostAndPort(host, port),
   target: .hostAndPort(host, port),
   eventLoopGroup: clientEventLoopGroup
   eventLoopGroup: clientEventLoopGroup
@@ -421,7 +421,7 @@ gRPC Swift provides a helper method to provide the correct `EventLoopGroup`
 based on the network preference:
 based on the network preference:
 
 
 ```swift
 ```swift
-GRPCNIO.makeEventLoopGroup(loopCount:networkPreference:) -> EventLoopGroup
+PlatformSupport.makeEventLoopGroup(loopCount:networkPreference:) -> EventLoopGroup
 ```
 ```
 
 
 Here `networkPreference` defaults to `.best`, which chooses the
 Here `networkPreference` defaults to `.best`, which chooses the

+ 1 - 1
Sources/GRPC/ClientConnection.swift

@@ -332,7 +332,7 @@ extension ClientConnection {
     timeout: TimeInterval?,
     timeout: TimeInterval?,
     logger: Logger
     logger: Logger
   ) -> ClientBootstrapProtocol {
   ) -> ClientBootstrapProtocol {
-    let bootstrap = GRPCNIO.makeClientBootstrap(group: group)
+    let bootstrap = PlatformSupport.makeClientBootstrap(group: group)
       // Enable SO_REUSEADDR and TCP_NODELAY.
       // Enable SO_REUSEADDR and TCP_NODELAY.
       .channelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
       .channelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
       .channelOption(ChannelOptions.socket(IPPROTO_TCP, TCP_NODELAY), value: 1)
       .channelOption(ChannelOptions.socket(IPPROTO_TCP, TCP_NODELAY), value: 1)

+ 4 - 4
Sources/GRPC/GRPCNIO.swift → Sources/GRPC/PlatformSupport.swift

@@ -56,14 +56,14 @@ extension NetworkPreference {
     case .best:
     case .best:
       #if canImport(Network)
       #if canImport(Network)
       guard #available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *) else {
       guard #available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *) else {
-        GRPCNIO.logger.critical("Network.framework can be imported but is not supported on this platform")
+        PlatformSupport.logger.critical("Network.framework can be imported but is not supported on this platform")
         // This is gated by the availability of `.networkFramework` so should never happen.
         // This is gated by the availability of `.networkFramework` so should never happen.
         fatalError(".networkFramework is being used on an unsupported platform")
         fatalError(".networkFramework is being used on an unsupported platform")
       }
       }
-      GRPCNIO.logger.info("'best' NetworkImplementation is .networkFramework")
+      PlatformSupport.logger.info("'best' NetworkImplementation is .networkFramework")
       return .networkFramework
       return .networkFramework
       #else
       #else
-      GRPCNIO.logger.info("'best' NetworkImplementation is .posix")
+      PlatformSupport.logger.info("'best' NetworkImplementation is .posix")
       return .posix
       return .posix
       #endif
       #endif
 
 
@@ -120,7 +120,7 @@ extension NIOTSListenerBootstrap: ServerBootstrapProtocol {}
 
 
 // MARK: - Bootstrap / EventLoopGroup helpers
 // MARK: - Bootstrap / EventLoopGroup helpers
 
 
-public enum GRPCNIO {
+public enum PlatformSupport {
   static let logger = Logger(subsystem: .nio)
   static let logger = Logger(subsystem: .nio)
 
 
   /// Makes a new event loop group based on the network preference.
   /// Makes a new event loop group based on the network preference.

+ 1 - 1
Sources/GRPC/Server.swift

@@ -93,7 +93,7 @@ import NIOSSL
 public final class Server {
 public final class Server {
   /// Makes and configures a `ServerBootstrap` using the provided configuration.
   /// Makes and configures a `ServerBootstrap` using the provided configuration.
   public class func makeBootstrap(configuration: Configuration) -> ServerBootstrapProtocol {
   public class func makeBootstrap(configuration: Configuration) -> ServerBootstrapProtocol {
-    let bootstrap = GRPCNIO.makeServerBootstrap(group: configuration.eventLoopGroup)
+    let bootstrap = PlatformSupport.makeServerBootstrap(group: configuration.eventLoopGroup)
 
 
     // Backlog is only available on `ServerBootstrap`.
     // Backlog is only available on `ServerBootstrap`.
     if bootstrap is ServerBootstrap {
     if bootstrap is ServerBootstrap {

+ 3 - 0
Sources/GRPC/Shims.swift

@@ -32,3 +32,6 @@ extension Server.Configuration {
     return nil
     return nil
   }
   }
 }
 }
+
+@available(*, deprecated, renamed: "PlatformSupport")
+public enum GRPCNIO {}

+ 2 - 2
Tests/GRPCTests/BasicEchoTestCase.swift

@@ -144,14 +144,14 @@ class EchoTestCaseBase: GRPCTestCase {
 
 
   override func setUp() {
   override func setUp() {
     super.setUp()
     super.setUp()
-    self.serverEventLoopGroup = GRPCNIO.makeEventLoopGroup(
+    self.serverEventLoopGroup = PlatformSupport.makeEventLoopGroup(
       loopCount: 1,
       loopCount: 1,
       networkPreference: self.networkPreference)
       networkPreference: self.networkPreference)
     self.server = try! self.makeServer()
     self.server = try! self.makeServer()
 
 
     self.port = self.server.channel.localAddress!.port!
     self.port = self.server.channel.localAddress!.port!
 
 
-    self.clientEventLoopGroup = GRPCNIO.makeEventLoopGroup(
+    self.clientEventLoopGroup = PlatformSupport.makeEventLoopGroup(
       loopCount: 1,
       loopCount: 1,
       networkPreference: self.networkPreference)
       networkPreference: self.networkPreference)
     self.client = try! self.makeEchoClient(port: self.port)
     self.client = try! self.makeEchoClient(port: self.port)