mirror of https://github.com/grpc/grpc.git
commit
7da613e06e
162 changed files with 7571 additions and 2123 deletions
@ -0,0 +1,259 @@ |
||||
// Generated by the protocol buffer compiler. DO NOT EDIT! |
||||
// source: helloworld.proto |
||||
#pragma warning disable 1591, 0612, 3021 |
||||
#region Designer generated code |
||||
|
||||
using pb = global::Google.Protobuf; |
||||
using pbc = global::Google.Protobuf.Collections; |
||||
using pbr = global::Google.Protobuf.Reflection; |
||||
using scg = global::System.Collections.Generic; |
||||
namespace Helloworld { |
||||
|
||||
/// <summary>Holder for reflection information generated from helloworld.proto</summary> |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] |
||||
public static partial class HelloworldReflection { |
||||
|
||||
#region Descriptor |
||||
/// <summary>File descriptor for helloworld.proto</summary> |
||||
public static pbr::FileDescriptor Descriptor { |
||||
get { return descriptor; } |
||||
} |
||||
private static pbr::FileDescriptor descriptor; |
||||
|
||||
static HelloworldReflection() { |
||||
byte[] descriptorData = global::System.Convert.FromBase64String( |
||||
string.Concat( |
||||
"ChBoZWxsb3dvcmxkLnByb3RvEgpoZWxsb3dvcmxkIhwKDEhlbGxvUmVxdWVz", |
||||
"dBIMCgRuYW1lGAEgASgJIh0KCkhlbGxvUmVwbHkSDwoHbWVzc2FnZRgBIAEo", |
||||
"CTJJCgdHcmVldGVyEj4KCFNheUhlbGxvEhguaGVsbG93b3JsZC5IZWxsb1Jl", |
||||
"cXVlc3QaFi5oZWxsb3dvcmxkLkhlbGxvUmVwbHkiAEI2Chtpby5ncnBjLmV4", |
||||
"YW1wbGVzLmhlbGxvd29ybGRCD0hlbGxvV29ybGRQcm90b1ABogIDSExXYgZw", |
||||
"cm90bzM=")); |
||||
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, |
||||
new pbr::FileDescriptor[] { }, |
||||
new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] { |
||||
new pbr::GeneratedClrTypeInfo(typeof(global::Helloworld.HelloRequest), global::Helloworld.HelloRequest.Parser, new[]{ "Name" }, null, null, null), |
||||
new pbr::GeneratedClrTypeInfo(typeof(global::Helloworld.HelloReply), global::Helloworld.HelloReply.Parser, new[]{ "Message" }, null, null, null) |
||||
})); |
||||
} |
||||
#endregion |
||||
|
||||
} |
||||
#region Messages |
||||
/// <summary> |
||||
/// The request message containing the user's name. |
||||
/// </summary> |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] |
||||
public sealed partial class HelloRequest : pb::IMessage<HelloRequest> { |
||||
private static readonly pb::MessageParser<HelloRequest> _parser = new pb::MessageParser<HelloRequest>(() => new HelloRequest()); |
||||
public static pb::MessageParser<HelloRequest> Parser { get { return _parser; } } |
||||
|
||||
public static pbr::MessageDescriptor Descriptor { |
||||
get { return global::Helloworld.HelloworldReflection.Descriptor.MessageTypes[0]; } |
||||
} |
||||
|
||||
pbr::MessageDescriptor pb::IMessage.Descriptor { |
||||
get { return Descriptor; } |
||||
} |
||||
|
||||
public HelloRequest() { |
||||
OnConstruction(); |
||||
} |
||||
|
||||
partial void OnConstruction(); |
||||
|
||||
public HelloRequest(HelloRequest other) : this() { |
||||
name_ = other.name_; |
||||
} |
||||
|
||||
public HelloRequest Clone() { |
||||
return new HelloRequest(this); |
||||
} |
||||
|
||||
/// <summary>Field number for the "name" field.</summary> |
||||
public const int NameFieldNumber = 1; |
||||
private string name_ = ""; |
||||
public string Name { |
||||
get { return name_; } |
||||
set { |
||||
name_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); |
||||
} |
||||
} |
||||
|
||||
public override bool Equals(object other) { |
||||
return Equals(other as HelloRequest); |
||||
} |
||||
|
||||
public bool Equals(HelloRequest other) { |
||||
if (ReferenceEquals(other, null)) { |
||||
return false; |
||||
} |
||||
if (ReferenceEquals(other, this)) { |
||||
return true; |
||||
} |
||||
if (Name != other.Name) return false; |
||||
return true; |
||||
} |
||||
|
||||
public override int GetHashCode() { |
||||
int hash = 1; |
||||
if (Name.Length != 0) hash ^= Name.GetHashCode(); |
||||
return hash; |
||||
} |
||||
|
||||
public override string ToString() { |
||||
return pb::JsonFormatter.ToDiagnosticString(this); |
||||
} |
||||
|
||||
public void WriteTo(pb::CodedOutputStream output) { |
||||
if (Name.Length != 0) { |
||||
output.WriteRawTag(10); |
||||
output.WriteString(Name); |
||||
} |
||||
} |
||||
|
||||
public int CalculateSize() { |
||||
int size = 0; |
||||
if (Name.Length != 0) { |
||||
size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); |
||||
} |
||||
return size; |
||||
} |
||||
|
||||
public void MergeFrom(HelloRequest other) { |
||||
if (other == null) { |
||||
return; |
||||
} |
||||
if (other.Name.Length != 0) { |
||||
Name = other.Name; |
||||
} |
||||
} |
||||
|
||||
public void MergeFrom(pb::CodedInputStream input) { |
||||
uint tag; |
||||
while ((tag = input.ReadTag()) != 0) { |
||||
switch(tag) { |
||||
default: |
||||
input.SkipLastField(); |
||||
break; |
||||
case 10: { |
||||
Name = input.ReadString(); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
/// <summary> |
||||
/// The response message containing the greetings |
||||
/// </summary> |
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] |
||||
public sealed partial class HelloReply : pb::IMessage<HelloReply> { |
||||
private static readonly pb::MessageParser<HelloReply> _parser = new pb::MessageParser<HelloReply>(() => new HelloReply()); |
||||
public static pb::MessageParser<HelloReply> Parser { get { return _parser; } } |
||||
|
||||
public static pbr::MessageDescriptor Descriptor { |
||||
get { return global::Helloworld.HelloworldReflection.Descriptor.MessageTypes[1]; } |
||||
} |
||||
|
||||
pbr::MessageDescriptor pb::IMessage.Descriptor { |
||||
get { return Descriptor; } |
||||
} |
||||
|
||||
public HelloReply() { |
||||
OnConstruction(); |
||||
} |
||||
|
||||
partial void OnConstruction(); |
||||
|
||||
public HelloReply(HelloReply other) : this() { |
||||
message_ = other.message_; |
||||
} |
||||
|
||||
public HelloReply Clone() { |
||||
return new HelloReply(this); |
||||
} |
||||
|
||||
/// <summary>Field number for the "message" field.</summary> |
||||
public const int MessageFieldNumber = 1; |
||||
private string message_ = ""; |
||||
public string Message { |
||||
get { return message_; } |
||||
set { |
||||
message_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); |
||||
} |
||||
} |
||||
|
||||
public override bool Equals(object other) { |
||||
return Equals(other as HelloReply); |
||||
} |
||||
|
||||
public bool Equals(HelloReply other) { |
||||
if (ReferenceEquals(other, null)) { |
||||
return false; |
||||
} |
||||
if (ReferenceEquals(other, this)) { |
||||
return true; |
||||
} |
||||
if (Message != other.Message) return false; |
||||
return true; |
||||
} |
||||
|
||||
public override int GetHashCode() { |
||||
int hash = 1; |
||||
if (Message.Length != 0) hash ^= Message.GetHashCode(); |
||||
return hash; |
||||
} |
||||
|
||||
public override string ToString() { |
||||
return pb::JsonFormatter.ToDiagnosticString(this); |
||||
} |
||||
|
||||
public void WriteTo(pb::CodedOutputStream output) { |
||||
if (Message.Length != 0) { |
||||
output.WriteRawTag(10); |
||||
output.WriteString(Message); |
||||
} |
||||
} |
||||
|
||||
public int CalculateSize() { |
||||
int size = 0; |
||||
if (Message.Length != 0) { |
||||
size += 1 + pb::CodedOutputStream.ComputeStringSize(Message); |
||||
} |
||||
return size; |
||||
} |
||||
|
||||
public void MergeFrom(HelloReply other) { |
||||
if (other == null) { |
||||
return; |
||||
} |
||||
if (other.Message.Length != 0) { |
||||
Message = other.Message; |
||||
} |
||||
} |
||||
|
||||
public void MergeFrom(pb::CodedInputStream input) { |
||||
uint tag; |
||||
while ((tag = input.ReadTag()) != 0) { |
||||
switch(tag) { |
||||
default: |
||||
input.SkipLastField(); |
||||
break; |
||||
case 10: { |
||||
Message = input.ReadString(); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
#endregion |
||||
|
||||
} |
||||
|
||||
#endregion Designer generated code |
@ -0,0 +1,143 @@ |
||||
// Generated by the protocol buffer compiler. DO NOT EDIT! |
||||
// source: helloworld.proto |
||||
// Original file comments: |
||||
// Copyright 2015, Google Inc. |
||||
// All rights reserved. |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without |
||||
// modification, are permitted provided that the following conditions are |
||||
// met: |
||||
// |
||||
// * Redistributions of source code must retain the above copyright |
||||
// notice, this list of conditions and the following disclaimer. |
||||
// * Redistributions in binary form must reproduce the above |
||||
// copyright notice, this list of conditions and the following disclaimer |
||||
// in the documentation and/or other materials provided with the |
||||
// distribution. |
||||
// * Neither the name of Google Inc. nor the names of its |
||||
// contributors may be used to endorse or promote products derived from |
||||
// this software without specific prior written permission. |
||||
// |
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
// |
||||
#region Designer generated code |
||||
|
||||
using System; |
||||
using System.Threading; |
||||
using System.Threading.Tasks; |
||||
using Grpc.Core; |
||||
|
||||
namespace Helloworld { |
||||
/// <summary> |
||||
/// The greeting service definition. |
||||
/// </summary> |
||||
public static class Greeter |
||||
{ |
||||
static readonly string __ServiceName = "helloworld.Greeter"; |
||||
|
||||
static readonly Marshaller<global::Helloworld.HelloRequest> __Marshaller_HelloRequest = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Helloworld.HelloRequest.Parser.ParseFrom); |
||||
static readonly Marshaller<global::Helloworld.HelloReply> __Marshaller_HelloReply = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Helloworld.HelloReply.Parser.ParseFrom); |
||||
|
||||
static readonly Method<global::Helloworld.HelloRequest, global::Helloworld.HelloReply> __Method_SayHello = new Method<global::Helloworld.HelloRequest, global::Helloworld.HelloReply>( |
||||
MethodType.Unary, |
||||
__ServiceName, |
||||
"SayHello", |
||||
__Marshaller_HelloRequest, |
||||
__Marshaller_HelloReply); |
||||
|
||||
/// <summary>Service descriptor</summary> |
||||
public static global::Google.Protobuf.Reflection.ServiceDescriptor Descriptor |
||||
{ |
||||
get { return global::Helloworld.HelloworldReflection.Descriptor.Services[0]; } |
||||
} |
||||
|
||||
/// <summary>Base class for server-side implementations of Greeter</summary> |
||||
public abstract class GreeterBase |
||||
{ |
||||
/// <summary> |
||||
/// Sends a greeting |
||||
/// </summary> |
||||
public virtual global::System.Threading.Tasks.Task<global::Helloworld.HelloReply> SayHello(global::Helloworld.HelloRequest request, ServerCallContext context) |
||||
{ |
||||
throw new RpcException(new Status(StatusCode.Unimplemented, "")); |
||||
} |
||||
|
||||
} |
||||
|
||||
/// <summary>Client for Greeter</summary> |
||||
public class GreeterClient : ClientBase<GreeterClient> |
||||
{ |
||||
/// <summary>Creates a new client for Greeter</summary> |
||||
/// <param name="channel">The channel to use to make remote calls.</param> |
||||
public GreeterClient(Channel channel) : base(channel) |
||||
{ |
||||
} |
||||
/// <summary>Creates a new client for Greeter that uses a custom <c>CallInvoker</c>.</summary> |
||||
/// <param name="callInvoker">The callInvoker to use to make remote calls.</param> |
||||
public GreeterClient(CallInvoker callInvoker) : base(callInvoker) |
||||
{ |
||||
} |
||||
/// <summary>Protected parameterless constructor to allow creation of test doubles.</summary> |
||||
protected GreeterClient() : base() |
||||
{ |
||||
} |
||||
/// <summary>Protected constructor to allow creation of configured clients.</summary> |
||||
/// <param name="configuration">The client configuration.</param> |
||||
protected GreeterClient(ClientBaseConfiguration configuration) : base(configuration) |
||||
{ |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Sends a greeting |
||||
/// </summary> |
||||
public virtual global::Helloworld.HelloReply SayHello(global::Helloworld.HelloRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)) |
||||
{ |
||||
return SayHello(request, new CallOptions(headers, deadline, cancellationToken)); |
||||
} |
||||
/// <summary> |
||||
/// Sends a greeting |
||||
/// </summary> |
||||
public virtual global::Helloworld.HelloReply SayHello(global::Helloworld.HelloRequest request, CallOptions options) |
||||
{ |
||||
return CallInvoker.BlockingUnaryCall(__Method_SayHello, null, options, request); |
||||
} |
||||
/// <summary> |
||||
/// Sends a greeting |
||||
/// </summary> |
||||
public virtual AsyncUnaryCall<global::Helloworld.HelloReply> SayHelloAsync(global::Helloworld.HelloRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken)) |
||||
{ |
||||
return SayHelloAsync(request, new CallOptions(headers, deadline, cancellationToken)); |
||||
} |
||||
/// <summary> |
||||
/// Sends a greeting |
||||
/// </summary> |
||||
public virtual AsyncUnaryCall<global::Helloworld.HelloReply> SayHelloAsync(global::Helloworld.HelloRequest request, CallOptions options) |
||||
{ |
||||
return CallInvoker.AsyncUnaryCall(__Method_SayHello, null, options, request); |
||||
} |
||||
protected override GreeterClient NewInstance(ClientBaseConfiguration configuration) |
||||
{ |
||||
return new GreeterClient(configuration); |
||||
} |
||||
} |
||||
|
||||
/// <summary>Creates service definition that can be registered with a server</summary> |
||||
public static ServerServiceDefinition BindService(GreeterBase serviceImpl) |
||||
{ |
||||
return ServerServiceDefinition.CreateBuilder() |
||||
.AddMethod(__Method_SayHello, serviceImpl.SayHello).Build(); |
||||
} |
||||
|
||||
} |
||||
} |
||||
#endregion |
@ -0,0 +1,22 @@ |
||||
{ |
||||
"title": "Greeter", |
||||
"version": "1.0.0-*", |
||||
"buildOptions": { |
||||
"debugType": "portable", |
||||
}, |
||||
"dependencies": { |
||||
"Google.Protobuf": "3.0.0-beta3", |
||||
"Grpc": "1.0.0-pre1", |
||||
}, |
||||
"frameworks": { |
||||
"net45": { |
||||
"frameworkAssemblies": { |
||||
"System.Runtime": "", |
||||
"System.IO": "" |
||||
}, |
||||
"dependencies": { |
||||
"Microsoft.NETCore.Platforms": "1.0.1" |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,53 @@ |
||||
// Copyright 2015, Google Inc. |
||||
// All rights reserved. |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without |
||||
// modification, are permitted provided that the following conditions are |
||||
// met: |
||||
// |
||||
// * Redistributions of source code must retain the above copyright |
||||
// notice, this list of conditions and the following disclaimer. |
||||
// * Redistributions in binary form must reproduce the above |
||||
// copyright notice, this list of conditions and the following disclaimer |
||||
// in the documentation and/or other materials provided with the |
||||
// distribution. |
||||
// * Neither the name of Google Inc. nor the names of its |
||||
// contributors may be used to endorse or promote products derived from |
||||
// this software without specific prior written permission. |
||||
// |
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
using System; |
||||
using Grpc.Core; |
||||
using Helloworld; |
||||
|
||||
namespace GreeterClient |
||||
{ |
||||
class Program |
||||
{ |
||||
public static void Main(string[] args) |
||||
{ |
||||
Channel channel = new Channel("127.0.0.1:50051", ChannelCredentials.Insecure); |
||||
|
||||
var client = new Greeter.GreeterClient(channel); |
||||
String user = "you"; |
||||
|
||||
var reply = client.SayHello(new HelloRequest { Name = user }); |
||||
Console.WriteLine("Greeting: " + reply.Message); |
||||
|
||||
channel.ShutdownAsync().Wait(); |
||||
Console.WriteLine("Press any key to exit..."); |
||||
Console.ReadKey(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,26 @@ |
||||
{ |
||||
"title": "GreeterClient", |
||||
"version": "1.0.0-*", |
||||
"buildOptions": { |
||||
"debugType": "portable", |
||||
"emitEntryPoint": "true" |
||||
}, |
||||
"dependencies": { |
||||
"Google.Protobuf": "3.0.0-beta3", |
||||
"Grpc": "1.0.0-pre1", |
||||
"Greeter": { |
||||
"target": "project" |
||||
} |
||||
}, |
||||
"frameworks": { |
||||
"net45": { |
||||
"frameworkAssemblies": { |
||||
"System.Runtime": "", |
||||
"System.IO": "" |
||||
}, |
||||
"dependencies": { |
||||
"Microsoft.NETCore.Platforms": "1.0.1" |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,66 @@ |
||||
// Copyright 2015, Google Inc. |
||||
// All rights reserved. |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without |
||||
// modification, are permitted provided that the following conditions are |
||||
// met: |
||||
// |
||||
// * Redistributions of source code must retain the above copyright |
||||
// notice, this list of conditions and the following disclaimer. |
||||
// * Redistributions in binary form must reproduce the above |
||||
// copyright notice, this list of conditions and the following disclaimer |
||||
// in the documentation and/or other materials provided with the |
||||
// distribution. |
||||
// * Neither the name of Google Inc. nor the names of its |
||||
// contributors may be used to endorse or promote products derived from |
||||
// this software without specific prior written permission. |
||||
// |
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
using System; |
||||
using System.Threading.Tasks; |
||||
using Grpc.Core; |
||||
using Helloworld; |
||||
|
||||
namespace GreeterServer |
||||
{ |
||||
class GreeterImpl : Greeter.GreeterBase |
||||
{ |
||||
// Server side handler of the SayHello RPC |
||||
public override Task<HelloReply> SayHello(HelloRequest request, ServerCallContext context) |
||||
{ |
||||
return Task.FromResult(new HelloReply { Message = "Hello " + request.Name }); |
||||
} |
||||
} |
||||
|
||||
class Program |
||||
{ |
||||
const int Port = 50051; |
||||
|
||||
public static void Main(string[] args) |
||||
{ |
||||
Server server = new Server |
||||
{ |
||||
Services = { Greeter.BindService(new GreeterImpl()) }, |
||||
Ports = { new ServerPort("localhost", Port, ServerCredentials.Insecure) } |
||||
}; |
||||
server.Start(); |
||||
|
||||
Console.WriteLine("Greeter server listening on port " + Port); |
||||
Console.WriteLine("Press any key to stop the server..."); |
||||
Console.ReadKey(); |
||||
|
||||
server.ShutdownAsync().Wait(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,26 @@ |
||||
{ |
||||
"title": "GreeterServer", |
||||
"version": "1.0.0-*", |
||||
"buildOptions": { |
||||
"debugType": "portable", |
||||
"emitEntryPoint": "true" |
||||
}, |
||||
"dependencies": { |
||||
"Google.Protobuf": "3.0.0-beta3", |
||||
"Grpc": "1.0.0-pre1", |
||||
"Greeter": { |
||||
"target": "project" |
||||
} |
||||
}, |
||||
"frameworks": { |
||||
"net45": { |
||||
"frameworkAssemblies": { |
||||
"System.Runtime": "", |
||||
"System.IO": "" |
||||
}, |
||||
"dependencies": { |
||||
"Microsoft.NETCore.Platforms": "1.0.1" |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,59 @@ |
||||
gRPC in 3 minutes (C#) |
||||
======================== |
||||
|
||||
BACKGROUND |
||||
------------- |
||||
This is a different version of the helloworld example, using the dotnet sdk |
||||
tools to build and run. |
||||
|
||||
For this sample, we've already generated the server and client stubs from [helloworld.proto][]. |
||||
|
||||
Example projects in this directory depend on the [Grpc](https://www.nuget.org/packages/Grpc/) |
||||
and [Google.Protobuf](https://www.nuget.org/packages/Google.Protobuf/) NuGet packages |
||||
which have been already added to the project for you. |
||||
|
||||
The examples in this directory target .NET 4.5 framework, as .NET Core support is |
||||
currently experimental. |
||||
|
||||
PREREQUISITES |
||||
------------- |
||||
|
||||
- The DotNetCore SDK cli. |
||||
|
||||
- The .NET 4.5 framework. |
||||
|
||||
Both are available to download at https://www.microsoft.com/net/download |
||||
|
||||
BUILD |
||||
------- |
||||
|
||||
From the `examples/csharp/helloworld-from-cli` directory: |
||||
|
||||
- `dotnet restore` |
||||
|
||||
- `dotnet build **/project.json` (this will automatically download NuGet dependencies) |
||||
|
||||
Try it! |
||||
------- |
||||
|
||||
- Run the server |
||||
|
||||
``` |
||||
> cd GreeterServer |
||||
> dotnet run |
||||
``` |
||||
|
||||
- Run the client |
||||
|
||||
``` |
||||
> cd GreeterClient |
||||
> dotnet run |
||||
``` |
||||
|
||||
Tutorial |
||||
-------- |
||||
|
||||
You can find a more detailed tutorial about Grpc in [gRPC Basics: C#][] |
||||
|
||||
[helloworld.proto]:../../protos/helloworld.proto |
||||
[gRPC Basics: C#]:http://www.grpc.io/docs/tutorials/basic/csharp.html |
@ -0,0 +1,219 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPCXX_IMPL_CODEGEN_THRIFT_SERIALIZER_H |
||||
#define GRPCXX_IMPL_CODEGEN_THRIFT_SERIALIZER_H |
||||
|
||||
#include <grpc/impl/codegen/byte_buffer.h> |
||||
#include <grpc/impl/codegen/byte_buffer_reader.h> |
||||
#include <grpc/impl/codegen/slice.h> |
||||
#include <grpc/impl/codegen/slice_buffer.h> |
||||
#include <thrift/protocol/TBinaryProtocol.h> |
||||
#include <thrift/protocol/TCompactProtocol.h> |
||||
#include <thrift/protocol/TProtocolException.h> |
||||
#include <thrift/transport/TBufferTransports.h> |
||||
#include <thrift/transport/TTransportUtils.h> |
||||
#include <boost/make_shared.hpp> |
||||
#include <memory> |
||||
#include <stdexcept> |
||||
#include <string> |
||||
|
||||
namespace apache { |
||||
namespace thrift { |
||||
namespace util { |
||||
|
||||
using apache::thrift::protocol::TBinaryProtocolT; |
||||
using apache::thrift::protocol::TCompactProtocolT; |
||||
using apache::thrift::protocol::TMessageType; |
||||
using apache::thrift::protocol::TNetworkBigEndian; |
||||
using apache::thrift::transport::TMemoryBuffer; |
||||
using apache::thrift::transport::TBufferBase; |
||||
using apache::thrift::transport::TTransport; |
||||
|
||||
template <typename Dummy, typename Protocol> |
||||
class ThriftSerializer { |
||||
public: |
||||
ThriftSerializer() |
||||
: prepared_(false), |
||||
last_deserialized_(false), |
||||
serialize_version_(false) {} |
||||
|
||||
virtual ~ThriftSerializer() {} |
||||
|
||||
// Serialize the passed type into the internal buffer
|
||||
// and returns a pointer to internal buffer and its size
|
||||
template <typename T> |
||||
void Serialize(const T& fields, const uint8_t** serialized_buffer, |
||||
size_t* serialized_len) { |
||||
// prepare or reset buffer
|
||||
if (!prepared_ || last_deserialized_) { |
||||
prepare(); |
||||
} else { |
||||
buffer_->resetBuffer(); |
||||
} |
||||
last_deserialized_ = false; |
||||
|
||||
// if required serialize protocol version
|
||||
if (serialize_version_) { |
||||
protocol_->writeMessageBegin("", TMessageType(0), 0); |
||||
} |
||||
|
||||
// serialize fields into buffer
|
||||
fields.write(protocol_.get()); |
||||
|
||||
// write the end of message
|
||||
if (serialize_version_) { |
||||
protocol_->writeMessageEnd(); |
||||
} |
||||
|
||||
uint8_t* byte_buffer; |
||||
uint32_t byte_buffer_size; |
||||
buffer_->getBuffer(&byte_buffer, &byte_buffer_size); |
||||
*serialized_buffer = byte_buffer; |
||||
*serialized_len = byte_buffer_size; |
||||
} |
||||
|
||||
// Serialize the passed type into the byte buffer
|
||||
template <typename T> |
||||
void Serialize(const T& fields, grpc_byte_buffer** bp) { |
||||
const uint8_t* byte_buffer; |
||||
size_t byte_buffer_size; |
||||
|
||||
Serialize(fields, &byte_buffer, &byte_buffer_size); |
||||
|
||||
gpr_slice slice = gpr_slice_from_copied_buffer( |
||||
reinterpret_cast<const char*>(byte_buffer), byte_buffer_size); |
||||
|
||||
*bp = grpc_raw_byte_buffer_create(&slice, 1); |
||||
|
||||
gpr_slice_unref(slice); |
||||
} |
||||
|
||||
// Deserialize the passed char array into the passed type, returns the number
|
||||
// of bytes that have been consumed from the passed string.
|
||||
template <typename T> |
||||
uint32_t Deserialize(uint8_t* serialized_buffer, size_t length, T* fields) { |
||||
// prepare buffer if necessary
|
||||
if (!prepared_) { |
||||
prepare(); |
||||
} |
||||
last_deserialized_ = true; |
||||
|
||||
// reset buffer transport
|
||||
buffer_->resetBuffer(serialized_buffer, length); |
||||
|
||||
// read the protocol version if necessary
|
||||
if (serialize_version_) { |
||||
std::string name = ""; |
||||
TMessageType mt = static_cast<TMessageType>(0); |
||||
int32_t seq_id = 0; |
||||
protocol_->readMessageBegin(name, mt, seq_id); |
||||
} |
||||
|
||||
// deserialize buffer into fields
|
||||
uint32_t len = fields->read(protocol_.get()); |
||||
|
||||
// read the end of message
|
||||
if (serialize_version_) { |
||||
protocol_->readMessageEnd(); |
||||
} |
||||
|
||||
return len; |
||||
} |
||||
|
||||
// Deserialize the passed byte buffer to passed type, returns the number
|
||||
// of bytes consumed from byte buffer
|
||||
template <typename T> |
||||
uint32_t Deserialize(grpc_byte_buffer* buffer, T* msg) { |
||||
grpc_byte_buffer_reader reader; |
||||
grpc_byte_buffer_reader_init(&reader, buffer); |
||||
|
||||
gpr_slice slice = grpc_byte_buffer_reader_readall(&reader); |
||||
|
||||
uint32_t len = |
||||
Deserialize(GPR_SLICE_START_PTR(slice), GPR_SLICE_LENGTH(slice), msg); |
||||
|
||||
gpr_slice_unref(slice); |
||||
|
||||
grpc_byte_buffer_reader_destroy(&reader); |
||||
|
||||
return len; |
||||
} |
||||
|
||||
// set serialization version flag
|
||||
void SetSerializeVersion(bool value) { serialize_version_ = value; } |
||||
|
||||
// Set the container size limit to deserialize
|
||||
// This function should be called after buffer_ is initialized
|
||||
void SetContainerSizeLimit(int32_t container_limit) { |
||||
if (!prepared_) { |
||||
prepare(); |
||||
} |
||||
protocol_->setContainerSizeLimit(container_limit); |
||||
} |
||||
|
||||
// Set the string size limit to deserialize
|
||||
// This function should be called after buffer_ is initialized
|
||||
void SetStringSizeLimit(int32_t string_limit) { |
||||
if (!prepared_) { |
||||
prepare(); |
||||
} |
||||
protocol_->setStringSizeLimit(string_limit); |
||||
} |
||||
|
||||
private: |
||||
bool prepared_; |
||||
bool last_deserialized_; |
||||
boost::shared_ptr<TMemoryBuffer> buffer_; |
||||
std::shared_ptr<Protocol> protocol_; |
||||
bool serialize_version_; |
||||
|
||||
void prepare() { |
||||
buffer_ = boost::make_shared<TMemoryBuffer>(); |
||||
// create a protocol for the memory buffer transport
|
||||
protocol_ = std::make_shared<Protocol>(buffer_); |
||||
prepared_ = true; |
||||
} |
||||
|
||||
}; // ThriftSerializer
|
||||
|
||||
typedef ThriftSerializer<void, TBinaryProtocolT<TBufferBase, TNetworkBigEndian>> |
||||
ThriftSerializerBinary; |
||||
typedef ThriftSerializer<void, TCompactProtocolT<TBufferBase>> |
||||
ThriftSerializerCompact; |
||||
|
||||
} // namespace util
|
||||
} // namespace thrift
|
||||
} // namespace apache
|
||||
|
||||
#endif |
@ -0,0 +1,85 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPCXX_IMPL_CODEGEN_THRIFT_UTILS_H |
||||
#define GRPCXX_IMPL_CODEGEN_THRIFT_UTILS_H |
||||
|
||||
#include <grpc++/impl/codegen/config.h> |
||||
#include <grpc++/impl/codegen/core_codegen_interface.h> |
||||
#include <grpc++/impl/codegen/serialization_traits.h> |
||||
#include <grpc++/impl/codegen/status.h> |
||||
#include <grpc++/impl/codegen/status_code_enum.h> |
||||
#include <grpc++/impl/codegen/thrift_serializer.h> |
||||
#include <grpc/impl/codegen/byte_buffer.h> |
||||
#include <grpc/impl/codegen/byte_buffer_reader.h> |
||||
#include <grpc/impl/codegen/slice.h> |
||||
#include <grpc/impl/codegen/slice_buffer.h> |
||||
#include <cstdint> |
||||
#include <cstdlib> |
||||
|
||||
namespace grpc { |
||||
|
||||
using apache::thrift::util::ThriftSerializerCompact; |
||||
|
||||
template <class T> |
||||
class SerializationTraits<T, typename std::enable_if<std::is_base_of< |
||||
apache::thrift::TBase, T>::value>::type> { |
||||
public: |
||||
static Status Serialize(const T& msg, grpc_byte_buffer** bp, |
||||
bool* own_buffer) { |
||||
*own_buffer = true; |
||||
|
||||
ThriftSerializerCompact serializer; |
||||
serializer.Serialize(msg, bp); |
||||
|
||||
return Status(StatusCode::OK, "ok"); |
||||
} |
||||
|
||||
static Status Deserialize(grpc_byte_buffer* buffer, T* msg, |
||||
int max_message_size) { |
||||
if (!buffer) { |
||||
return Status(StatusCode::INTERNAL, "No payload"); |
||||
} |
||||
|
||||
ThriftSerializerCompact deserializer; |
||||
deserializer.Deserialize(buffer, msg); |
||||
|
||||
grpc_byte_buffer_destroy(buffer); |
||||
|
||||
return Status(StatusCode::OK, "ok"); |
||||
} |
||||
}; |
||||
|
||||
} // namespace grpc
|
||||
|
||||
#endif // GRPCXX_IMPL_CODEGEN_THRIFT_UTILS_H
|
File diff suppressed because it is too large
Load Diff
@ -1,394 +0,0 @@ |
||||
/* |
||||
* |
||||
* Copyright 2015, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
/* |
||||
* This test file is derived from fixture h2_ssl.c in core end2end test |
||||
* (test/core/end2end/fixture/h2_ssl.c). The structure of the fixture is |
||||
* preserved as much as possible |
||||
* |
||||
* This fixture creates a server full stack using chttp2 and a client |
||||
* full stack using Cronet. End-to-end tests are run against this |
||||
* configuration |
||||
* |
||||
*/ |
||||
|
||||
|
||||
#import <XCTest/XCTest.h> |
||||
#include "test/core/end2end/end2end_tests.h" |
||||
|
||||
#include <stdio.h> |
||||
#include <string.h> |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/host_port.h> |
||||
#include <grpc/support/log.h> |
||||
|
||||
#include "src/core/lib/channel/channel_args.h" |
||||
#include "src/core/lib/security/credentials/credentials.h" |
||||
#include "src/core/lib/support/env.h" |
||||
#include "src/core/lib/support/string.h" |
||||
#include "src/core/lib/support/tmpfile.h" |
||||
#include "test/core/end2end/data/ssl_test_data.h" |
||||
#include "test/core/util/port.h" |
||||
#include "test/core/util/test_config.h" |
||||
|
||||
#include <grpc/grpc_cronet.h> |
||||
#import <Cronet/Cronet.h> |
||||
|
||||
typedef struct fullstack_secure_fixture_data { |
||||
char *localaddr; |
||||
} fullstack_secure_fixture_data; |
||||
|
||||
static grpc_end2end_test_fixture chttp2_create_fixture_secure_fullstack( |
||||
grpc_channel_args *client_args, grpc_channel_args *server_args) { |
||||
grpc_end2end_test_fixture f; |
||||
int port = grpc_pick_unused_port_or_die(); |
||||
fullstack_secure_fixture_data *ffd = |
||||
gpr_malloc(sizeof(fullstack_secure_fixture_data)); |
||||
memset(&f, 0, sizeof(f)); |
||||
|
||||
gpr_join_host_port(&ffd->localaddr, "localhost", port); |
||||
|
||||
f.fixture_data = ffd; |
||||
f.cq = grpc_completion_queue_create(NULL); |
||||
|
||||
return f; |
||||
} |
||||
|
||||
static void process_auth_failure(void *state, grpc_auth_context *ctx, |
||||
const grpc_metadata *md, size_t md_count, |
||||
grpc_process_auth_metadata_done_cb cb, |
||||
void *user_data) { |
||||
GPR_ASSERT(state == NULL); |
||||
cb(user_data, NULL, 0, NULL, 0, GRPC_STATUS_UNAUTHENTICATED, NULL); |
||||
} |
||||
|
||||
static void cronet_init_client_secure_fullstack( |
||||
grpc_end2end_test_fixture *f, grpc_channel_args *client_args, |
||||
cronet_engine *cronetEngine) { |
||||
fullstack_secure_fixture_data *ffd = f->fixture_data; |
||||
f->client = |
||||
grpc_cronet_secure_channel_create(cronetEngine, ffd->localaddr, client_args, NULL); |
||||
GPR_ASSERT(f->client != NULL); |
||||
} |
||||
|
||||
static void chttp2_init_server_secure_fullstack( |
||||
grpc_end2end_test_fixture *f, grpc_channel_args *server_args, |
||||
grpc_server_credentials *server_creds) { |
||||
fullstack_secure_fixture_data *ffd = f->fixture_data; |
||||
if (f->server) { |
||||
grpc_server_destroy(f->server); |
||||
} |
||||
f->server = grpc_server_create(server_args, NULL); |
||||
grpc_server_register_completion_queue(f->server, f->cq, NULL); |
||||
GPR_ASSERT(grpc_server_add_secure_http2_port(f->server, ffd->localaddr, |
||||
server_creds)); |
||||
grpc_server_credentials_release(server_creds); |
||||
grpc_server_start(f->server); |
||||
} |
||||
|
||||
static void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture *f) { |
||||
fullstack_secure_fixture_data *ffd = f->fixture_data; |
||||
gpr_free(ffd->localaddr); |
||||
gpr_free(ffd); |
||||
} |
||||
|
||||
static void cronet_init_client_simple_ssl_secure_fullstack( |
||||
grpc_end2end_test_fixture *f, grpc_channel_args *client_args) { |
||||
grpc_arg ssl_name_override = {GRPC_ARG_STRING, |
||||
GRPC_SSL_TARGET_NAME_OVERRIDE_ARG, |
||||
{"foo.test.google.fr"}}; |
||||
|
||||
grpc_channel_args *new_client_args = |
||||
grpc_channel_args_copy_and_add(client_args, &ssl_name_override, 1); |
||||
[Cronet setHttp2Enabled:YES]; |
||||
[Cronet start]; |
||||
cronet_engine *cronetEngine = [Cronet getGlobalEngine]; |
||||
|
||||
cronet_init_client_secure_fullstack(f, new_client_args, cronetEngine); |
||||
grpc_channel_args_destroy(new_client_args); |
||||
} |
||||
|
||||
static int fail_server_auth_check(grpc_channel_args *server_args) { |
||||
size_t i; |
||||
if (server_args == NULL) return 0; |
||||
for (i = 0; i < server_args->num_args; i++) { |
||||
if (strcmp(server_args->args[i].key, FAIL_AUTH_CHECK_SERVER_ARG_NAME) == |
||||
0) { |
||||
return 1; |
||||
} |
||||
} |
||||
return 0; |
||||
} |
||||
|
||||
static void chttp2_init_server_simple_ssl_secure_fullstack( |
||||
grpc_end2end_test_fixture *f, grpc_channel_args *server_args) { |
||||
grpc_ssl_pem_key_cert_pair pem_cert_key_pair = {test_server1_key, |
||||
test_server1_cert}; |
||||
grpc_server_credentials *ssl_creds = |
||||
grpc_ssl_server_credentials_create(NULL, &pem_cert_key_pair, 1, 0, NULL); |
||||
if (fail_server_auth_check(server_args)) { |
||||
grpc_auth_metadata_processor processor = {process_auth_failure, NULL, NULL}; |
||||
grpc_server_credentials_set_auth_metadata_processor(ssl_creds, processor); |
||||
} |
||||
chttp2_init_server_secure_fullstack(f, server_args, ssl_creds); |
||||
} |
||||
|
||||
/* All test configurations */ |
||||
|
||||
static grpc_end2end_test_config configs[] = { |
||||
{"chttp2/simple_ssl_fullstack", |
||||
FEATURE_MASK_SUPPORTS_DELAYED_CONNECTION | |
||||
FEATURE_MASK_SUPPORTS_PER_CALL_CREDENTIALS, |
||||
chttp2_create_fixture_secure_fullstack, |
||||
cronet_init_client_simple_ssl_secure_fullstack, |
||||
chttp2_init_server_simple_ssl_secure_fullstack, |
||||
chttp2_tear_down_secure_fullstack}, |
||||
}; |
||||
|
||||
|
||||
|
||||
static char *roots_filename; |
||||
|
||||
@interface CoreCronetEnd2EndTests : XCTestCase |
||||
|
||||
@end |
||||
|
||||
@implementation CoreCronetEnd2EndTests |
||||
|
||||
|
||||
// The setUp() function is run before the test cases run and only run once |
||||
+ (void)setUp { |
||||
[super setUp]; |
||||
|
||||
FILE *roots_file; |
||||
size_t roots_size = strlen(test_root_cert); |
||||
|
||||
char *argv[] = {"CoreCronetEnd2EndTests"}; |
||||
grpc_test_init(1, argv); |
||||
grpc_end2end_tests_pre_init(); |
||||
|
||||
/* Set the SSL roots env var. */ |
||||
roots_file = gpr_tmpfile("chttp2_simple_ssl_fullstack_test", &roots_filename); |
||||
GPR_ASSERT(roots_filename != NULL); |
||||
GPR_ASSERT(roots_file != NULL); |
||||
GPR_ASSERT(fwrite(test_root_cert, 1, roots_size, roots_file) == roots_size); |
||||
fclose(roots_file); |
||||
gpr_setenv(GRPC_DEFAULT_SSL_ROOTS_FILE_PATH_ENV_VAR, roots_filename); |
||||
|
||||
grpc_init(); |
||||
|
||||
} |
||||
|
||||
// The tearDown() function is run after all test cases finish running |
||||
+ (void)tearDown { |
||||
grpc_shutdown(); |
||||
|
||||
/* Cleanup. */ |
||||
remove(roots_filename); |
||||
gpr_free(roots_filename); |
||||
|
||||
[super tearDown]; |
||||
} |
||||
|
||||
- (void)testIndividualCase:(char*)test_case { |
||||
char *argv[] = {"h2_ssl", test_case}; |
||||
|
||||
for (int i = 0; i < sizeof(configs) / sizeof(*configs); i++) { |
||||
grpc_end2end_tests(sizeof(argv) / sizeof(argv[0]), argv, configs[i]); |
||||
} |
||||
} |
||||
|
||||
// TODO(mxyan): Use NSStringFromSelector(_cmd) to acquire test name from the |
||||
// test case method name, so that bodies of test cases can stay identical |
||||
- (void)testBadHostname { |
||||
[self testIndividualCase:"bad_hostname"]; |
||||
} |
||||
|
||||
- (void)testBinaryMetadata { |
||||
[self testIndividualCase:"binary_metadata"]; |
||||
} |
||||
|
||||
- (void)testCallCreds { |
||||
[self testIndividualCase:"call_creds"]; |
||||
} |
||||
|
||||
- (void)testCancelAfterAccept { |
||||
[self testIndividualCase:"cancel_after_accept"]; |
||||
} |
||||
|
||||
- (void)testCancelAfterClientDone { |
||||
[self testIndividualCase:"cancel_after_client_done"]; |
||||
} |
||||
|
||||
- (void)testCancelAfterInvoke { |
||||
[self testIndividualCase:"cancel_after_invoke"]; |
||||
} |
||||
|
||||
- (void)testCancelBeforeInvoke { |
||||
[self testIndividualCase:"cancel_before_invoke"]; |
||||
} |
||||
|
||||
- (void)testCancelInAVacuum { |
||||
[self testIndividualCase:"cancel_in_a_vacuum"]; |
||||
} |
||||
|
||||
- (void)testCancelWithStatus { |
||||
[self testIndividualCase:"cancel_with_status"]; |
||||
} |
||||
|
||||
- (void)testCompressedPayload { |
||||
[self testIndividualCase:"compressed_payload"]; |
||||
} |
||||
|
||||
- (void)testConnectivity { |
||||
[self testIndividualCase:"connectivity"]; |
||||
} |
||||
|
||||
- (void)testDefaultHost { |
||||
[self testIndividualCase:"default_host"]; |
||||
} |
||||
|
||||
- (void)testDisappearingServer { |
||||
[self testIndividualCase:"disappearing_server"]; |
||||
} |
||||
|
||||
- (void)testEmptyBatch { |
||||
[self testIndividualCase:"empty_batch"]; |
||||
} |
||||
|
||||
- (void)testFilterCausesClose { |
||||
[self testIndividualCase:"filter_causes_close"]; |
||||
} |
||||
|
||||
- (void)testGracefulServerShutdown { |
||||
[self testIndividualCase:"graceful_server_shutdown"]; |
||||
} |
||||
|
||||
- (void)testHighInitialSeqno { |
||||
[self testIndividualCase:"high_initial_seqno"]; |
||||
} |
||||
|
||||
- (void)testHpackSize { |
||||
[self testIndividualCase:"hpack_size"]; |
||||
} |
||||
|
||||
- (void)testIdempotentRequest { |
||||
[self testIndividualCase:"idempotent_request"]; |
||||
} |
||||
|
||||
- (void)testInvokeLargeRequest { |
||||
[self testIndividualCase:"invoke_large_request"]; |
||||
} |
||||
|
||||
- (void)testLargeMetadata { |
||||
[self testIndividualCase:"large_metadata"]; |
||||
} |
||||
|
||||
- (void)testMaxConcurrentStreams { |
||||
[self testIndividualCase:"max_concurrent_streams"]; |
||||
} |
||||
|
||||
- (void)testMaxMessageLength { |
||||
[self testIndividualCase:"max_message_length"]; |
||||
} |
||||
|
||||
- (void)testNegativeDeadline { |
||||
[self testIndividualCase:"negative_deadline"]; |
||||
} |
||||
|
||||
- (void)testNetworkStatusChange { |
||||
[self testIndividualCase:"network_status_change"]; |
||||
} |
||||
|
||||
- (void)testNoOp { |
||||
[self testIndividualCase:"no_op"]; |
||||
} |
||||
|
||||
- (void)testPayload { |
||||
[self testIndividualCase:"payload"]; |
||||
} |
||||
|
||||
- (void)testPing { |
||||
[self testIndividualCase:"ping"]; |
||||
} |
||||
|
||||
- (void)testPingPongStreaming { |
||||
[self testIndividualCase:"ping_pong_streaming"]; |
||||
} |
||||
|
||||
- (void)testRegisteredCall { |
||||
[self testIndividualCase:"registered_call"]; |
||||
} |
||||
|
||||
- (void)testRequestWithFlags { |
||||
[self testIndividualCase:"request_with_flags"]; |
||||
} |
||||
|
||||
- (void)testRequestWithPayload { |
||||
[self testIndividualCase:"request_with_payload"]; |
||||
} |
||||
|
||||
- (void)testServerFinishesRequest { |
||||
[self testIndividualCase:"server_finishes_request"]; |
||||
} |
||||
|
||||
- (void)testShutdownFinishesCalls { |
||||
[self testIndividualCase:"shutdown_finishes_calls"]; |
||||
} |
||||
|
||||
- (void)testShutdownFinishesTags { |
||||
[self testIndividualCase:"shutdown_finishes_tags"]; |
||||
} |
||||
|
||||
- (void)testSimpleDelayedRequest { |
||||
[self testIndividualCase:"simple_delayed_request"]; |
||||
} |
||||
|
||||
- (void)testSimpleMetadata { |
||||
[self testIndividualCase:"simple_metadata"]; |
||||
} |
||||
|
||||
- (void)testSimpleRequest { |
||||
[self testIndividualCase:"simple_request"]; |
||||
} |
||||
|
||||
- (void)testStreamingErrorResponse { |
||||
[self testIndividualCase:"streaming_error_response"]; |
||||
} |
||||
|
||||
- (void)testTrailingMetadata { |
||||
[self testIndividualCase:"trailing_metadata"]; |
||||
} |
||||
|
||||
@end |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue