Selaa lähdekoodia

Remove redundant "Echo2" sample.

Tim Burks 7 vuotta sitten
vanhempi
commit
4a8b3a19dc

+ 0 - 14
Examples/Echo2/Makefile

@@ -1,14 +0,0 @@
-PATH := ../../Plugin:$(PATH)
-
-all:
-	protoc Protos/*.proto -IProtos --swift_out=Sources --swiftgrpc_out=Sources 
-	swift build -c release
-	cp .build/release/Echo .
-
-project:
-	swift package generate-xcodeproj
-
-clean :
-	rm -rf Packages googleapis .build
-	rm -f Package.pins Echo Sources/*.pb.swift Sources/*.grpc.swift google.json
-	rm -rf Package.resolved Echo.xcodeproj

+ 0 - 35
Examples/Echo2/Package.swift

@@ -1,35 +0,0 @@
-// swift-tools-version:4.0
-
-/*
- * Copyright 2017, gRPC Authors All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-import PackageDescription
-
-let package = Package(
-  name: "Echo",
-  dependencies: [
-    .package(url: "../..", .branch("HEAD")),
-    .package(url: "https://github.com/apple/swift-protobuf.git", from: "1.0.2"),
-    .package(url: "https://github.com/kylef/Commander.git", from: "0.8.0")
-  ],
-  targets: [
-    .target(name: "Echo",
-            dependencies: [
-              "SwiftGRPC",
-              "SwiftProtobuf",
-              "Commander"
-            ],
-	    path: "Sources")
-  ])

+ 0 - 33
Examples/Echo2/Protos/echo.proto

@@ -1,33 +0,0 @@
-// Copyright (c) 2015, Google Inc.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-syntax = "proto3";
-
-package echo;
-
-import "echo_messages.proto";
-
-service Echo {
-  // Immediately returns an echo of a request.
-  rpc Get(EchoRequest) returns (EchoResponse) {}
-  
-  // Splits a request into words and returns each word in a stream of messages.
-  rpc Expand(EchoRequest) returns (stream EchoResponse) {}  
-  
-  // Collects a stream of messages and returns them concatenated when the caller closes.
-  rpc Collect(stream EchoRequest) returns (EchoResponse) {}
-  
-  // Streams back messages as they are received in an input stream.
-  rpc Update(stream EchoRequest) returns (stream EchoResponse) {}
-}

+ 0 - 27
Examples/Echo2/Protos/echo_messages.proto

@@ -1,27 +0,0 @@
-// Copyright (c) 2015, Google Inc.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-syntax = "proto3";
-
-package echo;
-
-message EchoRequest {
-  // The text of a message to be echoed.
-  string text = 1;
-}
-
-message EchoResponse {
-  // The text of an echo response.
-  string text = 1;
-}

+ 0 - 6
Examples/Echo2/README.md

@@ -1,6 +0,0 @@
-# Echo2
-
-This directory contains a minor variation of the Echo
-sample that divides the echo.proto into two parts: one
-containing message definitions and one for service 
-definitions.

+ 0 - 16
Examples/Echo2/RUNME

@@ -1,16 +0,0 @@
-#!/bin/sh
-#
-# Use this script to regenerate the Protocol Buffer and gRPC files
-# needed to build the example.
-#
-# Note that it requires updated protoc, protoc-gen-swift, and
-# protoc-gen-swiftgrpc binaries and assumes that protoc-gen-swift 
-# is installed in $HOME/local/bin.
-
-PATH=../../Plugin:$PATH
-protoc \
-	Protos/*.proto \
-	--swift_out=Sources \
-	--swiftgrpc_out=Sources \
- 	-IProtos 
-

+ 0 - 80
Examples/Echo2/Sources/EchoProvider.swift

@@ -1,80 +0,0 @@
-/*
- * Copyright 2016, gRPC Authors All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-import Dispatch
-import Foundation
-
-class EchoProvider: Echo_EchoProvider {
-  // get returns requests as they were received.
-  func get(request: Echo_EchoRequest, session _: Echo_EchoGetSession) throws -> Echo_EchoResponse {
-    var response = Echo_EchoResponse()
-    response.text = "Swift echo get: " + request.text
-    return response
-  }
-
-  // expand splits a request into words and returns each word in a separate message.
-  func expand(request: Echo_EchoRequest, session: Echo_EchoExpandSession) throws {
-    let parts = request.text.components(separatedBy: " ")
-    var i = 0
-    for part in parts {
-      var response = Echo_EchoResponse()
-      response.text = "Swift echo expand (\(i)): \(part)"
-      let sem = DispatchSemaphore(value: 0)
-      try session.send(response) { sem.signal() }
-      _ = sem.wait(timeout: DispatchTime.distantFuture)
-      i += 1
-      sleep(1)
-    }
-  }
-
-  // collect collects a sequence of messages and returns them concatenated when the caller closes.
-  func collect(session: Echo_EchoCollectSession) throws {
-    var parts: [String] = []
-    while true {
-      do {
-        let request = try session.receive()
-        parts.append(request.text)
-      } catch Echo_EchoServerError.endOfStream {
-        break
-      } catch (let error) {
-        print("\(error)")
-      }
-    }
-    var response = Echo_EchoResponse()
-    response.text = "Swift echo collect: " + parts.joined(separator: " ")
-    try session.sendAndClose(response)
-  }
-
-  // update streams back messages as they are received in an input stream.
-  func update(session: Echo_EchoUpdateSession) throws {
-    var count = 0
-    while true {
-      do {
-        let request = try session.receive()
-        count += 1
-        var response = Echo_EchoResponse()
-        response.text = "Swift echo update (\(count)): \(request.text)"
-        let sem = DispatchSemaphore(value: 0)
-        try session.send(response) { sem.signal() }
-        _ = sem.wait(timeout: DispatchTime.distantFuture)
-      } catch Echo_EchoServerError.endOfStream {
-        break
-      } catch (let error) {
-        print("\(error)")
-      }
-    }
-    try session.close()
-  }
-}

+ 0 - 239
Examples/Echo2/Sources/main.swift

@@ -1,239 +0,0 @@
-/*
- * Copyright 2017, gRPC Authors All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-import Commander
-import Dispatch
-import Foundation
-import gRPC
-
-// Common flags and options
-let sslFlag = Flag("ssl", description: "if true, use SSL for connections")
-func addressOption(_ address: String) -> Option<String> {
-  return Option("address", default: address, description: "address of server")
-}
-
-let portOption = Option("port",
-                        default: "8080",
-                        description: "port of server")
-let messageOption = Option("message",
-                           default: "Testing 1 2 3",
-                           description: "message to send")
-
-// Helper function for client actions
-func buildEchoService(_ ssl: Bool, _ address: String, _ port: String, _: String)
-  -> Echo_EchoServiceClient {
-  var service: Echo_EchoServiceClient
-  if ssl {
-    let certificateURL = URL(fileURLWithPath: "ssl.crt")
-    let certificates = try! String(contentsOf: certificateURL)
-    service = Echo_EchoServiceClient(address: address + ":" + port,
-                               certificates: certificates,
-                               host: "example.com")
-    service.host = "example.com"
-  } else {
-    service = Echo_EchoServiceClient(address: address + ":" + port, secure: false)
-  }
-  service.metadata = Metadata([
-    "x-goog-api-key": "YOUR_API_KEY",
-    "x-ios-bundle-identifier": "io.grpc.echo"
-  ])
-  return service
-}
-
-Group {
-  $0.command("serve",
-             sslFlag,
-             addressOption("0.0.0.0"),
-             portOption,
-             description: "Run an echo server.") { ssl, address, port in
-    let sem = DispatchSemaphore(value: 0)
-    let echoProvider = EchoProvider()
-    var echoServer: Echo_EchoServer?
-    if ssl {
-      print("starting secure server")
-      let certificateURL = URL(fileURLWithPath: "ssl.crt")
-      let keyURL = URL(fileURLWithPath: "ssl.key")
-      echoServer = Echo_EchoServer(address: address + ":" + port,
-                                   certificateURL: certificateURL,
-                                   keyURL: keyURL,
-                                   provider: echoProvider)
-      echoServer?.start()
-    } else {
-      print("starting insecure server")
-      echoServer = Echo_EchoServer(address: address + ":" + port,
-                                   provider: echoProvider)
-      echoServer?.start()
-    }
-    // This blocks to keep the main thread from finishing while the server runs,
-    // but the server never exits. Kill the process to stop it.
-    _ = sem.wait(timeout: DispatchTime.distantFuture)
-    // This suppresses a "variable echoServer was written to, but never read" warning.
-    _ = echoServer
-    // And this ensures that echoServer doesn't get deallocated right after it is created.
-    echoServer = nil
-  }
-
-  $0.command("get", sslFlag, addressOption("localhost"), portOption, messageOption,
-             description: "Perform a unary get().") { ssl, address, port, message in
-    print("calling get")
-    let service = buildEchoService(ssl, address, port, message)
-    var requestMessage = Echo_EchoRequest()
-    requestMessage.text = message
-    print("get sending: " + requestMessage.text)
-    let responseMessage = try service.get(requestMessage)
-    print("get received: " + responseMessage.text)
-  }
-
-  $0.command("expand", sslFlag, addressOption("localhost"), portOption, messageOption,
-             description: "Perform a server-streaming expand().") { ssl, address, port, message in
-    print("calling expand")
-    let service = buildEchoService(ssl, address, port, message)
-    var requestMessage = Echo_EchoRequest()
-    requestMessage.text = message
-    print("expand sending: " + requestMessage.text)
-    let sem = DispatchSemaphore(value: 0)
-    var callResult : CallResult?
-    let expandCall = try service.expand(requestMessage) { result in
-      callResult = result
-      sem.signal()
-    }
-    var running = true
-    while running {
-      do {
-        let responseMessage = try expandCall.receive()
-        print("expand received: \(responseMessage.text)")
-      } catch ClientError.endOfStream {
-        running = false
-      }
-    }
-    _ = sem.wait(timeout: DispatchTime.distantFuture)
-    if let statusCode = callResult?.statusCode {
-      print("expand completed with code \(statusCode)")
-    }
-  }
-
-  $0.command("collect", sslFlag, addressOption("localhost"), portOption, messageOption,
-             description: "Perform a client-streaming collect().") { ssl, address, port, message in
-    print("calling collect")
-    let service = buildEchoService(ssl, address, port, message)
-    let sem = DispatchSemaphore(value: 0)
-    var callResult : CallResult?
-    let collectCall = try service.collect { result in
-      callResult = result
-      sem.signal()
-    }
-
-    let sendCountMutex = Mutex()
-    var sendCount = 0
-
-    let parts = message.components(separatedBy: " ")
-    for part in parts {
-      var requestMessage = Echo_EchoRequest()
-      requestMessage.text = part
-      print("collect sending: " + part)
-      try collectCall.send(requestMessage) {
-        error in
-        sendCountMutex.synchronize {
-          sendCount = sendCount + 1
-        }
-	if let error = error {	
-          print("collect send error \(error)")
-	}
-      }
-    }
-    // don't close until all sends have completed
-    var waiting = true
-    while (waiting) {
-      sendCountMutex.synchronize {
-        if sendCount == parts.count {
-          waiting = false
-        }
-      }
-    }
-    let responseMessage = try collectCall.closeAndReceive()
-    print("collect received: \(responseMessage.text)")
-    _ = sem.wait(timeout: DispatchTime.distantFuture)
-    if let statusCode = callResult?.statusCode {
-      print("collect completed with status \(statusCode)")
-    }
-  }
-
-  $0.command("update", sslFlag, addressOption("localhost"), portOption, messageOption,
-             description: "Perform a bidirectional-streaming update().") { ssl, address, port, message in
-    print("calling update")
-    let service = buildEchoService(ssl, address, port, message)
-    let sem = DispatchSemaphore(value: 0)
-    var callResult : CallResult?
-    let updateCall = try service.update { result in
-      callResult = result
-      sem.signal()
-    }
-
-    let responsesMutex = Mutex()
-    var responses : [String] = []
-
-    DispatchQueue.global().async {
-      var running = true
-      while running {
-        do {
-          let responseMessage = try updateCall.receive()
-          responsesMutex.synchronize {
-            responses.append("update received: \(responseMessage.text)")
-          }
-        } catch ClientError.endOfStream {
-          running = false
-        } catch (let error) {
-          responsesMutex.synchronize {
-            responses.append("update receive error: \(error)")
-          }
-        }
-      }
-    }
-
-    let parts = message.components(separatedBy: " ")
-    for part in parts {
-      var requestMessage = Echo_EchoRequest()
-      requestMessage.text = part
-      print("update sending: " + requestMessage.text)
-      try updateCall.send(requestMessage) {
-        error in
-        if let error = error {
-          print("update send error: \(error)")
-        }
-      }
-    }
-
-    // don't close until last update is received
-    var waiting = true
-    while (waiting) {
-      responsesMutex.synchronize {
-        if responses.count == parts.count {
-          waiting = false
-        }
-      }
-    }
-    try updateCall.closeSend()
-
-    _ = sem.wait(timeout: DispatchTime.distantFuture)
-
-    for response in responses {
-      print(response)
-    }
-    if let statusCode = callResult?.statusCode {
-      print("update completed with status \(statusCode)")
-    }
-  }
-
-}.run()

+ 0 - 17
Examples/Echo2/ssl.crt

@@ -1,17 +0,0 @@
------BEGIN CERTIFICATE-----
-MIICqDCCAZACCQCqiXoqUJivWDANBgkqhkiG9w0BAQUFADAWMRQwEgYDVQQDEwtl
-eGFtcGxlLmNvbTAeFw0xNzA5MDIwMDI5NDVaFw0xODA5MDIwMDI5NDVaMBYxFDAS
-BgNVBAMTC2V4YW1wbGUuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKC
-AQEA1VsheX+pqTrOV23/BZlUselhrguBI1wt0IvY3hcEPddTzjzG33LDCw2DsY5m
-zfITDjar0DaOcqGNdgoMFOOnja47BZgqgZS5hdl5XzC1N7QVZ4KrdYeY6N8eaVI4
-sHreD0oUDcHtLjRY8dSI/UcyeWmJQFNrf/nQVYD1Z57WTJrTbk+L7svRAKK41+Gv
-h3Y5QPl07yBGLyMMTCO4mWeslFekSDnmknniUMq+7U8s7tCTi04U33h6UhBRm328
-RJLXiSbe6D5N2X5mf4MwXyqYKaYQRnloTJfRxWk33O/zhy688/cHxHU/H4YrjN2z
-IowoHMg52KUCuZgr7F48mq6F3QIDAQABMA0GCSqGSIb3DQEBBQUAA4IBAQB6GMt8
-31wrtZtFm9GSDmYKbTUTItzME42H67KnkcLoTiBDOEC1cKSIIlxZsVgTIVgF09Ko
-3HBbJ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