Merge remote-tracking branch 'upstream/master' into cares

pull/7759/head
Yuchen Zeng 8 years ago
commit e61bf3b406
  1. 2
      .gitmodules
  2. 31
      examples/cpp/README.md
  3. 337
      examples/cpp/cpptutorial.md
  4. 2
      examples/cpp/helloworld/Makefile
  5. 2
      examples/cpp/route_guide/Makefile
  6. 4
      examples/csharp/helloworld/.nuget/packages.config
  7. 5
      examples/csharp/helloworld/Greeter.sln
  8. 1
      examples/csharp/helloworld/Greeter/packages.config
  9. 4
      examples/csharp/route_guide/.nuget/packages.config
  10. 5
      examples/csharp/route_guide/RouteGuide.sln
  11. 8
      examples/csharp/route_guide/RouteGuide/RouteGuide.csproj
  12. 8
      examples/csharp/route_guide/RouteGuideServer/RouteGuideServer.csproj
  13. 1
      examples/csharp/route_guide/RouteGuideServer/packages.config
  14. 2
      examples/objective-c/auth_sample/AuthTestService.podspec
  15. 2
      examples/objective-c/helloworld/HelloWorld.podspec
  16. 2
      examples/objective-c/route_guide/RouteGuide.podspec
  17. 2
      examples/python/route_guide/route_guide_server.py
  18. 8
      gRPC-ProtoRPC.podspec
  19. 6
      gRPC-RxLibrary.podspec
  20. 6
      gRPC.podspec
  21. 64
      include/grpc++/ext/reflection.pb.h
  22. 4
      requirements.txt
  23. 2
      setup.py
  24. 15
      src/compiler/node_generator.cc
  25. 19
      src/core/ext/transport/chttp2/client/insecure/channel_create.c
  26. 2
      src/core/ext/transport/chttp2/client/insecure/channel_create_posix.c
  27. 13
      src/core/ext/transport/chttp2/client/secure/secure_channel_create.c
  28. 6
      src/core/ext/transport/chttp2/server/insecure/server_chttp2.c
  29. 2
      src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c
  30. 12
      src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c
  31. 7
      src/core/ext/transport/chttp2/transport/chttp2_transport.c
  32. 4
      src/core/ext/transport/chttp2/transport/chttp2_transport.h
  33. 24
      src/core/lib/channel/handshaker.c
  34. 9
      src/core/lib/channel/handshaker.h
  35. 8
      src/core/lib/http/httpcli_security_connector.c
  36. 9
      src/core/lib/security/transport/handshake.c
  37. 7
      src/core/lib/security/transport/handshake.h
  38. 59
      src/core/lib/security/transport/security_connector.c
  39. 13
      src/core/lib/security/transport/security_connector.h
  40. 1
      src/core/lib/support/log_linux.c
  41. 137
      src/cpp/ext/reflection.pb.cc
  42. 4
      src/csharp/Grpc.Core.Tests/Grpc.Core.Tests.csproj
  43. 2
      src/csharp/Grpc.Core.Tests/packages.config
  44. 4
      src/csharp/Grpc.Core/Grpc.Core.csproj
  45. 2
      src/csharp/Grpc.Core/Grpc.Core.nuspec
  46. 2
      src/csharp/Grpc.Core/packages.config
  47. 2
      src/csharp/Grpc.Core/project.json
  48. 5
      src/csharp/Grpc.Examples.MathClient/project.json
  49. 5
      src/csharp/Grpc.Examples.MathServer/project.json
  50. 4
      src/csharp/Grpc.Examples.Tests/Grpc.Examples.Tests.csproj
  51. 2
      src/csharp/Grpc.Examples.Tests/packages.config
  52. 4
      src/csharp/Grpc.Examples/Grpc.Examples.csproj
  53. 2
      src/csharp/Grpc.Examples/packages.config
  54. 5
      src/csharp/Grpc.Examples/project.json
  55. 4
      src/csharp/Grpc.HealthCheck/Grpc.HealthCheck.csproj
  56. 2
      src/csharp/Grpc.HealthCheck/Grpc.HealthCheck.nuspec
  57. 2
      src/csharp/Grpc.HealthCheck/packages.config
  58. 5
      src/csharp/Grpc.IntegrationTesting.QpsWorker/project.json
  59. 5
      src/csharp/Grpc.IntegrationTesting.StressClient/project.json
  60. 4
      src/csharp/Grpc.IntegrationTesting/Grpc.IntegrationTesting.csproj
  61. 2
      src/csharp/Grpc.IntegrationTesting/packages.config
  62. 4
      src/node/src/credentials.js
  63. 5
      src/node/test/credentials_test.js
  64. 4
      src/objective-c/!ProtoCompiler-gRPCPlugin.podspec
  65. 10
      src/objective-c/!ProtoCompiler.podspec
  66. 2
      src/objective-c/README.md
  67. 2
      src/objective-c/examples/RemoteTestClient/RemoteTest.podspec
  68. 2
      src/objective-c/examples/SwiftSample/ViewController.swift
  69. 2
      src/objective-c/tests/RemoteTestClient/RemoteTest.podspec
  70. 2
      src/python/grpcio/grpc/_cython/_cygrpc/call.pyx.pxi
  71. 2
      src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi
  72. 2
      src/python/grpcio/grpc/_cython/_cygrpc/completion_queue.pyx.pxi
  73. 14
      src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi
  74. 12
      src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi
  75. 2
      src/python/grpcio/grpc/_cython/_cygrpc/server.pyx.pxi
  76. 4
      src/python/grpcio/grpc/_cython/cygrpc.pyx
  77. 1
      src/python/grpcio_health_checking/setup.py
  78. 2
      src/python/grpcio_tests/setup.py
  79. 4
      src/python/grpcio_tests/tests/unit/_cython/cygrpc_test.py
  80. 68
      src/ruby/lib/grpc/generic/active_call.rb
  81. 15
      src/ruby/lib/grpc/generic/bidi_call.rb
  82. 9
      src/ruby/lib/grpc/generic/rpc_desc.rb
  83. 23
      src/ruby/lib/grpc/generic/rpc_server.rb
  84. 278
      src/ruby/spec/generic/active_call_spec.rb
  85. 14
      src/ruby/spec/generic/rpc_desc_spec.rb
  86. 2
      templates/src/csharp/Grpc.Core/project.json.template
  87. 2
      templates/src/csharp/Grpc.Examples.MathClient/project.json.template
  88. 2
      templates/src/csharp/Grpc.Examples.MathServer/project.json.template
  89. 2
      templates/src/csharp/Grpc.IntegrationTesting.QpsWorker/project.json.template
  90. 2
      templates/src/csharp/Grpc.IntegrationTesting.StressClient/project.json.template
  91. 4
      templates/src/csharp/build_options.include
  92. 2
      templates/tools/dockerfile/csharp_deps.include
  93. 2
      test/core/bad_client/bad_client.c
  94. 52
      test/core/census/resource_test.c
  95. 4
      test/core/end2end/fixtures/h2_sockpair+trace.c
  96. 4
      test/core/end2end/fixtures/h2_sockpair.c
  97. 4
      test/core/end2end/fixtures/h2_sockpair_1byte.c
  98. 2
      test/core/end2end/fuzzers/api_fuzzer.c
  99. 2
      test/core/end2end/fuzzers/client_fuzzer.c
  100. 2
      test/core/end2end/fuzzers/server_fuzzer.c
  101. Some files were not shown because too many files have changed in this diff Show More

2
.gitmodules vendored

@ -4,7 +4,7 @@
[submodule "third_party/protobuf"]
path = third_party/protobuf
url = https://github.com/google/protobuf.git
branch = 3.0.0-beta-3
branch = 3.0.0-GA
[submodule "third_party/gflags"]
path = third_party/gflags
url = https://github.com/gflags/gflags.git

@ -2,26 +2,14 @@
## Installation
To install gRPC on your system, follow the instructions to build from source [here](../../INSTALL.md). This also installs the protocol buffer compiler `protoc` (if you don't have it already), and the C++ gRPC plugin for `protoc`.
To install gRPC on your system, follow the instructions to build from source
[here](../../INSTALL.md). This also installs the protocol buffer compiler
`protoc` (if you don't have it already), and the C++ gRPC plugin for `protoc`.
## Hello C++ gRPC!
Here's how to build and run the C++ implementation of the [Hello World](../protos/helloworld.proto) example used in [Getting started](..).
The example code for this and our other examples lives in the `examples`
directory. Clone this repository to your local machine by running the
following command:
```sh
$ git clone -b $(curl -L http://grpc.io/release) https://github.com/grpc/grpc
```
Change your current directory to examples/cpp/helloworld
```sh
$ cd examples/cpp/helloworld/
```
Here's how to build and run the C++ implementation of the [Hello
World](../protos/helloworld.proto) example used in [Getting started](..).
### Client and server implementations
@ -31,18 +19,25 @@ The server implementation is at [greeter_server.cc](helloworld/greeter_server.cc
### Try it!
Build client and server:
```sh
$ make
```
Run the server, which will listen on port 50051:
```sh
$ ./greeter_server
```
Run the client (in a different terminal):
```sh
$ ./greeter_client
```
If things go smoothly, you will see the "Greeter received: Hello world" in the client side output.
If things go smoothly, you will see the "Greeter received: Hello world" in the
client side output.
## Tutorial

@ -1,58 +1,77 @@
#gRPC Basics: C++
This tutorial provides a basic C++ programmer's introduction to working with gRPC. By walking through this example you'll learn how to:
This tutorial provides a basic C++ programmer's introduction to working with
gRPC. By walking through this example you'll learn how to:
- Define a service in a .proto file.
- Define a service in a `.proto` file.
- Generate server and client code using the protocol buffer compiler.
- Use the C++ gRPC API to write a simple client and server for your service.
It assumes that you have read the [Getting started](..) guide and are familiar with [protocol buffers] (https://developers.google.com/protocol-buffers/docs/overview). Note that the example in this tutorial uses the proto3 version of the protocol buffers language, which is currently in alpha release: you can find out more in the [proto3 language guide](https://developers.google.com/protocol-buffers/docs/proto3) and see the [release notes](https://github.com/google/protobuf/releases) for the new version in the protocol buffers Github repository.
This isn't a comprehensive guide to using gRPC in C++: more reference documentation is coming soon.
It assumes that you are familiar with
[protocol buffers](https://developers.google.com/protocol-buffers/docs/overview).
Note that the example in this tutorial uses the proto3 version of the protocol
buffers language, which is currently in alpha release: you can find out more in
the [proto3 language guide](https://developers.google.com/protocol-buffers/docs/proto3)
and see the [release notes](https://github.com/google/protobuf/releases) for the
new version in the protocol buffers Github repository.
## Why use gRPC?
Our example is a simple route mapping application that lets clients get information about features on their route, create a summary of their route, and exchange route information such as traffic updates with the server and other clients.
Our example is a simple route mapping application that lets clients get
information about features on their route, create a summary of their route, and
exchange route information such as traffic updates with the server and other
clients.
With gRPC we can define our service once in a .proto file and implement clients and servers in any of gRPC's supported languages, which in turn can be run in environments ranging from servers inside Google to your own tablet - all the complexity of communication between different languages and environments is handled for you by gRPC. We also get all the advantages of working with protocol buffers, including efficient serialization, a simple IDL, and easy interface updating.
With gRPC we can define our service once in a `.proto` file and implement clients
and servers in any of gRPC's supported languages, which in turn can be run in
environments ranging from servers inside Google to your own tablet - all the
complexity of communication between different languages and environments is
handled for you by gRPC. We also get all the advantages of working with protocol
buffers, including efficient serialization, a simple IDL, and easy interface
updating.
## Example code and setup
The example code for our tutorial is in [examples/cpp/route_guide](route_guide). To download the example, clone this repository by running the following command:
```shell
$ git clone -b $(curl -L http://grpc.io/release) https://github.com/grpc/grpc
```
Then change your current directory to `examples/cpp/route_guide`:
```shell
$ cd examples/cpp/route_guide
```
You also should have the relevant tools installed to generate the server and client interface code - if you don't already, follow the setup instructions in [gRPC in 3 minutes](README.md).
The example code for our tutorial is in [examples/cpp/route_guide](route_guide).
You also should have the relevant tools installed to generate the server and
client interface code - if you don't already, follow the setup instructions in
[INSTALL.md](../../INSTALL.md).
## Defining the service
Our first step (as you'll know from [Getting started](..) is to define the gRPC *service* and the method *request* and *response* types using [protocol buffers] (https://developers.google.com/protocol-buffers/docs/overview). You can see the complete .proto file in [`examples/protos/route_guide.proto`](../protos/route_guide.proto).
Our first step is to define the gRPC *service* and the method *request* and
*response* types using
[protocol buffers](https://developers.google.com/protocol-buffers/docs/overview).
You can see the complete `.proto` file in
[`examples/protos/route_guide.proto`](../protos/route_guide.proto).
To define a service, you specify a named `service` in your .proto file:
To define a service, you specify a named `service` in your `.proto` file:
```
```protobuf
service RouteGuide {
...
}
```
Then you define `rpc` methods inside your service definition, specifying their request and response types. gRPC lets you define four kinds of service method, all of which are used in the `RouteGuide` service:
Then you define `rpc` methods inside your service definition, specifying their
request and response types. gRPC lets you define four kinds of service method,
all of which are used in the `RouteGuide` service:
- A *simple RPC* where the client sends a request to the server using the stub and waits for a response to come back, just like a normal function call.
```
- A *simple RPC* where the client sends a request to the server using the stub
and waits for a response to come back, just like a normal function call.
```protobuf
// Obtains the feature at a given position.
rpc GetFeature(Point) returns (Feature) {}
```
- A *server-side streaming RPC* where the client sends a request to the server and gets a stream to read a sequence of messages back. The client reads from the returned stream until there are no more messages. As you can see in our example, you specify a server-side streaming method by placing the `stream` keyword before the *response* type.
```
- A *server-side streaming RPC* where the client sends a request to the server
and gets a stream to read a sequence of messages back. The client reads from
the returned stream until there are no more messages. As you can see in our
example, you specify a server-side streaming method by placing the `stream`
keyword before the *response* type.
```protobuf
// Obtains the Features available within the given Rectangle. Results are
// streamed rather than returned at once (e.g. in a response message with a
// repeated field), as the rectangle may cover a large area and contain a
@ -60,22 +79,38 @@ Then you define `rpc` methods inside your service definition, specifying their r
rpc ListFeatures(Rectangle) returns (stream Feature) {}
```
- A *client-side streaming RPC* where the client writes a sequence of messages and sends them to the server, again using a provided stream. Once the client has finished writing the messages, it waits for the server to read them all and return its response. You specify a client-side streaming method by placing the `stream` keyword before the *request* type.
```
- A *client-side streaming RPC* where the client writes a sequence of messages
and sends them to the server, again using a provided stream. Once the client
has finished writing the messages, it waits for the server to read them all
and return its response. You specify a client-side streaming method by placing
the `stream` keyword before the *request* type.
```protobuf
// Accepts a stream of Points on a route being traversed, returning a
// RouteSummary when traversal is completed.
rpc RecordRoute(stream Point) returns (RouteSummary) {}
```
- A *bidirectional streaming RPC* where both sides send a sequence of messages using a read-write stream. The two streams operate independently, so clients and servers can read and write in whatever order they like: for example, the server could wait to receive all the client messages before writing its responses, or it could alternately read a message then write a message, or some other combination of reads and writes. The order of messages in each stream is preserved. You specify this type of method by placing the `stream` keyword before both the request and the response.
```
- A *bidirectional streaming RPC* where both sides send a sequence of messages
using a read-write stream. The two streams operate independently, so clients
and servers can read and write in whatever order they like: for example, the
server could wait to receive all the client messages before writing its
responses, or it could alternately read a message then write a message, or
some other combination of reads and writes. The order of messages in each
stream is preserved. You specify this type of method by placing the `stream`
keyword before both the request and the response.
```protobuf
// Accepts a stream of RouteNotes sent while a route is being traversed,
// while receiving other RouteNotes (e.g. from other users).
rpc RouteChat(stream RouteNote) returns (stream RouteNote) {}
```
Our .proto file also contains protocol buffer message type definitions for all the request and response types used in our service methods - for example, here's the `Point` message type:
```
Our `.proto` file also contains protocol buffer message type definitions for all
the request and response types used in our service methods - for example, here's
the `Point` message type:
```protobuf
// Points are represented as latitude-longitude pairs in the E7 representation
// (degrees multiplied by 10**7 and rounded to the nearest integer).
// Latitudes should be in the range +/- 90 degrees and longitude should be in
@ -86,12 +121,16 @@ message Point {
}
```
## Generating client and server code
Next we need to generate the gRPC client and server interfaces from our .proto service definition. We do this using the protocol buffer compiler `protoc` with a special gRPC C++ plugin.
Next we need to generate the gRPC client and server interfaces from our `.proto`
service definition. We do this using the protocol buffer compiler `protoc` with
a special gRPC C++ plugin.
For simplicity, we've provided a [makefile](route_guide/Makefile) that runs `protoc` for you with the appropriate plugin, input, and output (if you want to run this yourself, make sure you've installed protoc and followed the gRPC code [installation instructions](../../INSTALL.md) first):
For simplicity, we've provided a [makefile](route_guide/Makefile) that runs
`protoc` for you with the appropriate plugin, input, and output (if you want to
run this yourself, make sure you've installed protoc and followed the gRPC code
[installation instructions](../../INSTALL.md) first):
```shell
$ make route_guide.grpc.pb.cc route_guide.pb.cc
@ -107,39 +146,58 @@ $ protoc -I ../../protos --cpp_out=. ../../protos/route_guide.proto
Running this command generates the following files in your current directory:
- `route_guide.pb.h`, the header which declares your generated message classes
- `route_guide.pb.cc`, which contains the implementation of your message classes
- `route_guide.grpc.pb.h`, the header which declares your generated service classes
- `route_guide.grpc.pb.cc`, which contains the implementation of your service classes
- `route_guide.grpc.pb.h`, the header which declares your generated service
classes
- `route_guide.grpc.pb.cc`, which contains the implementation of your service
classes
These contain:
- All the protocol buffer code to populate, serialize, and retrieve our request and response message types
- All the protocol buffer code to populate, serialize, and retrieve our request
and response message types
- A class called `RouteGuide` that contains
- a remote interface type (or *stub*) for clients to call with the methods defined in the `RouteGuide` service.
- two abstract interfaces for servers to implement, also with the methods defined in the `RouteGuide` service.
- a remote interface type (or *stub*) for clients to call with the methods
defined in the `RouteGuide` service.
- two abstract interfaces for servers to implement, also with the methods
defined in the `RouteGuide` service.
<a name="server"></a>
## Creating the server
First let's look at how we create a `RouteGuide` server. If you're only interested in creating gRPC clients, you can skip this section and go straight to [Creating the client](#client) (though you might find it interesting anyway!).
First let's look at how we create a `RouteGuide` server. If you're only
interested in creating gRPC clients, you can skip this section and go straight
to [Creating the client](#client) (though you might find it interesting
anyway!).
There are two parts to making our `RouteGuide` service do its job:
- Implementing the service interface generated from our service definition: doing the actual "work" of our service.
- Running a gRPC server to listen for requests from clients and return the service responses.
- Implementing the service interface generated from our service definition:
doing the actual "work" of our service.
- Running a gRPC server to listen for requests from clients and return the
service responses.
You can find our example `RouteGuide` server in [route_guide/route_guide_server.cc](route_guide/route_guide_server.cc). Let's take a closer look at how it works.
You can find our example `RouteGuide` server in
[route_guide/route_guide_server.cc](route_guide/route_guide_server.cc). Let's
take a closer look at how it works.
### Implementing RouteGuide
As you can see, our server has a `RouteGuideImpl` class that implements the generated `RouteGuide::Service` interface:
As you can see, our server has a `RouteGuideImpl` class that implements the
generated `RouteGuide::Service` interface:
```cpp
class RouteGuideImpl final : public RouteGuide::Service {
...
}
```
In this case we're implementing the *synchronous* version of `RouteGuide`, which provides our default gRPC server behaviour. It's also possible to implement an asynchronous interface, `RouteGuide::AsyncService`, which allows you to further customize your server's threading behaviour, though we won't look at this in this tutorial.
In this case we're implementing the *synchronous* version of `RouteGuide`, which
provides our default gRPC server behaviour. It's also possible to implement an
asynchronous interface, `RouteGuide::AsyncService`, which allows you to further
customize your server's threading behaviour, though we won't look at this in
this tutorial.
`RouteGuideImpl` implements all our service methods. Let's look at the simplest type first, `GetFeature`, which just gets a `Point` from the client and returns the corresponding feature information from its database in a `Feature`.
`RouteGuideImpl` implements all our service methods. Let's look at the simplest
type first, `GetFeature`, which just gets a `Point` from the client and returns
the corresponding feature information from its database in a `Feature`.
```cpp
Status GetFeature(ServerContext* context, const Point* point,
@ -150,34 +208,52 @@ In this case we're implementing the *synchronous* version of `RouteGuide`, which
}
```
The method is passed a context object for the RPC, the client's `Point` protocol buffer request, and a `Feature` protocol buffer to fill in with the response information. In the method we populate the `Feature` with the appropriate information, and then `return` with an `OK` status to tell gRPC that we've finished dealing with the RPC and that the `Feature` can be returned to the client.
The method is passed a context object for the RPC, the client's `Point` protocol
buffer request, and a `Feature` protocol buffer to fill in with the response
information. In the method we populate the `Feature` with the appropriate
information, and then `return` with an `OK` status to tell gRPC that we've
finished dealing with the RPC and that the `Feature` can be returned to the
client.
Now let's look at something a bit more complicated - a streaming RPC. `ListFeatures` is a server-side streaming RPC, so we need to send back multiple `Feature`s to our client.
Now let's look at something a bit more complicated - a streaming RPC.
`ListFeatures` is a server-side streaming RPC, so we need to send back multiple
`Feature`s to our client.
```cpp
Status ListFeatures(ServerContext* context, const Rectangle* rectangle,
ServerWriter<Feature>* writer) override {
auto lo = rectangle->lo();
auto hi = rectangle->hi();
long left = std::min(lo.longitude(), hi.longitude());
long right = std::max(lo.longitude(), hi.longitude());
long top = std::max(lo.latitude(), hi.latitude());
long bottom = std::min(lo.latitude(), hi.latitude());
for (const Feature& f : feature_list_) {
if (f.location().longitude() >= left &&
f.location().longitude() <= right &&
f.location().latitude() >= bottom &&
f.location().latitude() <= top) {
writer->Write(f);
}
Status ListFeatures(ServerContext* context, const Rectangle* rectangle,
ServerWriter<Feature>* writer) override {
auto lo = rectangle->lo();
auto hi = rectangle->hi();
long left = std::min(lo.longitude(), hi.longitude());
long right = std::max(lo.longitude(), hi.longitude());
long top = std::max(lo.latitude(), hi.latitude());
long bottom = std::min(lo.latitude(), hi.latitude());
for (const Feature& f : feature_list_) {
if (f.location().longitude() >= left &&
f.location().longitude() <= right &&
f.location().latitude() >= bottom &&
f.location().latitude() <= top) {
writer->Write(f);
}
return Status::OK;
}
return Status::OK;
}
```
As you can see, instead of getting simple request and response objects in our method parameters, this time we get a request object (the `Rectangle` in which our client wants to find `Feature`s) and a special `ServerWriter` object. In the method, we populate as many `Feature` objects as we need to return, writing them to the `ServerWriter` using its `Write()` method. Finally, as in our simple RPC, we `return Status::OK` to tell gRPC that we've finished writing responses.
As you can see, instead of getting simple request and response objects in our
method parameters, this time we get a request object (the `Rectangle` in which
our client wants to find `Feature`s) and a special `ServerWriter` object. In the
method, we populate as many `Feature` objects as we need to return, writing them
to the `ServerWriter` using its `Write()` method. Finally, as in our simple RPC,
we `return Status::OK` to tell gRPC that we've finished writing responses.
If you look at the client-side streaming method `RecordRoute` you'll see it's quite similar, except this time we get a `ServerReader` instead of a request object and a single response. We use the `ServerReader`s `Read()` method to repeatedly read in our client's requests to a request object (in this case a `Point`) until there are no more messages: the server needs to check the return value of `Read()` after each call. If `true`, the stream is still good and it can continue reading; if `false` the message stream has ended.
If you look at the client-side streaming method `RecordRoute` you'll see it's
quite similar, except this time we get a `ServerReader` instead of a request
object and a single response. We use the `ServerReader`s `Read()` method to
repeatedly read in our client's requests to a request object (in this case a
`Point`) until there are no more messages: the server needs to check the return
value of `Read()` after each call. If `true`, the stream is still good and it
can continue reading; if `false` the message stream has ended.
```cpp
while (stream->Read(&point)) {
@ -205,11 +281,18 @@ Finally, let's look at our bidirectional streaming RPC `RouteChat()`.
}
```
This time we get a `ServerReaderWriter` that can be used to read *and* write messages. The syntax for reading and writing here is exactly the same as for our client-streaming and server-streaming methods. Although each side will always get the other's messages in the order they were written, both the client and server can read and write in any order — the streams operate completely independently.
This time we get a `ServerReaderWriter` that can be used to read *and* write
messages. The syntax for reading and writing here is exactly the same as for our
client-streaming and server-streaming methods. Although each side will always
get the other's messages in the order they were written, both the client and
server can read and write in any order — the streams operate completely
independently.
### Starting the server
Once we've implemented all our methods, we also need to start up a gRPC server so that clients can actually use our service. The following snippet shows how we do this for our `RouteGuide` service:
Once we've implemented all our methods, we also need to start up a gRPC server
so that clients can actually use our service. The following snippet shows how we
do this for our `RouteGuide` service:
```cpp
void RunServer(const std::string& db_path) {
@ -227,44 +310,55 @@ void RunServer(const std::string& db_path) {
As you can see, we build and start our server using a `ServerBuilder`. To do this, we:
1. Create an instance of our service implementation class `RouteGuideImpl`.
2. Create an instance of the factory `ServerBuilder` class.
3. Specify the address and port we want to use to listen for client requests using the builder's `AddListeningPort()` method.
4. Register our service implementation with the builder.
5. Call `BuildAndStart()` on the builder to create and start an RPC server for our service.
5. Call `Wait()` on the server to do a blocking wait until process is killed or `Shutdown()` is called.
1. Create an instance of the factory `ServerBuilder` class.
1. Specify the address and port we want to use to listen for client requests
using the builder's `AddListeningPort()` method.
1. Register our service implementation with the builder.
1. Call `BuildAndStart()` on the builder to create and start an RPC server for
our service.
1. Call `Wait()` on the server to do a blocking wait until process is killed or
`Shutdown()` is called.
<a name="client"></a>
## Creating the client
In this section, we'll look at creating a C++ client for our `RouteGuide` service. You can see our complete example client code in [route_guide/route_guide_client.cc](route_guide/route_guide_client.cc).
In this section, we'll look at creating a C++ client for our `RouteGuide`
service. You can see our complete example client code in
[route_guide/route_guide_client.cc](route_guide/route_guide_client.cc).
### Creating a stub
To call service methods, we first need to create a *stub*.
First we need to create a gRPC *channel* for our stub, specifying the server address and port we want to connect to without SSL:
First we need to create a gRPC *channel* for our stub, specifying the server
address and port we want to connect to without SSL:
```cpp
grpc::CreateChannel("localhost:50051", grpc::InsecureChannelCredentials());
```
Now we can use the channel to create our stub using the `NewStub` method provided in the `RouteGuide` class we generated from our .proto.
Now we can use the channel to create our stub using the `NewStub` method
provided in the `RouteGuide` class we generated from our `.proto`.
```cpp
public:
RouteGuideClient(std::shared_ptr<Channel> channel, const std::string& db)
: stub_(RouteGuide::NewStub(channel)) {
...
}
public:
RouteGuideClient(std::shared_ptr<Channel> channel, const std::string& db)
: stub_(RouteGuide::NewStub(channel)) {
...
}
```
### Calling service methods
Now let's look at how we call our service methods. Note that in this tutorial we're calling the *blocking/synchronous* versions of each method: this means that the RPC call waits for the server to respond, and will either return a response or raise an exception.
Now let's look at how we call our service methods. Note that in this tutorial
we're calling the *blocking/synchronous* versions of each method: this means
that the RPC call waits for the server to respond, and will either return a
response or raise an exception.
#### Simple RPC
Calling the simple RPC `GetFeature` is nearly as straightforward as calling a local method.
Calling the simple RPC `GetFeature` is nearly as straightforward as calling a
local method.
```cpp
Point point;
@ -281,33 +375,53 @@ Calling the simple RPC `GetFeature` is nearly as straightforward as calling a lo
}
```
As you can see, we create and populate a request protocol buffer object (in our case `Point`), and create a response protocol buffer object for the server to fill in. We also create a `ClientContext` object for our call - you can optionally set RPC configuration values on this object, such as deadlines, though for now we'll use the default settings. Note that you cannot reuse this object between calls. Finally, we call the method on the stub, passing it the context, request, and response. If the method returns `OK`, then we can read the response information from the server from our response object.
As you can see, we create and populate a request protocol buffer object (in our
case `Point`), and create a response protocol buffer object for the server to
fill in. We also create a `ClientContext` object for our call - you can
optionally set RPC configuration values on this object, such as deadlines,
though for now we'll use the default settings. Note that you cannot reuse this
object between calls. Finally, we call the method on the stub, passing it the
context, request, and response. If the method returns `OK`, then we can read the
response information from the server from our response object.
```cpp
std::cout << "Found feature called " << feature->name() << " at "
<< feature->location().latitude()/kCoordFactor_ << ", "
<< feature->location().longitude()/kCoordFactor_ << std::endl;
std::cout << "Found feature called " << feature->name() << " at "
<< feature->location().latitude()/kCoordFactor_ << ", "
<< feature->location().longitude()/kCoordFactor_ << std::endl;
```
#### Streaming RPCs
Now let's look at our streaming methods. If you've already read [Creating the server](#server) some of this may look very familiar - streaming RPCs are implemented in a similar way on both sides. Here's where we call the server-side streaming method `ListFeatures`, which returns a stream of geographical `Feature`s:
Now let's look at our streaming methods. If you've already read [Creating the
server](#server) some of this may look very familiar - streaming RPCs are
implemented in a similar way on both sides. Here's where we call the server-side
streaming method `ListFeatures`, which returns a stream of geographical
`Feature`s:
```cpp
std::unique_ptr<ClientReader<Feature> > reader(
stub_->ListFeatures(&context, rect));
while (reader->Read(&feature)) {
std::cout << "Found feature called "
<< feature.name() << " at "
<< feature.location().latitude()/kCoordFactor_ << ", "
<< feature.location().longitude()/kCoordFactor_ << std::endl;
}
Status status = reader->Finish();
std::unique_ptr<ClientReader<Feature> > reader(
stub_->ListFeatures(&context, rect));
while (reader->Read(&feature)) {
std::cout << "Found feature called "
<< feature.name() << " at "
<< feature.location().latitude()/kCoordFactor_ << ", "
<< feature.location().longitude()/kCoordFactor_ << std::endl;
}
Status status = reader->Finish();
```
Instead of passing the method a context, request, and response, we pass it a context and request and get a `ClientReader` object back. The client can use the `ClientReader` to read the server's responses. We use the `ClientReader`s `Read()` method to repeatedly read in the server's responses to a response protocol buffer object (in this case a `Feature`) until there are no more messages: the client needs to check the return value of `Read()` after each call. If `true`, the stream is still good and it can continue reading; if `false` the message stream has ended. Finally, we call `Finish()` on the stream to complete the call and get our RPC status.
Instead of passing the method a context, request, and response, we pass it a
context and request and get a `ClientReader` object back. The client can use the
`ClientReader` to read the server's responses. We use the `ClientReader`s
`Read()` method to repeatedly read in the server's responses to a response
protocol buffer object (in this case a `Feature`) until there are no more
messages: the client needs to check the return value of `Read()` after each
call. If `true`, the stream is still good and it can continue reading; if
`false` the message stream has ended. Finally, we call `Finish()` on the stream
to complete the call and get our RPC status.
The client-side streaming method `RecordRoute` is similar, except there we pass the method a context and response object and get back a `ClientWriter`.
The client-side streaming method `RecordRoute` is similar, except there we pass
the method a context and response object and get back a `ClientWriter`.
```cpp
std::unique_ptr<ClientWriter<Point> > writer(
@ -337,16 +451,26 @@ The client-side streaming method `RecordRoute` is similar, except there we pass
}
```
Once we've finished writing our client's requests to the stream using `Write()`, we need to call `WritesDone()` on the stream to let gRPC know that we've finished writing, then `Finish()` to complete the call and get our RPC status. If the status is `OK`, our response object that we initially passed to `RecordRoute()` will be populated with the server's response.
Once we've finished writing our client's requests to the stream using `Write()`,
we need to call `WritesDone()` on the stream to let gRPC know that we've
finished writing, then `Finish()` to complete the call and get our RPC status.
If the status is `OK`, our response object that we initially passed to
`RecordRoute()` will be populated with the server's response.
Finally, let's look at our bidirectional streaming RPC `RouteChat()`. In this case, we just pass a context to the method and get back a `ClientReaderWriter`, which we can use to both write and read messages.
Finally, let's look at our bidirectional streaming RPC `RouteChat()`. In this
case, we just pass a context to the method and get back a `ClientReaderWriter`,
which we can use to both write and read messages.
```cpp
std::shared_ptr<ClientReaderWriter<RouteNote, RouteNote> > stream(
stub_->RouteChat(&context));
std::shared_ptr<ClientReaderWriter<RouteNote, RouteNote> > stream(
stub_->RouteChat(&context));
```
The syntax for reading and writing here is exactly the same as for our client-streaming and server-streaming methods. Although each side will always get the other's messages in the order they were written, both the client and server can read and write in any order — the streams operate completely independently.
The syntax for reading and writing here is exactly the same as for our
client-streaming and server-streaming methods. Although each side will always
get the other's messages in the order they were written, both the client and
server can read and write in any order — the streams operate completely
independently.
## Try it out!
@ -362,4 +486,3 @@ Run the client (in a different terminal):
```shell
$ ./route_guide_client
```

@ -107,7 +107,7 @@ ifneq ($(HAS_VALID_PROTOC),true)
@echo "Please install Google protocol buffers 3.0.0 and its compiler."
@echo "You can find it here:"
@echo
@echo " https://github.com/google/protobuf/releases/tag/v3.0.0-beta-3.3"
@echo " https://github.com/google/protobuf/releases/tag/v3.0.0"
@echo
@echo "Here is what I get when trying to evaluate your version of protoc:"
@echo

@ -96,7 +96,7 @@ ifneq ($(HAS_VALID_PROTOC),true)
@echo "Please install Google protocol buffers 3.0.0 and its compiler."
@echo "You can find it here:"
@echo
@echo " https://github.com/google/protobuf/releases/tag/v3.0.0-beta-3.3"
@echo " https://github.com/google/protobuf/releases/tag/v3.0.0"
@echo
@echo "Here is what I get when trying to evaluate your version of protoc:"
@echo

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Grpc.Tools" version="0.15.0" />
</packages>

@ -9,11 +9,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GreeterServer", "GreeterSer
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GreeterClient", "GreeterClient\GreeterClient.csproj", "{ACCF4597-3748-4117-8633-1CB767F8CCC3}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{FF1EBE95-F20D-4C27-8A61-D0125F3C8152}"
ProjectSection(SolutionItems) = preProject
.nuget\packages.config = .nuget\packages.config
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU

@ -4,4 +4,5 @@
<package id="Grpc" version="0.15.0" targetFramework="net45" />
<package id="Grpc.Core" version="0.15.0" targetFramework="net45" />
<package id="Ix-Async" version="1.2.5" targetFramework="net45" />
<package id="Grpc.Tools" version="0.15.0" targetFramework="net45" />
</packages>

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Grpc.Tools" version="0.15.0" />
</packages>

@ -9,11 +9,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RouteGuideClient", "RouteGu
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RouteGuideServer", "RouteGuideServer\RouteGuideServer.csproj", "{4B7C7794-BE24-4477-ACE7-18259EB73D27}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{2F6B184B-A576-4F21-AF2E-27E73D1FC96E}"
ProjectSection(SolutionItems) = preProject
.nuget\packages.config = .nuget\packages.config
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU

@ -45,15 +45,15 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Interactive.Async, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Ix-Async.1.2.5\lib\net45\System.Interactive.Async.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="System.Interactive.Async, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Ix-Async.1.2.5\lib\net45\System.Interactive.Async.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />

@ -47,15 +47,15 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Interactive.Async, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Ix-Async.1.2.5\lib\net45\System.Interactive.Async.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="System.Interactive.Async, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Ix-Async.1.2.5\lib\net45\System.Interactive.Async.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />

@ -5,4 +5,5 @@
<package id="Grpc.Core" version="0.15.0" targetFramework="net45" />
<package id="Ix-Async" version="1.2.5" targetFramework="net45" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
<package id="Grpc.Tools" version="0.15.0" targetFramework="net45" />
</packages>

@ -14,7 +14,7 @@ Pod::Spec.new do |s|
src = "../../protos"
# Run protoc with the Objective-C and gRPC plugins to generate protocol messages and gRPC clients.
s.dependency "!ProtoCompiler-gRPCPlugin", "~> 1.0.0-pre1"
s.dependency "!ProtoCompiler-gRPCPlugin", "~> 1.0.0-pre1.2"
# Pods directory corresponding to this app's Podfile, relative to the location of this podspec.
pods_root = 'Pods'

@ -14,7 +14,7 @@ Pod::Spec.new do |s|
src = "../../protos"
# Run protoc with the Objective-C and gRPC plugins to generate protocol messages and gRPC clients.
s.dependency "!ProtoCompiler-gRPCPlugin", "~> 1.0.0-pre1"
s.dependency "!ProtoCompiler-gRPCPlugin", "~> 1.0.0-pre1.2"
# Pods directory corresponding to this app's Podfile, relative to the location of this podspec.
pods_root = 'Pods'

@ -14,7 +14,7 @@ Pod::Spec.new do |s|
src = "../../protos"
# Run protoc with the Objective-C and gRPC plugins to generate protocol messages and gRPC clients.
s.dependency "!ProtoCompiler-gRPCPlugin", "~> 1.0.0-pre1"
s.dependency "!ProtoCompiler-gRPCPlugin", "~> 1.0.0-pre1.2"
# Pods directory corresponding to this app's Podfile, relative to the location of this podspec.
pods_root = 'Pods'

@ -68,7 +68,7 @@ def get_distance(start, end):
R = 6371000; # metres
return R * c;
class RouteGuideServicer(route_guide_pb2.BetaRouteGuideServicer):
class RouteGuideServicer(route_guide_pb2.RouteGuideServicer):
"""Provides methods that implement functionality of route guide server."""
def __init__(self):

@ -1,9 +1,3 @@
# GRPC CocoaPods podspec
# This file has been automatically generated from a template file.
# Please look at the templates directory instead.
# This file can be regenerated from the template by running
# tools/buildgen/generate_projects.sh
# Copyright 2015, Google Inc.
# All rights reserved.
#
@ -61,7 +55,7 @@ Pod::Spec.new do |s|
s.dependency 'gRPC', version
s.dependency 'gRPC-RxLibrary', version
s.dependency 'Protobuf', '~> 3.0.0-beta-3.1'
s.dependency 'Protobuf', '~> 3.0'
# This is needed by all pods that depend on Protobuf:
s.pod_target_xcconfig = {
'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1',

@ -1,9 +1,3 @@
# GRPC CocoaPods podspec
# This file has been automatically generated from a template file.
# Please look at the templates directory instead.
# This file can be regenerated from the template by running
# tools/buildgen/generate_projects.sh
# Copyright 2015, Google Inc.
# All rights reserved.
#

@ -1,9 +1,3 @@
# GRPC CocoaPods podspec
# This file has been automatically generated from a template file.
# Please look at the templates directory instead.
# This file can be regenerated from the template by running
# tools/buildgen/generate_projects.sh
# Copyright 2015, Google Inc.
# All rights reserved.
#

@ -83,7 +83,7 @@ class ServiceResponse;
// ===================================================================
class ServerReflectionRequest : public ::google::protobuf::Message {
class ServerReflectionRequest : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:grpc.reflection.v1alpha.ServerReflectionRequest) */ {
public:
ServerReflectionRequest();
virtual ~ServerReflectionRequest();
@ -126,7 +126,11 @@ class ServerReflectionRequest : public ::google::protobuf::Message {
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
return InternalSerializeWithCachedSizesToArray(false, output);
}
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
@ -260,7 +264,7 @@ class ServerReflectionRequest : public ::google::protobuf::Message {
};
// -------------------------------------------------------------------
class ExtensionRequest : public ::google::protobuf::Message {
class ExtensionRequest : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:grpc.reflection.v1alpha.ExtensionRequest) */ {
public:
ExtensionRequest();
virtual ~ExtensionRequest();
@ -294,7 +298,11 @@ class ExtensionRequest : public ::google::protobuf::Message {
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
return InternalSerializeWithCachedSizesToArray(false, output);
}
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
@ -350,7 +358,7 @@ class ExtensionRequest : public ::google::protobuf::Message {
};
// -------------------------------------------------------------------
class ServerReflectionResponse : public ::google::protobuf::Message {
class ServerReflectionResponse : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:grpc.reflection.v1alpha.ServerReflectionResponse) */ {
public:
ServerReflectionResponse();
virtual ~ServerReflectionResponse();
@ -392,7 +400,11 @@ class ServerReflectionResponse : public ::google::protobuf::Message {
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
return InternalSerializeWithCachedSizesToArray(false, output);
}
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
@ -505,7 +517,7 @@ class ServerReflectionResponse : public ::google::protobuf::Message {
};
// -------------------------------------------------------------------
class FileDescriptorResponse : public ::google::protobuf::Message {
class FileDescriptorResponse : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:grpc.reflection.v1alpha.FileDescriptorResponse) */ {
public:
FileDescriptorResponse();
virtual ~FileDescriptorResponse();
@ -539,7 +551,11 @@ class FileDescriptorResponse : public ::google::protobuf::Message {
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
return InternalSerializeWithCachedSizesToArray(false, output);
}
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
@ -593,7 +609,7 @@ class FileDescriptorResponse : public ::google::protobuf::Message {
};
// -------------------------------------------------------------------
class ExtensionNumberResponse : public ::google::protobuf::Message {
class ExtensionNumberResponse : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:grpc.reflection.v1alpha.ExtensionNumberResponse) */ {
public:
ExtensionNumberResponse();
virtual ~ExtensionNumberResponse();
@ -627,7 +643,11 @@ class ExtensionNumberResponse : public ::google::protobuf::Message {
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
return InternalSerializeWithCachedSizesToArray(false, output);
}
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
@ -690,7 +710,7 @@ class ExtensionNumberResponse : public ::google::protobuf::Message {
};
// -------------------------------------------------------------------
class ListServiceResponse : public ::google::protobuf::Message {
class ListServiceResponse : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:grpc.reflection.v1alpha.ListServiceResponse) */ {
public:
ListServiceResponse();
virtual ~ListServiceResponse();
@ -724,7 +744,11 @@ class ListServiceResponse : public ::google::protobuf::Message {
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
return InternalSerializeWithCachedSizesToArray(false, output);
}
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
@ -774,7 +798,7 @@ class ListServiceResponse : public ::google::protobuf::Message {
};
// -------------------------------------------------------------------
class ServiceResponse : public ::google::protobuf::Message {
class ServiceResponse : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:grpc.reflection.v1alpha.ServiceResponse) */ {
public:
ServiceResponse();
virtual ~ServiceResponse();
@ -808,7 +832,11 @@ class ServiceResponse : public ::google::protobuf::Message {
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
return InternalSerializeWithCachedSizesToArray(false, output);
}
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();
@ -857,7 +885,7 @@ class ServiceResponse : public ::google::protobuf::Message {
};
// -------------------------------------------------------------------
class ErrorResponse : public ::google::protobuf::Message {
class ErrorResponse : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:grpc.reflection.v1alpha.ErrorResponse) */ {
public:
ErrorResponse();
virtual ~ErrorResponse();
@ -891,7 +919,11 @@ class ErrorResponse : public ::google::protobuf::Message {
::google::protobuf::io::CodedInputStream* input);
void SerializeWithCachedSizes(
::google::protobuf::io::CodedOutputStream* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const;
::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* output) const;
::google::protobuf::uint8* SerializeWithCachedSizesToArray(::google::protobuf::uint8* output) const {
return InternalSerializeWithCachedSizesToArray(false, output);
}
int GetCachedSize() const { return _cached_size_; }
private:
void SharedCtor();

@ -3,6 +3,6 @@ coverage>=4.0
cython>=0.23
enum34>=1.0.4
futures>=2.2.0
protobuf>=3.0.0a3
protobuf>=3.0.0
six>=1.10
wheel>=0.29
wheel>=0.29

@ -207,7 +207,7 @@ INSTALL_REQUIRES = (
'futures>=2.2.0',
# TODO(atash): eventually split the grpcio package into a metapackage
# depending on protobuf and the runtime component (independent of protobuf)
'protobuf>=3.0.0a3',
'protobuf>=3.0.0',
)
SETUP_REQUIRES = INSTALL_REQUIRES + (

@ -114,8 +114,8 @@ map<grpc::string, const Descriptor *> GetAllMessages(
const MethodDescriptor *method = service->method(method_num);
const Descriptor *input_type = method->input_type();
const Descriptor *output_type = method->output_type();
message_types[input_type->name()] = input_type;
message_types[output_type->name()] = output_type;
message_types[input_type->full_name()] = input_type;
message_types[output_type->full_name()] = output_type;
}
}
return message_types;
@ -127,7 +127,7 @@ grpc::string MessageIdentifierName(const grpc::string &name) {
grpc::string NodeObjectPath(const Descriptor *descriptor) {
grpc::string module_alias = ModuleAlias(descriptor->file()->name());
grpc::string name = descriptor->name();
grpc::string name = descriptor->full_name();
grpc_generator::StripPrefix(&name, descriptor->file()->package() + ".");
return module_alias + "." + name;
}
@ -135,8 +135,9 @@ grpc::string NodeObjectPath(const Descriptor *descriptor) {
// Prints out the message serializer and deserializer functions
void PrintMessageTransformer(const Descriptor *descriptor, Printer *out) {
map<grpc::string, grpc::string> template_vars;
template_vars["identifier_name"] = MessageIdentifierName(descriptor->name());
template_vars["name"] = descriptor->name();
grpc::string full_name = descriptor->full_name();
template_vars["identifier_name"] = MessageIdentifierName(full_name);
template_vars["name"] = full_name;
template_vars["node_name"] = NodeObjectPath(descriptor);
// Print the serializer
out->Print(template_vars, "function serialize_$identifier_name$(arg) {\n");
@ -169,9 +170,9 @@ void PrintMethod(const MethodDescriptor *method, Printer *out) {
vars["service_name"] = method->service()->full_name();
vars["name"] = method->name();
vars["input_type"] = NodeObjectPath(input_type);
vars["input_type_id"] = MessageIdentifierName(input_type->name());
vars["input_type_id"] = MessageIdentifierName(input_type->full_name());
vars["output_type"] = NodeObjectPath(output_type);
vars["output_type_id"] = MessageIdentifierName(output_type->name());
vars["output_type_id"] = MessageIdentifierName(output_type->full_name());
vars["client_stream"] = method->client_streaming() ? "true" : "false";
vars["server_stream"] = method->server_streaming() ? "true" : "false";
out->Print("{\n");

@ -88,14 +88,21 @@ static void on_initial_connect_string_sent(grpc_exec_ctx *exec_ctx, void *arg,
}
static void on_handshake_done(grpc_exec_ctx *exec_ctx, grpc_endpoint *endpoint,
grpc_channel_args *args, void *user_data,
grpc_channel_args *args,
gpr_slice_buffer *read_buffer, void *user_data,
grpc_error *error) {
connector *c = user_data;
c->result->transport =
grpc_create_chttp2_transport(exec_ctx, args, endpoint, 1);
GPR_ASSERT(c->result->transport);
grpc_chttp2_transport_start_reading(exec_ctx, c->result->transport, NULL, 0);
c->result->channel_args = args;
if (error != GRPC_ERROR_NONE) {
grpc_channel_args_destroy(args);
gpr_free(read_buffer);
} else {
c->result->transport =
grpc_create_chttp2_transport(exec_ctx, args, endpoint, 1);
GPR_ASSERT(c->result->transport);
grpc_chttp2_transport_start_reading(exec_ctx, c->result->transport,
read_buffer);
c->result->channel_args = args;
}
grpc_closure *notify = c->notify;
c->notify = NULL;
grpc_exec_ctx_sched(exec_ctx, notify, error, NULL);

@ -75,7 +75,7 @@ grpc_channel *grpc_insecure_channel_create_from_fd(
grpc_channel *channel = grpc_channel_create(
&exec_ctx, target, final_args, GRPC_CLIENT_DIRECT_CHANNEL, transport);
grpc_channel_args_destroy(final_args);
grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL, 0);
grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL);
grpc_exec_ctx_finish(&exec_ctx);

@ -114,8 +114,7 @@ static void on_secure_handshake_done(grpc_exec_ctx *exec_ctx, void *arg,
gpr_mu_unlock(&c->mu);
c->result->transport = grpc_create_chttp2_transport(
exec_ctx, c->args.channel_args, secure_endpoint, 1);
grpc_chttp2_transport_start_reading(exec_ctx, c->result->transport, NULL,
0);
grpc_chttp2_transport_start_reading(exec_ctx, c->result->transport, NULL);
auth_context_arg = grpc_auth_context_to_arg(auth_context);
c->result->channel_args =
grpc_channel_args_copy_and_add(c->tmp_args, &auth_context_arg, 1);
@ -126,10 +125,13 @@ static void on_secure_handshake_done(grpc_exec_ctx *exec_ctx, void *arg,
}
static void on_handshake_done(grpc_exec_ctx *exec_ctx, grpc_endpoint *endpoint,
grpc_channel_args *args, void *user_data,
grpc_channel_args *args,
gpr_slice_buffer *read_buffer, void *user_data,
grpc_error *error) {
connector *c = user_data;
c->tmp_args = args;
if (error != GRPC_ERROR_NONE) {
gpr_free(read_buffer);
grpc_closure *notify = c->notify;
c->notify = NULL;
grpc_exec_ctx_sched(exec_ctx, notify, error, NULL);
@ -137,10 +139,9 @@ static void on_handshake_done(grpc_exec_ctx *exec_ctx, grpc_endpoint *endpoint,
// TODO(roth, jboeuf): Convert security connector handshaking to use new
// handshake API, and then move the code from on_secure_handshake_done()
// into this function.
c->tmp_args = args;
grpc_channel_security_connector_do_handshake(
exec_ctx, c->security_connector, endpoint, c->args.deadline,
on_secure_handshake_done, c);
exec_ctx, c->security_connector, endpoint, read_buffer,
c->args.deadline, on_secure_handshake_done, c);
}
}

@ -55,7 +55,8 @@ typedef struct server_connect_state {
} server_connect_state;
static void on_handshake_done(grpc_exec_ctx *exec_ctx, grpc_endpoint *endpoint,
grpc_channel_args *args, void *user_data,
grpc_channel_args *args,
gpr_slice_buffer *read_buffer, void *user_data,
grpc_error *error) {
server_connect_state *state = user_data;
if (error != GRPC_ERROR_NONE) {
@ -64,6 +65,7 @@ static void on_handshake_done(grpc_exec_ctx *exec_ctx, grpc_endpoint *endpoint,
grpc_error_free_string(error_str);
GRPC_ERROR_UNREF(error);
grpc_handshake_manager_shutdown(exec_ctx, state->handshake_mgr);
gpr_free(read_buffer);
} else {
// Beware that the call to grpc_create_chttp2_transport() has to happen
// before grpc_tcp_server_destroy(). This is fine here, but similar code
@ -75,7 +77,7 @@ static void on_handshake_done(grpc_exec_ctx *exec_ctx, grpc_endpoint *endpoint,
grpc_server_setup_transport(exec_ctx, state->server, transport,
state->accepting_pollset,
grpc_server_get_channel_args(state->server));
grpc_chttp2_transport_start_reading(exec_ctx, transport, NULL, 0);
grpc_chttp2_transport_start_reading(exec_ctx, transport, read_buffer);
}
// Clean up.
grpc_channel_args_destroy(args);

@ -67,7 +67,7 @@ void grpc_server_add_insecure_channel_from_fd(grpc_server *server,
&exec_ctx, server_args, server_endpoint, 0 /* is_client */);
grpc_endpoint_add_to_pollset(&exec_ctx, server_endpoint, grpc_cq_pollset(cq));
grpc_server_setup_transport(&exec_ctx, server, transport, NULL, server_args);
grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL, 0);
grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL);
grpc_exec_ctx_finish(&exec_ctx);
}

@ -111,7 +111,7 @@ static void on_secure_handshake_done(grpc_exec_ctx *exec_ctx, void *statep,
grpc_server_setup_transport(exec_ctx, state->state->server, transport,
state->accepting_pollset, args_copy);
grpc_channel_args_destroy(args_copy);
grpc_chttp2_transport_start_reading(exec_ctx, transport, NULL, 0);
grpc_chttp2_transport_start_reading(exec_ctx, transport, NULL);
} else {
/* We need to consume this here, because the server may already have
* gone away. */
@ -128,7 +128,8 @@ static void on_secure_handshake_done(grpc_exec_ctx *exec_ctx, void *statep,
}
static void on_handshake_done(grpc_exec_ctx *exec_ctx, grpc_endpoint *endpoint,
grpc_channel_args *args, void *user_data,
grpc_channel_args *args,
gpr_slice_buffer *read_buffer, void *user_data,
grpc_error *error) {
server_secure_connect *state = user_data;
if (error != GRPC_ERROR_NONE) {
@ -136,9 +137,10 @@ static void on_handshake_done(grpc_exec_ctx *exec_ctx, grpc_endpoint *endpoint,
gpr_log(GPR_ERROR, "Handshaking failed: %s", error_str);
grpc_error_free_string(error_str);
GRPC_ERROR_UNREF(error);
grpc_channel_args_destroy(args);
gpr_free(read_buffer);
grpc_handshake_manager_shutdown(exec_ctx, state->handshake_mgr);
grpc_handshake_manager_destroy(exec_ctx, state->handshake_mgr);
grpc_channel_args_destroy(args);
state_unref(state->state);
gpr_free(state);
return;
@ -150,8 +152,8 @@ static void on_handshake_done(grpc_exec_ctx *exec_ctx, grpc_endpoint *endpoint,
// into this function.
state->args = args;
grpc_server_security_connector_do_handshake(
exec_ctx, state->state->sc, state->acceptor, endpoint, state->deadline,
on_secure_handshake_done, state);
exec_ctx, state->state->sc, state->acceptor, endpoint, read_buffer,
state->deadline, on_secure_handshake_done, state);
}
static void on_accept(grpc_exec_ctx *exec_ctx, void *statep, grpc_endpoint *tcp,

@ -2546,9 +2546,12 @@ grpc_transport *grpc_create_chttp2_transport(
void grpc_chttp2_transport_start_reading(grpc_exec_ctx *exec_ctx,
grpc_transport *transport,
gpr_slice *slices, size_t nslices) {
gpr_slice_buffer *read_buffer) {
grpc_chttp2_transport *t = (grpc_chttp2_transport *)transport;
REF_TRANSPORT(t, "reading_action"); /* matches unref inside reading_action */
gpr_slice_buffer_addn(&t->read_buffer, slices, nslices);
if (read_buffer != NULL) {
gpr_slice_buffer_move_into(read_buffer, &t->read_buffer);
gpr_free(read_buffer);
}
reading_action(exec_ctx, t, GRPC_ERROR_NONE);
}

@ -44,8 +44,10 @@ grpc_transport *grpc_create_chttp2_transport(
grpc_exec_ctx *exec_ctx, const grpc_channel_args *channel_args,
grpc_endpoint *ep, int is_client);
/// Takes ownership of \a read_buffer, which (if non-NULL) contains
/// leftover bytes previously read from the endpoint (e.g., by handshakers).
void grpc_chttp2_transport_start_reading(grpc_exec_ctx *exec_ctx,
grpc_transport *transport,
gpr_slice *slices, size_t nslices);
gpr_slice_buffer *read_buffer);
#endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_CHTTP2_TRANSPORT_H */

@ -62,11 +62,13 @@ void grpc_handshaker_do_handshake(grpc_exec_ctx* exec_ctx,
grpc_handshaker* handshaker,
grpc_endpoint* endpoint,
grpc_channel_args* args,
gpr_slice_buffer* read_buffer,
gpr_timespec deadline,
grpc_tcp_server_acceptor* acceptor,
grpc_handshaker_done_cb cb, void* user_data) {
handshaker->vtable->do_handshake(exec_ctx, handshaker, endpoint, args,
deadline, acceptor, cb, user_data);
read_buffer, deadline, acceptor, cb,
user_data);
}
//
@ -143,7 +145,8 @@ void grpc_handshake_manager_shutdown(grpc_exec_ctx* exec_ctx,
// handshakers together.
static void call_next_handshaker(grpc_exec_ctx* exec_ctx,
grpc_endpoint* endpoint,
grpc_channel_args* args, void* user_data,
grpc_channel_args* args,
gpr_slice_buffer* read_buffer, void* user_data,
grpc_error* error) {
grpc_handshake_manager* mgr = user_data;
GPR_ASSERT(mgr->state != NULL);
@ -151,8 +154,8 @@ static void call_next_handshaker(grpc_exec_ctx* exec_ctx,
// If we got an error, skip all remaining handshakers and invoke the
// caller-supplied callback immediately.
if (error != GRPC_ERROR_NONE) {
mgr->state->final_cb(exec_ctx, endpoint, args, mgr->state->final_user_data,
error);
mgr->state->final_cb(exec_ctx, endpoint, args, read_buffer,
mgr->state->final_user_data, error);
return;
}
grpc_handshaker_done_cb cb = call_next_handshaker;
@ -163,9 +166,9 @@ static void call_next_handshaker(grpc_exec_ctx* exec_ctx,
user_data = mgr->state->final_user_data;
}
// Invoke handshaker.
grpc_handshaker_do_handshake(exec_ctx, mgr->handshakers[mgr->state->index],
endpoint, args, mgr->state->deadline,
mgr->state->acceptor, cb, user_data);
grpc_handshaker_do_handshake(
exec_ctx, mgr->handshakers[mgr->state->index], endpoint, args,
read_buffer, mgr->state->deadline, mgr->state->acceptor, cb, user_data);
++mgr->state->index;
// If this is the last handshaker, clean up state.
if (mgr->state->index == mgr->count) {
@ -180,10 +183,12 @@ void grpc_handshake_manager_do_handshake(
gpr_timespec deadline, grpc_tcp_server_acceptor* acceptor,
grpc_handshaker_done_cb cb, void* user_data) {
grpc_channel_args* args_copy = grpc_channel_args_copy(args);
gpr_slice_buffer* read_buffer = malloc(sizeof(*read_buffer));
gpr_slice_buffer_init(read_buffer);
if (mgr->count == 0) {
// No handshakers registered, so we just immediately call the done
// callback with the passed-in endpoint.
cb(exec_ctx, endpoint, args_copy, user_data, GRPC_ERROR_NONE);
cb(exec_ctx, endpoint, args_copy, read_buffer, user_data, GRPC_ERROR_NONE);
} else {
GPR_ASSERT(mgr->state == NULL);
mgr->state = gpr_malloc(sizeof(struct grpc_handshaker_state));
@ -192,6 +197,7 @@ void grpc_handshake_manager_do_handshake(
mgr->state->acceptor = acceptor;
mgr->state->final_cb = cb;
mgr->state->final_user_data = user_data;
call_next_handshaker(exec_ctx, endpoint, args_copy, mgr, GRPC_ERROR_NONE);
call_next_handshaker(exec_ctx, endpoint, args_copy, read_buffer, mgr,
GRPC_ERROR_NONE);
}
}

@ -36,6 +36,7 @@
#include <grpc/impl/codegen/grpc_types.h>
#include <grpc/impl/codegen/time.h>
#include <grpc/support/slice_buffer.h>
#include "src/core/lib/iomgr/closure.h"
#include "src/core/lib/iomgr/endpoint.h"
@ -56,10 +57,11 @@
typedef struct grpc_handshaker grpc_handshaker;
/// Callback type invoked when a handshaker is done.
/// Takes ownership of \a args.
/// Takes ownership of \a args and \a read_buffer.
typedef void (*grpc_handshaker_done_cb)(grpc_exec_ctx* exec_ctx,
grpc_endpoint* endpoint,
grpc_channel_args* args,
gpr_slice_buffer* read_buffer,
void* user_data, grpc_error* error);
struct grpc_handshaker_vtable {
@ -72,10 +74,12 @@ struct grpc_handshaker_vtable {
/// Performs handshaking. When finished, calls \a cb with \a user_data.
/// Takes ownership of \a args.
/// Takes ownership of \a read_buffer, which contains leftover bytes read
/// from the endpoint by the previous handshaker.
/// \a acceptor will be NULL for client-side handshakers.
void (*do_handshake)(grpc_exec_ctx* exec_ctx, grpc_handshaker* handshaker,
grpc_endpoint* endpoint, grpc_channel_args* args,
gpr_timespec deadline,
gpr_slice_buffer* read_buffer, gpr_timespec deadline,
grpc_tcp_server_acceptor* acceptor,
grpc_handshaker_done_cb cb, void* user_data);
};
@ -101,6 +105,7 @@ void grpc_handshaker_do_handshake(grpc_exec_ctx* exec_ctx,
grpc_handshaker* handshaker,
grpc_endpoint* endpoint,
grpc_channel_args* args,
gpr_slice_buffer* read_buffer,
gpr_timespec deadline,
grpc_tcp_server_acceptor* acceptor,
grpc_handshaker_done_cb cb, void* user_data);

@ -61,6 +61,7 @@ static void httpcli_ssl_destroy(grpc_security_connector *sc) {
static void httpcli_ssl_do_handshake(grpc_exec_ctx *exec_ctx,
grpc_channel_security_connector *sc,
grpc_endpoint *nonsecure_endpoint,
gpr_slice_buffer *read_buffer,
gpr_timespec deadline,
grpc_security_handshake_done_cb cb,
void *user_data) {
@ -69,6 +70,7 @@ static void httpcli_ssl_do_handshake(grpc_exec_ctx *exec_ctx,
tsi_result result = TSI_OK;
tsi_handshaker *handshaker;
if (c->handshaker_factory == NULL) {
gpr_free(read_buffer);
cb(exec_ctx, user_data, GRPC_SECURITY_ERROR, NULL, NULL);
return;
}
@ -77,10 +79,12 @@ static void httpcli_ssl_do_handshake(grpc_exec_ctx *exec_ctx,
if (result != TSI_OK) {
gpr_log(GPR_ERROR, "Handshaker creation failed with error %s.",
tsi_result_to_string(result));
gpr_free(read_buffer);
cb(exec_ctx, user_data, GRPC_SECURITY_ERROR, NULL, NULL);
} else {
grpc_do_security_handshake(exec_ctx, handshaker, &sc->base, true,
nonsecure_endpoint, deadline, cb, user_data);
nonsecure_endpoint, read_buffer, deadline, cb,
user_data);
}
}
@ -183,7 +187,7 @@ static void ssl_handshake(grpc_exec_ctx *exec_ctx, void *arg,
pem_root_certs, pem_root_certs_size, host, &sc) ==
GRPC_SECURITY_OK);
grpc_channel_security_connector_do_handshake(
exec_ctx, sc, tcp, deadline, on_secure_transport_setup_done, c);
exec_ctx, sc, tcp, NULL, deadline, on_secure_transport_setup_done, c);
GRPC_SECURITY_CONNECTOR_UNREF(&sc->base, "httpcli");
}

@ -325,8 +325,9 @@ static void on_timeout(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
void grpc_do_security_handshake(
grpc_exec_ctx *exec_ctx, tsi_handshaker *handshaker,
grpc_security_connector *connector, bool is_client_side,
grpc_endpoint *nonsecure_endpoint, gpr_timespec deadline,
grpc_security_handshake_done_cb cb, void *user_data) {
grpc_endpoint *nonsecure_endpoint, gpr_slice_buffer *read_buffer,
gpr_timespec deadline, grpc_security_handshake_done_cb cb,
void *user_data) {
grpc_security_connector_handshake_list *handshake_node;
grpc_security_handshake *h = gpr_malloc(sizeof(grpc_security_handshake));
memset(h, 0, sizeof(grpc_security_handshake));
@ -346,6 +347,10 @@ void grpc_do_security_handshake(
gpr_slice_buffer_init(&h->left_overs);
gpr_slice_buffer_init(&h->outgoing);
gpr_slice_buffer_init(&h->incoming);
if (read_buffer != NULL) {
gpr_slice_buffer_move_into(read_buffer, &h->incoming);
gpr_free(read_buffer);
}
if (!is_client_side) {
grpc_server_security_connector *server_connector =
(grpc_server_security_connector *)connector;

@ -37,12 +37,13 @@
#include "src/core/lib/iomgr/endpoint.h"
#include "src/core/lib/security/transport/security_connector.h"
/* Calls the callback upon completion. Takes owership of handshaker. */
/* Calls the callback upon completion. Takes owership of handshaker and
* read_buffer. */
void grpc_do_security_handshake(
grpc_exec_ctx *exec_ctx, tsi_handshaker *handshaker,
grpc_security_connector *connector, bool is_client_side,
grpc_endpoint *nonsecure_endpoint, gpr_timespec deadline,
grpc_security_handshake_done_cb cb, void *user_data);
grpc_endpoint *nonsecure_endpoint, gpr_slice_buffer *read_buffer,
gpr_timespec deadline, grpc_security_handshake_done_cb cb, void *user_data);
void grpc_security_handshake_shutdown(grpc_exec_ctx *exec_ctx, void *handshake);

@ -127,25 +127,29 @@ void grpc_server_security_connector_shutdown(
void grpc_channel_security_connector_do_handshake(
grpc_exec_ctx *exec_ctx, grpc_channel_security_connector *sc,
grpc_endpoint *nonsecure_endpoint, gpr_timespec deadline,
grpc_security_handshake_done_cb cb, void *user_data) {
grpc_endpoint *nonsecure_endpoint, gpr_slice_buffer *read_buffer,
gpr_timespec deadline, grpc_security_handshake_done_cb cb,
void *user_data) {
if (sc == NULL || nonsecure_endpoint == NULL) {
gpr_free(read_buffer);
cb(exec_ctx, user_data, GRPC_SECURITY_ERROR, NULL, NULL);
} else {
sc->do_handshake(exec_ctx, sc, nonsecure_endpoint, deadline, cb, user_data);
sc->do_handshake(exec_ctx, sc, nonsecure_endpoint, read_buffer, deadline,
cb, user_data);
}
}
void grpc_server_security_connector_do_handshake(
grpc_exec_ctx *exec_ctx, grpc_server_security_connector *sc,
grpc_tcp_server_acceptor *acceptor, grpc_endpoint *nonsecure_endpoint,
gpr_timespec deadline, grpc_security_handshake_done_cb cb,
void *user_data) {
gpr_slice_buffer *read_buffer, gpr_timespec deadline,
grpc_security_handshake_done_cb cb, void *user_data) {
if (sc == NULL || nonsecure_endpoint == NULL) {
gpr_free(read_buffer);
cb(exec_ctx, user_data, GRPC_SECURITY_ERROR, NULL, NULL);
} else {
sc->do_handshake(exec_ctx, sc, acceptor, nonsecure_endpoint, deadline, cb,
user_data);
sc->do_handshake(exec_ctx, sc, acceptor, nonsecure_endpoint, read_buffer,
deadline, cb, user_data);
}
}
@ -312,23 +316,23 @@ static void fake_channel_check_call_host(grpc_exec_ctx *exec_ctx,
static void fake_channel_do_handshake(grpc_exec_ctx *exec_ctx,
grpc_channel_security_connector *sc,
grpc_endpoint *nonsecure_endpoint,
gpr_slice_buffer *read_buffer,
gpr_timespec deadline,
grpc_security_handshake_done_cb cb,
void *user_data) {
grpc_do_security_handshake(exec_ctx, tsi_create_fake_handshaker(1), &sc->base,
true, nonsecure_endpoint, deadline, cb, user_data);
true, nonsecure_endpoint, read_buffer, deadline,
cb, user_data);
}
static void fake_server_do_handshake(grpc_exec_ctx *exec_ctx,
grpc_server_security_connector *sc,
grpc_tcp_server_acceptor *acceptor,
grpc_endpoint *nonsecure_endpoint,
gpr_timespec deadline,
grpc_security_handshake_done_cb cb,
void *user_data) {
static void fake_server_do_handshake(
grpc_exec_ctx *exec_ctx, grpc_server_security_connector *sc,
grpc_tcp_server_acceptor *acceptor, grpc_endpoint *nonsecure_endpoint,
gpr_slice_buffer *read_buffer, gpr_timespec deadline,
grpc_security_handshake_done_cb cb, void *user_data) {
grpc_do_security_handshake(exec_ctx, tsi_create_fake_handshaker(0), &sc->base,
false, nonsecure_endpoint, deadline, cb,
user_data);
false, nonsecure_endpoint, read_buffer, deadline,
cb, user_data);
}
static grpc_security_connector_vtable fake_channel_vtable = {
@ -418,6 +422,7 @@ static grpc_security_status ssl_create_handshaker(
static void ssl_channel_do_handshake(grpc_exec_ctx *exec_ctx,
grpc_channel_security_connector *sc,
grpc_endpoint *nonsecure_endpoint,
gpr_slice_buffer *read_buffer,
gpr_timespec deadline,
grpc_security_handshake_done_cb cb,
void *user_data) {
@ -430,30 +435,32 @@ static void ssl_channel_do_handshake(grpc_exec_ctx *exec_ctx,
: c->target_name,
&handshaker);
if (status != GRPC_SECURITY_OK) {
gpr_free(read_buffer);
cb(exec_ctx, user_data, status, NULL, NULL);
} else {
grpc_do_security_handshake(exec_ctx, handshaker, &sc->base, true,
nonsecure_endpoint, deadline, cb, user_data);
nonsecure_endpoint, read_buffer, deadline, cb,
user_data);
}
}
static void ssl_server_do_handshake(grpc_exec_ctx *exec_ctx,
grpc_server_security_connector *sc,
grpc_tcp_server_acceptor *acceptor,
grpc_endpoint *nonsecure_endpoint,
gpr_timespec deadline,
grpc_security_handshake_done_cb cb,
void *user_data) {
static void ssl_server_do_handshake(
grpc_exec_ctx *exec_ctx, grpc_server_security_connector *sc,
grpc_tcp_server_acceptor *acceptor, grpc_endpoint *nonsecure_endpoint,
gpr_slice_buffer *read_buffer, gpr_timespec deadline,
grpc_security_handshake_done_cb cb, void *user_data) {
grpc_ssl_server_security_connector *c =
(grpc_ssl_server_security_connector *)sc;
tsi_handshaker *handshaker;
grpc_security_status status =
ssl_create_handshaker(c->handshaker_factory, false, NULL, &handshaker);
if (status != GRPC_SECURITY_OK) {
gpr_free(read_buffer);
cb(exec_ctx, user_data, status, NULL, NULL);
} else {
grpc_do_security_handshake(exec_ctx, handshaker, &sc->base, false,
nonsecure_endpoint, deadline, cb, user_data);
nonsecure_endpoint, read_buffer, deadline, cb,
user_data);
}
}

@ -143,7 +143,8 @@ struct grpc_channel_security_connector {
grpc_security_call_host_check_cb cb, void *user_data);
void (*do_handshake)(grpc_exec_ctx *exec_ctx,
grpc_channel_security_connector *sc,
grpc_endpoint *nonsecure_endpoint, gpr_timespec deadline,
grpc_endpoint *nonsecure_endpoint,
gpr_slice_buffer *read_buffer, gpr_timespec deadline,
grpc_security_handshake_done_cb cb, void *user_data);
};
@ -156,8 +157,8 @@ void grpc_channel_security_connector_check_call_host(
/* Handshake. */
void grpc_channel_security_connector_do_handshake(
grpc_exec_ctx *exec_ctx, grpc_channel_security_connector *connector,
grpc_endpoint *nonsecure_endpoint, gpr_timespec deadline,
grpc_security_handshake_done_cb cb, void *user_data);
grpc_endpoint *nonsecure_endpoint, gpr_slice_buffer *read_buffer,
gpr_timespec deadline, grpc_security_handshake_done_cb cb, void *user_data);
/* --- server_security_connector object. ---
@ -174,14 +175,16 @@ struct grpc_server_security_connector {
void (*do_handshake)(grpc_exec_ctx *exec_ctx,
grpc_server_security_connector *sc,
grpc_tcp_server_acceptor *acceptor,
grpc_endpoint *nonsecure_endpoint, gpr_timespec deadline,
grpc_endpoint *nonsecure_endpoint,
gpr_slice_buffer *read_buffer, gpr_timespec deadline,
grpc_security_handshake_done_cb cb, void *user_data);
};
void grpc_server_security_connector_do_handshake(
grpc_exec_ctx *exec_ctx, grpc_server_security_connector *sc,
grpc_tcp_server_acceptor *acceptor, grpc_endpoint *nonsecure_endpoint,
gpr_timespec deadline, grpc_security_handshake_done_cb cb, void *user_data);
gpr_slice_buffer *read_buffer, gpr_timespec deadline,
grpc_security_handshake_done_cb cb, void *user_data);
void grpc_server_security_connector_shutdown(
grpc_exec_ctx *exec_ctx, grpc_server_security_connector *connector);

@ -47,7 +47,6 @@
#include <grpc/support/log.h>
#include <grpc/support/string_util.h>
#include <grpc/support/time.h>
#include <linux/unistd.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>

@ -98,6 +98,7 @@ const ::google::protobuf::internal::GeneratedMessageReflection*
} // namespace
void protobuf_AssignDesc_reflection_2eproto() GOOGLE_ATTRIBUTE_COLD;
void protobuf_AssignDesc_reflection_2eproto() {
protobuf_AddDesc_reflection_2eproto();
const ::google::protobuf::FileDescriptor* file =
@ -253,6 +254,7 @@ inline void protobuf_AssignDescriptorsOnce() {
&protobuf_AssignDesc_reflection_2eproto);
}
void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD;
void protobuf_RegisterTypes(const ::std::string&) {
protobuf_AssignDescriptorsOnce();
::google::protobuf::MessageFactory::InternalRegisterGeneratedMessage(
@ -296,6 +298,7 @@ void protobuf_ShutdownFile_reflection_2eproto() {
delete ErrorResponse_reflection_;
}
void protobuf_AddDesc_reflection_2eproto() GOOGLE_ATTRIBUTE_COLD;
void protobuf_AddDesc_reflection_2eproto() {
static bool already_here = false;
if (already_here) return;
@ -366,16 +369,6 @@ struct StaticDescriptorInitializer_reflection_2eproto {
}
} static_descriptor_initializer_reflection_2eproto_;
namespace {
static void MergeFromFail(int line) GOOGLE_ATTRIBUTE_COLD;
static void MergeFromFail(int line) {
GOOGLE_CHECK(false) << __FILE__ << ":" << line;
}
} // namespace
// ===================================================================
#if !defined(_MSC_VER) || _MSC_VER >= 1900
@ -684,8 +677,8 @@ void ServerReflectionRequest::SerializeWithCachedSizes(
// @@protoc_insertion_point(serialize_end:grpc.reflection.v1alpha.ServerReflectionRequest)
}
::google::protobuf::uint8* ServerReflectionRequest::SerializeWithCachedSizesToArray(
::google::protobuf::uint8* target) const {
::google::protobuf::uint8* ServerReflectionRequest::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
// @@protoc_insertion_point(serialize_to_array_start:grpc.reflection.v1alpha.ServerReflectionRequest)
// optional string host = 1;
if (this->host().size() > 0) {
@ -723,8 +716,8 @@ void ServerReflectionRequest::SerializeWithCachedSizes(
// optional .grpc.reflection.v1alpha.ExtensionRequest file_containing_extension = 5;
if (has_file_containing_extension()) {
target = ::google::protobuf::internal::WireFormatLite::
WriteMessageNoVirtualToArray(
5, *message_request_.file_containing_extension_, target);
InternalWriteMessageNoVirtualToArray(
5, *message_request_.file_containing_extension_, false, target);
}
// optional string all_extension_numbers_of_type = 6;
@ -812,7 +805,9 @@ int ServerReflectionRequest::ByteSize() const {
void ServerReflectionRequest::MergeFrom(const ::google::protobuf::Message& from) {
// @@protoc_insertion_point(generalized_merge_from_start:grpc.reflection.v1alpha.ServerReflectionRequest)
if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);
if (GOOGLE_PREDICT_FALSE(&from == this)) {
::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
}
const ServerReflectionRequest* source =
::google::protobuf::internal::DynamicCastToGenerated<const ServerReflectionRequest>(
&from);
@ -827,7 +822,9 @@ void ServerReflectionRequest::MergeFrom(const ::google::protobuf::Message& from)
void ServerReflectionRequest::MergeFrom(const ServerReflectionRequest& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:grpc.reflection.v1alpha.ServerReflectionRequest)
if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);
if (GOOGLE_PREDICT_FALSE(&from == this)) {
::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
}
switch (from.message_request_case()) {
case kFileByFilename: {
set_file_by_filename(from.file_by_filename());
@ -1486,8 +1483,8 @@ void ExtensionRequest::SerializeWithCachedSizes(
// @@protoc_insertion_point(serialize_end:grpc.reflection.v1alpha.ExtensionRequest)
}
::google::protobuf::uint8* ExtensionRequest::SerializeWithCachedSizesToArray(
::google::protobuf::uint8* target) const {
::google::protobuf::uint8* ExtensionRequest::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
// @@protoc_insertion_point(serialize_to_array_start:grpc.reflection.v1alpha.ExtensionRequest)
// optional string containing_type = 1;
if (this->containing_type().size() > 0) {
@ -1535,7 +1532,9 @@ int ExtensionRequest::ByteSize() const {
void ExtensionRequest::MergeFrom(const ::google::protobuf::Message& from) {
// @@protoc_insertion_point(generalized_merge_from_start:grpc.reflection.v1alpha.ExtensionRequest)
if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);
if (GOOGLE_PREDICT_FALSE(&from == this)) {
::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
}
const ExtensionRequest* source =
::google::protobuf::internal::DynamicCastToGenerated<const ExtensionRequest>(
&from);
@ -1550,7 +1549,9 @@ void ExtensionRequest::MergeFrom(const ::google::protobuf::Message& from) {
void ExtensionRequest::MergeFrom(const ExtensionRequest& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:grpc.reflection.v1alpha.ExtensionRequest)
if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);
if (GOOGLE_PREDICT_FALSE(&from == this)) {
::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
}
if (from.containing_type().size() > 0) {
containing_type_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.containing_type_);
@ -1937,8 +1938,8 @@ void ServerReflectionResponse::SerializeWithCachedSizes(
// @@protoc_insertion_point(serialize_end:grpc.reflection.v1alpha.ServerReflectionResponse)
}
::google::protobuf::uint8* ServerReflectionResponse::SerializeWithCachedSizesToArray(
::google::protobuf::uint8* target) const {
::google::protobuf::uint8* ServerReflectionResponse::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
// @@protoc_insertion_point(serialize_to_array_start:grpc.reflection.v1alpha.ServerReflectionResponse)
// optional string valid_host = 1;
if (this->valid_host().size() > 0) {
@ -1954,36 +1955,36 @@ void ServerReflectionResponse::SerializeWithCachedSizes(
// optional .grpc.reflection.v1alpha.ServerReflectionRequest original_request = 2;
if (this->has_original_request()) {
target = ::google::protobuf::internal::WireFormatLite::
WriteMessageNoVirtualToArray(
2, *this->original_request_, target);
InternalWriteMessageNoVirtualToArray(
2, *this->original_request_, false, target);
}
// optional .grpc.reflection.v1alpha.FileDescriptorResponse file_descriptor_response = 4;
if (has_file_descriptor_response()) {
target = ::google::protobuf::internal::WireFormatLite::
WriteMessageNoVirtualToArray(
4, *message_response_.file_descriptor_response_, target);
InternalWriteMessageNoVirtualToArray(
4, *message_response_.file_descriptor_response_, false, target);
}
// optional .grpc.reflection.v1alpha.ExtensionNumberResponse all_extension_numbers_response = 5;
if (has_all_extension_numbers_response()) {
target = ::google::protobuf::internal::WireFormatLite::
WriteMessageNoVirtualToArray(
5, *message_response_.all_extension_numbers_response_, target);
InternalWriteMessageNoVirtualToArray(
5, *message_response_.all_extension_numbers_response_, false, target);
}
// optional .grpc.reflection.v1alpha.ListServiceResponse list_services_response = 6;
if (has_list_services_response()) {
target = ::google::protobuf::internal::WireFormatLite::
WriteMessageNoVirtualToArray(
6, *message_response_.list_services_response_, target);
InternalWriteMessageNoVirtualToArray(
6, *message_response_.list_services_response_, false, target);
}
// optional .grpc.reflection.v1alpha.ErrorResponse error_response = 7;
if (has_error_response()) {
target = ::google::protobuf::internal::WireFormatLite::
WriteMessageNoVirtualToArray(
7, *message_response_.error_response_, target);
InternalWriteMessageNoVirtualToArray(
7, *message_response_.error_response_, false, target);
}
// @@protoc_insertion_point(serialize_to_array_end:grpc.reflection.v1alpha.ServerReflectionResponse)
@ -2049,7 +2050,9 @@ int ServerReflectionResponse::ByteSize() const {
void ServerReflectionResponse::MergeFrom(const ::google::protobuf::Message& from) {
// @@protoc_insertion_point(generalized_merge_from_start:grpc.reflection.v1alpha.ServerReflectionResponse)
if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);
if (GOOGLE_PREDICT_FALSE(&from == this)) {
::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
}
const ServerReflectionResponse* source =
::google::protobuf::internal::DynamicCastToGenerated<const ServerReflectionResponse>(
&from);
@ -2064,7 +2067,9 @@ void ServerReflectionResponse::MergeFrom(const ::google::protobuf::Message& from
void ServerReflectionResponse::MergeFrom(const ServerReflectionResponse& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:grpc.reflection.v1alpha.ServerReflectionResponse)
if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);
if (GOOGLE_PREDICT_FALSE(&from == this)) {
::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
}
switch (from.message_response_case()) {
case kFileDescriptorResponse: {
mutable_file_descriptor_response()->::grpc::reflection::v1alpha::FileDescriptorResponse::MergeFrom(from.file_descriptor_response());
@ -2550,8 +2555,8 @@ void FileDescriptorResponse::SerializeWithCachedSizes(
// @@protoc_insertion_point(serialize_end:grpc.reflection.v1alpha.FileDescriptorResponse)
}
::google::protobuf::uint8* FileDescriptorResponse::SerializeWithCachedSizesToArray(
::google::protobuf::uint8* target) const {
::google::protobuf::uint8* FileDescriptorResponse::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
// @@protoc_insertion_point(serialize_to_array_start:grpc.reflection.v1alpha.FileDescriptorResponse)
// repeated bytes file_descriptor_proto = 1;
for (int i = 0; i < this->file_descriptor_proto_size(); i++) {
@ -2582,7 +2587,9 @@ int FileDescriptorResponse::ByteSize() const {
void FileDescriptorResponse::MergeFrom(const ::google::protobuf::Message& from) {
// @@protoc_insertion_point(generalized_merge_from_start:grpc.reflection.v1alpha.FileDescriptorResponse)
if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);
if (GOOGLE_PREDICT_FALSE(&from == this)) {
::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
}
const FileDescriptorResponse* source =
::google::protobuf::internal::DynamicCastToGenerated<const FileDescriptorResponse>(
&from);
@ -2597,7 +2604,9 @@ void FileDescriptorResponse::MergeFrom(const ::google::protobuf::Message& from)
void FileDescriptorResponse::MergeFrom(const FileDescriptorResponse& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:grpc.reflection.v1alpha.FileDescriptorResponse)
if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);
if (GOOGLE_PREDICT_FALSE(&from == this)) {
::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
}
file_descriptor_proto_.MergeFrom(from.file_descriptor_proto_);
}
@ -2863,8 +2872,8 @@ void ExtensionNumberResponse::SerializeWithCachedSizes(
// @@protoc_insertion_point(serialize_end:grpc.reflection.v1alpha.ExtensionNumberResponse)
}
::google::protobuf::uint8* ExtensionNumberResponse::SerializeWithCachedSizesToArray(
::google::protobuf::uint8* target) const {
::google::protobuf::uint8* ExtensionNumberResponse::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
// @@protoc_insertion_point(serialize_to_array_start:grpc.reflection.v1alpha.ExtensionNumberResponse)
// optional string base_type_name = 1;
if (this->base_type_name().size() > 0) {
@ -2931,7 +2940,9 @@ int ExtensionNumberResponse::ByteSize() const {
void ExtensionNumberResponse::MergeFrom(const ::google::protobuf::Message& from) {
// @@protoc_insertion_point(generalized_merge_from_start:grpc.reflection.v1alpha.ExtensionNumberResponse)
if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);
if (GOOGLE_PREDICT_FALSE(&from == this)) {
::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
}
const ExtensionNumberResponse* source =
::google::protobuf::internal::DynamicCastToGenerated<const ExtensionNumberResponse>(
&from);
@ -2946,7 +2957,9 @@ void ExtensionNumberResponse::MergeFrom(const ::google::protobuf::Message& from)
void ExtensionNumberResponse::MergeFrom(const ExtensionNumberResponse& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:grpc.reflection.v1alpha.ExtensionNumberResponse)
if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);
if (GOOGLE_PREDICT_FALSE(&from == this)) {
::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
}
extension_number_.MergeFrom(from.extension_number_);
if (from.base_type_name().size() > 0) {
@ -3199,14 +3212,14 @@ void ListServiceResponse::SerializeWithCachedSizes(
// @@protoc_insertion_point(serialize_end:grpc.reflection.v1alpha.ListServiceResponse)
}
::google::protobuf::uint8* ListServiceResponse::SerializeWithCachedSizesToArray(
::google::protobuf::uint8* target) const {
::google::protobuf::uint8* ListServiceResponse::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
// @@protoc_insertion_point(serialize_to_array_start:grpc.reflection.v1alpha.ListServiceResponse)
// repeated .grpc.reflection.v1alpha.ServiceResponse service = 1;
for (unsigned int i = 0, n = this->service_size(); i < n; i++) {
target = ::google::protobuf::internal::WireFormatLite::
WriteMessageNoVirtualToArray(
1, this->service(i), target);
InternalWriteMessageNoVirtualToArray(
1, this->service(i), false, target);
}
// @@protoc_insertion_point(serialize_to_array_end:grpc.reflection.v1alpha.ListServiceResponse)
@ -3233,7 +3246,9 @@ int ListServiceResponse::ByteSize() const {
void ListServiceResponse::MergeFrom(const ::google::protobuf::Message& from) {
// @@protoc_insertion_point(generalized_merge_from_start:grpc.reflection.v1alpha.ListServiceResponse)
if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);
if (GOOGLE_PREDICT_FALSE(&from == this)) {
::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
}
const ListServiceResponse* source =
::google::protobuf::internal::DynamicCastToGenerated<const ListServiceResponse>(
&from);
@ -3248,7 +3263,9 @@ void ListServiceResponse::MergeFrom(const ::google::protobuf::Message& from) {
void ListServiceResponse::MergeFrom(const ListServiceResponse& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:grpc.reflection.v1alpha.ListServiceResponse)
if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);
if (GOOGLE_PREDICT_FALSE(&from == this)) {
::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
}
service_.MergeFrom(from.service_);
}
@ -3459,8 +3476,8 @@ void ServiceResponse::SerializeWithCachedSizes(
// @@protoc_insertion_point(serialize_end:grpc.reflection.v1alpha.ServiceResponse)
}
::google::protobuf::uint8* ServiceResponse::SerializeWithCachedSizesToArray(
::google::protobuf::uint8* target) const {
::google::protobuf::uint8* ServiceResponse::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
// @@protoc_insertion_point(serialize_to_array_start:grpc.reflection.v1alpha.ServiceResponse)
// optional string name = 1;
if (this->name().size() > 0) {
@ -3496,7 +3513,9 @@ int ServiceResponse::ByteSize() const {
void ServiceResponse::MergeFrom(const ::google::protobuf::Message& from) {
// @@protoc_insertion_point(generalized_merge_from_start:grpc.reflection.v1alpha.ServiceResponse)
if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);
if (GOOGLE_PREDICT_FALSE(&from == this)) {
::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
}
const ServiceResponse* source =
::google::protobuf::internal::DynamicCastToGenerated<const ServiceResponse>(
&from);
@ -3511,7 +3530,9 @@ void ServiceResponse::MergeFrom(const ::google::protobuf::Message& from) {
void ServiceResponse::MergeFrom(const ServiceResponse& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:grpc.reflection.v1alpha.ServiceResponse)
if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);
if (GOOGLE_PREDICT_FALSE(&from == this)) {
::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
}
if (from.name().size() > 0) {
name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.name_);
@ -3762,8 +3783,8 @@ void ErrorResponse::SerializeWithCachedSizes(
// @@protoc_insertion_point(serialize_end:grpc.reflection.v1alpha.ErrorResponse)
}
::google::protobuf::uint8* ErrorResponse::SerializeWithCachedSizesToArray(
::google::protobuf::uint8* target) const {
::google::protobuf::uint8* ErrorResponse::InternalSerializeWithCachedSizesToArray(
bool deterministic, ::google::protobuf::uint8* target) const {
// @@protoc_insertion_point(serialize_to_array_start:grpc.reflection.v1alpha.ErrorResponse)
// optional int32 error_code = 1;
if (this->error_code() != 0) {
@ -3811,7 +3832,9 @@ int ErrorResponse::ByteSize() const {
void ErrorResponse::MergeFrom(const ::google::protobuf::Message& from) {
// @@protoc_insertion_point(generalized_merge_from_start:grpc.reflection.v1alpha.ErrorResponse)
if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);
if (GOOGLE_PREDICT_FALSE(&from == this)) {
::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
}
const ErrorResponse* source =
::google::protobuf::internal::DynamicCastToGenerated<const ErrorResponse>(
&from);
@ -3826,7 +3849,9 @@ void ErrorResponse::MergeFrom(const ::google::protobuf::Message& from) {
void ErrorResponse::MergeFrom(const ErrorResponse& from) {
// @@protoc_insertion_point(class_specific_merge_from_start:grpc.reflection.v1alpha.ErrorResponse)
if (GOOGLE_PREDICT_FALSE(&from == this)) MergeFromFail(__LINE__);
if (GOOGLE_PREDICT_FALSE(&from == this)) {
::google::protobuf::internal::MergeFromFail(__FILE__, __LINE__);
}
if (from.error_code() != 0) {
set_error_code(from.error_code());
}

@ -40,7 +40,7 @@
<HintPath>..\packages\NUnit.3.2.0\lib\net45\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System.Interactive.Async">
<HintPath>..\packages\Ix-Async.1.2.5\lib\net45\System.Interactive.Async.dll</HintPath>
<HintPath>..\packages\System.Interactive.Async.3.0.0\lib\net45\System.Interactive.Async.dll</HintPath>
</Reference>
<Reference Include="nunitlite">
<HintPath>..\packages\NUnitLite.3.2.0\lib\net45\nunitlite.dll</HintPath>
@ -108,4 +108,4 @@
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup />
</Project>
</Project>

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Ix-Async" version="1.2.5" targetFramework="net45" />
<package id="System.Interactive.Async" version="3.0.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
<package id="NUnit" version="3.2.0" targetFramework="net45" />
<package id="NUnitLite" version="3.2.0" targetFramework="net45" />

@ -40,7 +40,7 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Interactive.Async">
<HintPath>..\packages\Ix-Async.1.2.5\lib\net45\System.Interactive.Async.dll</HintPath>
<HintPath>..\packages\System.Interactive.Async.3.0.0\lib\net45\System.Interactive.Async.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
@ -152,4 +152,4 @@
<Link>roots.pem</Link>
</EmbeddedResource>
</ItemGroup>
</Project>
</Project>

@ -15,7 +15,7 @@
<copyright>Copyright 2015, Google Inc.</copyright>
<tags>gRPC RPC Protocol HTTP/2</tags>
<dependencies>
<dependency id="Ix-Async" version="1.2.5" />
<dependency id="System.Interactive.Async" version="3.0.0" />
</dependencies>
</metadata>
<files>

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Ix-Async" version="1.2.5" targetFramework="net45" />
<package id="System.Interactive.Async" version="3.0.0" targetFramework="net45" />
</packages>

@ -31,7 +31,7 @@
"xmlDoc": true
},
"dependencies": {
"Ix-Async": "1.2.5"
"System.Interactive.Async": "3.0.0"
},
"frameworks": {
"net45": { },

@ -42,11 +42,6 @@
}
}
},
"runtimes": {
"win7-x64": { },
"debian.8-x64": { },
"osx.10.11-x64": { }
},
"dependencies": {
"Grpc.Examples": {

@ -42,11 +42,6 @@
}
}
},
"runtimes": {
"win7-x64": { },
"debian.8-x64": { },
"osx.10.11-x64": { }
},
"dependencies": {
"Grpc.Examples": {

@ -43,7 +43,7 @@
<HintPath>..\packages\NUnit.3.2.0\lib\net45\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System.Interactive.Async">
<HintPath>..\packages\Ix-Async.1.2.5\lib\net45\System.Interactive.Async.dll</HintPath>
<HintPath>..\packages\System.Interactive.Async.3.0.0\lib\net45\System.Interactive.Async.dll</HintPath>
</Reference>
<Reference Include="nunitlite">
<HintPath>..\packages\NUnitLite.3.2.0\lib\net45\nunitlite.dll</HintPath>
@ -75,4 +75,4 @@
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
</Project>
</Project>

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Google.Protobuf" version="3.0.0-beta3" targetFramework="net45" />
<package id="Ix-Async" version="1.2.5" targetFramework="net45" />
<package id="System.Interactive.Async" version="3.0.0" targetFramework="net45" />
<package id="NUnit" version="3.2.0" targetFramework="net45" />
<package id="NUnitLite" version="3.2.0" targetFramework="net45" />
</packages>

@ -48,7 +48,7 @@
<Reference Include="System.Data.Linq" />
<Reference Include="System.Interactive.Async, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Ix-Async.1.2.5\lib\net45\System.Interactive.Async.dll</HintPath>
<HintPath>..\packages\System.Interactive.Async.3.0.0\lib\net45\System.Interactive.Async.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
@ -72,4 +72,4 @@
<None Include="Grpc.Examples.project.json" />
<None Include="packages.config" />
</ItemGroup>
</Project>
</Project>

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Google.Protobuf" version="3.0.0-beta3" targetFramework="net45" />
<package id="Ix-Async" version="1.2.5" targetFramework="net45" />
<package id="System.Interactive.Async" version="3.0.0" targetFramework="net45" />
<package id="NUnit" version="3.2.0" targetFramework="net45" />
</packages>

@ -1,6 +1,11 @@
{
"buildOptions": {
},
"runtimes": {
"win7-x64": { },
"debian.8-x64": { },
"osx.10.11-x64": { }
},
"dependencies": {
"Grpc.Core": {

@ -46,7 +46,7 @@
<Reference Include="System.Core" />
<Reference Include="System.Interactive.Async, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Ix-Async.1.2.5\lib\net45\System.Interactive.Async.dll</HintPath>
<HintPath>..\packages\System.Interactive.Async.3.0.0\lib\net45\System.Interactive.Async.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
@ -82,4 +82,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>

@ -16,7 +16,7 @@
<dependencies>
<dependency id="Google.Protobuf" version="$ProtobufVersion$" />
<dependency id="Grpc.Core" version="$version$" />
<dependency id="Ix-Async" version="1.2.3" />
<dependency id="System.Interactive.Async" version="3.0.0" />
</dependencies>
</metadata>
<files>

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Google.Protobuf" version="3.0.0-beta3" targetFramework="net45" />
<package id="Ix-Async" version="1.2.5" targetFramework="net45" />
<package id="System.Interactive.Async" version="3.0.0" targetFramework="net45" />
</packages>

@ -44,11 +44,6 @@
}
}
},
"runtimes": {
"win7-x64": { },
"debian.8-x64": { },
"osx.10.11-x64": { }
},
"dependencies": {
"Grpc.IntegrationTesting": {

@ -44,11 +44,6 @@
}
}
},
"runtimes": {
"win7-x64": { },
"debian.8-x64": { },
"osx.10.11-x64": { }
},
"dependencies": {
"Grpc.IntegrationTesting": {

@ -70,7 +70,7 @@
<HintPath>..\packages\NUnit.3.2.0\lib\net45\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System.Interactive.Async">
<HintPath>..\packages\Ix-Async.1.2.5\lib\net45\System.Interactive.Async.dll</HintPath>
<HintPath>..\packages\System.Interactive.Async.3.0.0\lib\net45\System.Interactive.Async.dll</HintPath>
</Reference>
<Reference Include="nunitlite">
<HintPath>..\packages\NUnitLite.3.2.0\lib\net45\nunitlite.dll</HintPath>
@ -149,4 +149,4 @@
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
</Project>
</Project>

@ -5,7 +5,7 @@
<package id="Google.Apis.Auth" version="1.11.1" targetFramework="net45" />
<package id="Google.Apis.Core" version="1.11.1" targetFramework="net45" />
<package id="Google.Protobuf" version="3.0.0-beta3" targetFramework="net45" />
<package id="Ix-Async" version="1.2.5" targetFramework="net45" />
<package id="System.Interactive.Async" version="3.0.0" targetFramework="net45" />
<package id="Moq" version="4.2.1510.2205" targetFramework="net45" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
<package id="NUnit" version="3.2.0" targetFramework="net45" />

@ -71,6 +71,8 @@ var Metadata = require('./metadata.js');
var common = require('./common.js');
var _ = require('lodash');
/**
* Create an SSL Credentials object. If using a client-side certificate, both
* the second and third arguments must be passed.
@ -99,7 +101,7 @@ exports.createFromMetadataGenerator = function(metadata_generator) {
var message = '';
if (error) {
message = error.message;
if (error.hasOwnProperty('code')) {
if (error.hasOwnProperty('code') && _.isFinite(error.code)) {
code = error.code;
} else {
code = grpc.status.UNAUTHENTICATED;

@ -71,7 +71,10 @@ var fakeSuccessfulGoogleCredentials = {
var fakeFailingGoogleCredentials = {
getRequestMetadata: function(service_url, callback) {
setTimeout(function() {
callback(new Error('Authentication failure'));
// Google credentials currently adds string error codes to auth errors
var error = new Error('Authentication failure');
error.code = 'ENOENT';
callback(error);
}, 0);
}
};

@ -37,7 +37,7 @@ Pod::Spec.new do |s|
# before them.
s.name = '!ProtoCompiler-gRPCPlugin'
v = '1.0.0-pre1'
s.version = v
s.version = "#{v}.2" # .2 to depend on protoc 3.0.0
s.summary = 'The gRPC ProtoC plugin generates Objective-C files from .proto services.'
s.description = <<-DESC
This podspec only downloads the gRPC protoc plugin so that local pods generating protos can use
@ -96,7 +96,7 @@ Pod::Spec.new do |s|
s.preserve_paths = plugin
# Restrict the protoc version to the one supported by this plugin.
s.dependency '!ProtoCompiler', '3.0.0-beta-3.1'
s.dependency '!ProtoCompiler', '3.0.0'
# For the Protobuf dependency not to complain:
s.ios.deployment_target = '7.1'
s.osx.deployment_target = '10.9'

@ -36,7 +36,7 @@ Pod::Spec.new do |s|
# exclamation mark ensures that other "regular" pods will be able to find it as it'll be installed
# before them.
s.name = '!ProtoCompiler'
v = '3.0.0-beta-3.1'
v = '3.0.0'
s.version = v
s.summary = 'The Protobuf Compiler (protoc) generates Objective-C files from .proto files'
s.description = <<-DESC
@ -108,7 +108,7 @@ Pod::Spec.new do |s|
'google/**/*.proto' # Well-known protobuf types
# Restrict the protobuf runtime version to the one supported by this version of protoc.
s.dependency 'Protobuf', v
s.dependency 'Protobuf', '~> 3.0'
# For the Protobuf dependency not to complain:
s.ios.deployment_target = '7.1'
s.osx.deployment_target = '10.9'
@ -120,7 +120,7 @@ Pod::Spec.new do |s|
repo_root = '../..'
plugin = 'grpc_objective_c_plugin'
s.prepare_command = <<-CMD
if [ ! -f protoc ]; then
if [ ! -f bin/protoc ]; then
cd #{repo_root}
# This will build protoc from the Protobuf submodule of gRPC, and put it in
# #{repo_root}/bins/opt/protobuf.
@ -129,7 +129,9 @@ Pod::Spec.new do |s|
# _we do not want_. Find a way for this to always build from source.
make #{plugin}
cd -
else
mv bin/protoc .
mv include/google .
fi
CMD
end

@ -48,7 +48,7 @@ Pod::Spec.new do |s|
src = '.'
# We'll use protoc with the gRPC plugin.
s.dependency '!ProtoCompiler-gRPCPlugin', '~> 1.0.0-pre1'
s.dependency '!ProtoCompiler-gRPCPlugin', '~> 1.0.0-pre1.2'
# Pods directory corresponding to this app's Podfile, relative to the location of this podspec.
pods_root = '<path to your Podfile>/Pods'

@ -11,7 +11,7 @@ Pod::Spec.new do |s|
s.osx.deployment_target = '10.9'
# Run protoc with the Objective-C and gRPC plugins to generate protocol messages and gRPC clients.
s.dependency "!ProtoCompiler-gRPCPlugin", "~> 1.0.0-pre1"
s.dependency "!ProtoCompiler-gRPCPlugin", "~> 1.0.0-pre1.2"
repo_root = '../../../..'
bin_dir = "#{repo_root}/bins/$CONFIG"

@ -91,7 +91,7 @@ class ViewController: UIViewController {
call.startWithWriteable(GRXWriteable { response, error in
if let response = response as? NSData {
NSLog("3. Received response:\n\(RMTSimpleResponse(data: response, error: nil))")
NSLog("3. Received response:\n\(try! RMTSimpleResponse(data: response))")
} else {
NSLog("3. Finished with error: \(error!)")
}

@ -11,7 +11,7 @@ Pod::Spec.new do |s|
s.osx.deployment_target = '10.9'
# Run protoc with the Objective-C and gRPC plugins to generate protocol messages and gRPC clients.
s.dependency "!ProtoCompiler-gRPCPlugin", "~> 1.0.0-pre1"
s.dependency "!ProtoCompiler-gRPCPlugin", "~> 1.0.0-pre1.2"
repo_root = '../../../..'
bin_dir = "#{repo_root}/bins/$CONFIG"

@ -34,6 +34,7 @@ cdef class Call:
def __cinit__(self):
# Create an *empty* call
grpc_init()
self.c_call = NULL
self.references = []
@ -106,6 +107,7 @@ cdef class Call:
def __dealloc__(self):
if self.c_call != NULL:
grpc_call_destroy(self.c_call)
grpc_shutdown()
# The object *should* always be valid from Python. Used for debugging.
@property

@ -34,6 +34,7 @@ cdef class Channel:
def __cinit__(self, bytes target, ChannelArgs arguments=None,
ChannelCredentials channel_credentials=None):
grpc_init()
cdef grpc_channel_args *c_arguments = NULL
cdef char *c_target = NULL
self.c_channel = NULL
@ -103,3 +104,4 @@ cdef class Channel:
def __dealloc__(self):
if self.c_channel != NULL:
grpc_channel_destroy(self.c_channel)
grpc_shutdown()

@ -38,6 +38,7 @@ cdef int _INTERRUPT_CHECK_PERIOD_MS = 200
cdef class CompletionQueue:
def __cinit__(self):
grpc_init()
with nogil:
self.c_completion_queue = grpc_completion_queue_create(NULL)
self.is_shutting_down = False
@ -129,3 +130,4 @@ cdef class CompletionQueue:
self.c_completion_queue, c_deadline, NULL)
self._interpret_event(event)
grpc_completion_queue_destroy(self.c_completion_queue)
grpc_shutdown()

@ -33,6 +33,7 @@ cimport cpython
cdef class ChannelCredentials:
def __cinit__(self):
grpc_init()
self.c_credentials = NULL
self.c_ssl_pem_key_cert_pair.private_key = NULL
self.c_ssl_pem_key_cert_pair.certificate_chain = NULL
@ -47,11 +48,13 @@ cdef class ChannelCredentials:
def __dealloc__(self):
if self.c_credentials != NULL:
grpc_channel_credentials_release(self.c_credentials)
grpc_shutdown()
cdef class CallCredentials:
def __cinit__(self):
grpc_init()
self.c_credentials = NULL
self.references = []
@ -64,17 +67,20 @@ cdef class CallCredentials:
def __dealloc__(self):
if self.c_credentials != NULL:
grpc_call_credentials_release(self.c_credentials)
grpc_shutdown()
cdef class ServerCredentials:
def __cinit__(self):
grpc_init()
self.c_credentials = NULL
self.references = []
def __dealloc__(self):
if self.c_credentials != NULL:
grpc_server_credentials_release(self.c_credentials)
grpc_shutdown()
cdef class CredentialsMetadataPlugin:
@ -90,6 +96,7 @@ cdef class CredentialsMetadataPlugin:
successful).
name (bytes): Plugin name.
"""
grpc_init()
if not callable(plugin_callback):
raise ValueError('expected callable plugin_callback')
self.plugin_callback = plugin_callback
@ -105,10 +112,14 @@ cdef class CredentialsMetadataPlugin:
cpython.Py_INCREF(self)
return result
def __dealloc__(self):
grpc_shutdown()
cdef class AuthMetadataContext:
def __cinit__(self):
grpc_init()
self.context.service_url = NULL
self.context.method_name = NULL
@ -120,6 +131,9 @@ cdef class AuthMetadataContext:
def method_name(self):
return self.context.method_name
def __dealloc__(self):
grpc_shutdown()
cdef void plugin_get_metadata(
void *state, grpc_auth_metadata_context context,

@ -176,12 +176,14 @@ cdef class Timespec:
cdef class CallDetails:
def __cinit__(self):
grpc_init()
with nogil:
grpc_call_details_init(&self.c_details)
def __dealloc__(self):
with nogil:
grpc_call_details_destroy(&self.c_details)
grpc_shutdown()
@property
def method(self):
@ -232,6 +234,7 @@ cdef class Event:
cdef class ByteBuffer:
def __cinit__(self, bytes data):
grpc_init()
if data is None:
self.c_byte_buffer = NULL
return
@ -288,6 +291,7 @@ cdef class ByteBuffer:
def __dealloc__(self):
if self.c_byte_buffer != NULL:
grpc_byte_buffer_destroy(self.c_byte_buffer)
grpc_shutdown()
cdef class SslPemKeyCertPair:
@ -319,6 +323,7 @@ cdef class ChannelArg:
cdef class ChannelArgs:
def __cinit__(self, args):
grpc_init()
self.args = list(args)
for arg in self.args:
if not isinstance(arg, ChannelArg):
@ -333,6 +338,7 @@ cdef class ChannelArgs:
def __dealloc__(self):
with nogil:
gpr_free(self.c_args.arguments)
grpc_shutdown()
def __len__(self):
# self.args is never stale; it's only updated from this file
@ -399,6 +405,7 @@ cdef class _MetadataIterator:
cdef class Metadata:
def __cinit__(self, metadata):
grpc_init()
self.metadata = list(metadata)
for metadatum in metadata:
if not isinstance(metadatum, Metadatum):
@ -420,6 +427,7 @@ cdef class Metadata:
# it'd be nice if that were documented somewhere...)
# TODO(atash): document this in the C core
grpc_metadata_array_destroy(&self.c_metadata_array)
grpc_shutdown()
def __len__(self):
return self.c_metadata_array.count
@ -437,6 +445,7 @@ cdef class Metadata:
cdef class Operation:
def __cinit__(self):
grpc_init()
self.references = []
self._received_status_details = NULL
self._received_status_details_capacity = 0
@ -529,6 +538,7 @@ cdef class Operation:
# This means that we need to clean up after receive_status_on_client.
if self.c_op.type == GRPC_OP_RECV_STATUS_ON_CLIENT:
gpr_free(self._received_status_details)
grpc_shutdown()
def operation_send_initial_metadata(Metadata metadata, int flags):
cdef Operation op = Operation()
@ -645,6 +655,7 @@ cdef class _OperationsIterator:
cdef class Operations:
def __cinit__(self, operations):
grpc_init()
self.operations = list(operations) # normalize iterable
self.c_ops = NULL
self.c_nops = 0
@ -667,6 +678,7 @@ cdef class Operations:
def __dealloc__(self):
with nogil:
gpr_free(self.c_ops)
grpc_shutdown()
def __iter__(self):
return _OperationsIterator(self)

@ -35,6 +35,7 @@ import time
cdef class Server:
def __cinit__(self, ChannelArgs arguments=None):
grpc_init()
cdef grpc_channel_args *c_arguments = NULL
self.references = []
self.registered_completion_queues = []
@ -172,3 +173,4 @@ cdef class Server:
while not self.is_shutdown:
time.sleep(0)
grpc_server_destroy(self.c_server)
grpc_shutdown()

@ -55,12 +55,8 @@ cdef extern from "Python.h":
def _initialize():
grpc_init()
grpc_set_ssl_roots_override_callback(
<grpc_ssl_roots_override_callback>ssl_roots_override_callback)
if Py_AtExit(grpc_shutdown) != 0:
raise ImportError('failed to register gRPC library shutdown callbacks')
_initialize()

@ -50,6 +50,7 @@ SETUP_REQUIRES = (
)
INSTALL_REQUIRES = (
'protobuf>=3.0.0',
'grpcio>=0.15.0',
)

@ -63,7 +63,7 @@ INSTALL_REQUIRES = (
'grpcio>=0.14.0',
'grpcio-health-checking>=0.14.0',
'oauth2client>=1.4.7',
'protobuf>=3.0.0a3',
'protobuf>=3.0.0',
'six>=1.10',
)

@ -30,6 +30,7 @@
import time
import threading
import unittest
import platform
from grpc._cython import cygrpc
from tests.unit._cython import test_utilities
@ -113,6 +114,9 @@ class TypeSmokeTest(unittest.TestCase):
lambda ignored_a, ignored_b: None, b'')
del plugin
@unittest.skipIf(
platform.python_implementation() == "PyPy",
'TODO(issue 7672): figure out why this fails on PyPy')
def testCallCredentialsFromPluginUpDown(self):
plugin = cygrpc.CredentialsMetadataPlugin(_metadata_plugin_callback, b'')
call_credentials = cygrpc.call_credentials_metadata_plugin(plugin)

@ -58,7 +58,7 @@ module GRPC
include Core::TimeConsts
include Core::CallOps
extend Forwardable
attr_reader(:deadline)
attr_reader :deadline, :metadata_sent, :metadata_to_send
def_delegators :@call, :cancel, :metadata, :write_flag, :write_flag=,
:peer, :peer_cert, :trailing_metadata
@ -101,7 +101,7 @@ module GRPC
# @param metadata_received [true|false] indicates if metadata has already
# been received. Should always be true for server calls
def initialize(call, marshal, unmarshal, deadline, started: true,
metadata_received: false)
metadata_received: false, metadata_to_send: nil)
fail(TypeError, '!Core::Call') unless call.is_a? Core::Call
@call = call
@deadline = deadline
@ -110,6 +110,20 @@ module GRPC
@metadata_received = metadata_received
@metadata_sent = started
@op_notifier = nil
fail(ArgumentError, 'Already sent md') if started && metadata_to_send
@metadata_to_send = metadata_to_send || {} unless started
@send_initial_md_mutex = Mutex.new
end
# Sends the initial metadata that has yet to be sent.
# Does nothing if metadata has already been sent for this call.
def send_initial_metadata
@send_initial_md_mutex.synchronize do
return if @metadata_sent
@metadata_tag = ActiveCall.client_invoke(@call, @metadata_to_send)
@metadata_sent = true
end
end
# output_metadata are provides access to hash that can be used to
@ -187,7 +201,7 @@ module GRPC
# @param marshalled [false, true] indicates if the object is already
# marshalled.
def remote_send(req, marshalled = false)
# TODO(murgatroid99): ensure metadata was sent
send_initial_metadata
GRPC.logger.debug("sending #{req}, marshalled? #{marshalled}")
payload = marshalled ? req : @marshal.call(req)
@call.run_batch(SEND_MESSAGE => payload)
@ -203,6 +217,7 @@ module GRPC
# list, mulitple metadata for its key are sent
def send_status(code = OK, details = '', assert_finished = false,
metadata: {})
send_initial_metadata
ops = {
SEND_STATUS_FROM_SERVER => Struct::Status.new(code, details, metadata)
}
@ -303,7 +318,7 @@ module GRPC
# a list, multiple metadata for its key are sent
# @return [Object] the response received from the server
def request_response(req, metadata: {})
start_call(metadata)
merge_metadata_to_send(metadata) && send_initial_metadata
remote_send(req)
writes_done(false)
response = remote_read
@ -327,7 +342,7 @@ module GRPC
# a list, multiple metadata for its key are sent
# @return [Object] the response received from the server
def client_streamer(requests, metadata: {})
start_call(metadata)
merge_metadata_to_send(metadata) && send_initial_metadata
requests.each { |r| remote_send(r) }
writes_done(false)
response = remote_read
@ -353,7 +368,7 @@ module GRPC
# a list, multiple metadata for its key are sent
# @return [Enumerator|nil] a response Enumerator
def server_streamer(req, metadata: {})
start_call(metadata)
merge_metadata_to_send(metadata) && send_initial_metadata
remote_send(req)
writes_done(false)
replies = enum_for(:each_remote_read_then_finish)
@ -392,9 +407,12 @@ module GRPC
# a list, multiple metadata for its key are sent
# @return [Enumerator, nil] a response Enumerator
def bidi_streamer(requests, metadata: {}, &blk)
start_call(metadata)
bd = BidiCall.new(@call, @marshal, @unmarshal,
merge_metadata_to_send(metadata) && send_initial_metadata
bd = BidiCall.new(@call,
@marshal,
@unmarshal,
metadata_received: @metadata_received)
bd.run_on_client(requests, @op_notifier, &blk)
end
@ -410,8 +428,12 @@ module GRPC
#
# @param gen_each_reply [Proc] generates the BiDi stream replies
def run_server_bidi(gen_each_reply)
bd = BidiCall.new(@call, @marshal, @unmarshal,
metadata_received: @metadata_received)
bd = BidiCall.new(@call,
@marshal,
@unmarshal,
metadata_received: @metadata_received,
req_view: MultiReqView.new(self))
bd.run_on_server(gen_each_reply)
end
@ -428,15 +450,23 @@ module GRPC
@op_notifier.notify(self)
end
# Add to the metadata that will be sent from the server.
# Fails if metadata has already been sent.
# Unused by client calls.
def merge_metadata_to_send(new_metadata = {})
@send_initial_md_mutex.synchronize do
fail('cant change metadata after already sent') if @metadata_sent
@metadata_to_send.merge!(new_metadata)
end
end
private
# Starts the call if not already started
# @param metadata [Hash] metadata to be sent to the server. If a value is
# a list, multiple metadata for its key are sent
def start_call(metadata = {})
return if @metadata_sent
@metadata_tag = ActiveCall.client_invoke(@call, metadata)
@metadata_sent = true
merge_metadata_to_send(metadata) && send_initial_metadata
end
def self.view_class(*visible_methods)
@ -454,12 +484,20 @@ module GRPC
# SingleReqView limits access to an ActiveCall's methods for use in server
# handlers that receive just one request.
SingleReqView = view_class(:cancelled?, :deadline, :metadata,
:output_metadata, :peer, :peer_cert)
:output_metadata, :peer, :peer_cert,
:send_initial_metadata,
:metadata_to_send,
:merge_metadata_to_send,
:metadata_sent)
# MultiReqView limits access to an ActiveCall's methods for use in
# server client_streamer handlers.
MultiReqView = view_class(:cancelled?, :deadline, :each_queued_msg,
:each_remote_read, :metadata, :output_metadata)
:each_remote_read, :metadata, :output_metadata,
:send_initial_metadata,
:metadata_to_send,
:merge_metadata_to_send,
:metadata_sent)
# Operation limits access to an ActiveCall's methods for use as
# a Operation on the client.

@ -56,7 +56,8 @@ module GRPC
# @param unmarshal [Function] f(string)->obj that unmarshals responses
# @param metadata_received [true|false] indicates if metadata has already
# been received. Should always be true for server calls
def initialize(call, marshal, unmarshal, metadata_received: false)
def initialize(call, marshal, unmarshal, metadata_received: false,
req_view: nil)
fail(ArgumentError, 'not a call') unless call.is_a? Core::Call
@call = call
@marshal = marshal
@ -68,6 +69,7 @@ module GRPC
@writes_complete = false
@complete = false
@done_mutex = Mutex.new
@req_view = req_view
end
# Begins orchestration of the Bidi stream for a client sending requests.
@ -97,7 +99,15 @@ module GRPC
#
# @param gen_each_reply [Proc] generates the BiDi stream replies.
def run_on_server(gen_each_reply)
replys = gen_each_reply.call(each_queued_msg)
# Pass in the optional call object parameter if possible
if gen_each_reply.arity == 1
replys = gen_each_reply.call(each_queued_msg)
elsif gen_each_reply.arity == 2
replys = gen_each_reply.call(each_queued_msg, @req_view)
else
fail 'Illegal arity of reply generator'
end
@loop_th = start_read_loop(is_client: false)
write_loop(replys, is_client: false)
end
@ -162,6 +172,7 @@ module GRPC
payload = @marshal.call(req)
# Fails if status already received
begin
@req_view.send_initial_metadata unless @req_view.nil?
@call.run_batch(SEND_MESSAGE => payload)
rescue GRPC::Core::CallError => e
# This is almost definitely caused by a status arriving while still

@ -104,7 +104,14 @@ module GRPC
end
def assert_arity_matches(mth)
if request_response? || server_streamer?
# A bidi handler function can optionally be passed a second
# call object parameter for access to metadata, cancelling, etc.
if bidi_streamer?
if mth.arity != 2 && mth.arity != 1
fail arity_error(mth, 2, "should be #{mth.name}(req, call) or " \
"#{mth.name}(req)")
end
elsif request_response? || server_streamer?
if mth.arity != 2
fail arity_error(mth, 2, "should be #{mth.name}(req, call)")
end

@ -335,8 +335,11 @@ module GRPC
return an_rpc if @pool.jobs_waiting <= @max_waiting_requests
GRPC.logger.warn("NOT AVAILABLE: too many jobs_waiting: #{an_rpc}")
noop = proc { |x| x }
# Create a new active call that knows that metadata hasn't been
# sent yet
c = ActiveCall.new(an_rpc.call, noop, noop, an_rpc.deadline,
metadata_received: true)
metadata_received: true, started: false)
c.send_status(GRPC::Core::StatusCodes::RESOURCE_EXHAUSTED, '')
nil
end
@ -347,8 +350,11 @@ module GRPC
return an_rpc if rpc_descs.key?(mth)
GRPC.logger.warn("UNIMPLEMENTED: #{an_rpc}")
noop = proc { |x| x }
# Create a new active call that knows that
# metadata hasn't been sent yet
c = ActiveCall.new(an_rpc.call, noop, noop, an_rpc.deadline,
metadata_received: true)
metadata_received: true, started: false)
c.send_status(GRPC::Core::StatusCodes::UNIMPLEMENTED, '')
nil
end
@ -396,17 +402,20 @@ module GRPC
unless @connect_md_proc.nil?
connect_md = @connect_md_proc.call(an_rpc.method, an_rpc.metadata)
end
an_rpc.call.run_batch(SEND_INITIAL_METADATA => connect_md)
return nil unless available?(an_rpc)
return nil unless implemented?(an_rpc)
# Create the ActiveCall
# Create the ActiveCall. Indicate that metadata hasnt been sent yet.
GRPC.logger.info("deadline is #{an_rpc.deadline}; (now=#{Time.now})")
rpc_desc = rpc_descs[an_rpc.method.to_sym]
c = ActiveCall.new(an_rpc.call, rpc_desc.marshal_proc,
rpc_desc.unmarshal_proc(:input), an_rpc.deadline,
metadata_received: true)
c = ActiveCall.new(an_rpc.call,
rpc_desc.marshal_proc,
rpc_desc.unmarshal_proc(:input),
an_rpc.deadline,
metadata_received: true,
started: false,
metadata_to_send: connect_md)
mth = an_rpc.method.to_sym
[c, mth]
end

@ -60,8 +60,10 @@ describe GRPC::ActiveCall do
end
describe '#multi_req_view' do
it 'exposes a fixed subset of the ActiveCall methods' do
want = %w(cancelled?, deadline, each_remote_read, metadata, shutdown)
it 'exposes a fixed subset of the ActiveCall.methods' do
want = %w(cancelled?, deadline, each_remote_read, metadata, \
shutdown, peer, peer_cert, send_initial_metadata, \
initial_metadata_sent)
v = @client_call.multi_req_view
want.each do |w|
expect(v.methods.include?(w))
@ -70,8 +72,10 @@ describe GRPC::ActiveCall do
end
describe '#single_req_view' do
it 'exposes a fixed subset of the ActiveCall methods' do
want = %w(cancelled?, deadline, metadata, shutdown)
it 'exposes a fixed subset of the ActiveCall.methods' do
want = %w(cancelled?, deadline, metadata, shutdown, \
send_initial_metadata, metadata_to_send, \
merge_metadata_to_send, initial_metadata_sent)
v = @client_call.single_req_view
want.each do |w|
expect(v.methods.include?(w))
@ -149,6 +153,146 @@ describe GRPC::ActiveCall do
end
end
describe 'sending initial metadata', send_initial_metadata: true do
it 'sends metadata before sending a message if it hasnt been sent yet' do
call = make_test_call
@client_call = ActiveCall.new(
call,
@pass_through,
@pass_through,
deadline,
started: false)
metadata = { key: 'dummy_val', other: 'other_val' }
expect(@client_call.metadata_sent).to eq(false)
@client_call.merge_metadata_to_send(metadata)
message = 'dummy message'
expect(call).to(
receive(:run_batch)
.with(
hash_including(
CallOps::SEND_INITIAL_METADATA => metadata)).once)
expect(call).to(
receive(:run_batch).with(hash_including(
CallOps::SEND_MESSAGE => message)).once)
@client_call.remote_send(message)
expect(@client_call.metadata_sent).to eq(true)
end
it 'doesnt send metadata if it thinks its already been sent' do
call = make_test_call
@client_call = ActiveCall.new(call,
@pass_through,
@pass_through,
deadline)
expect(@client_call.metadata_sent).to eql(true)
expect(call).to(
receive(:run_batch).with(hash_including(
CallOps::SEND_INITIAL_METADATA)).never)
@client_call.remote_send('test message')
end
it 'sends metadata if it is explicitly sent and ok to do so' do
call = make_test_call
@client_call = ActiveCall.new(call,
@pass_through,
@pass_through,
deadline,
started: false)
expect(@client_call.metadata_sent).to eql(false)
metadata = { test_key: 'val' }
@client_call.merge_metadata_to_send(metadata)
expect(@client_call.metadata_to_send).to eq(metadata)
expect(call).to(
receive(:run_batch).with(hash_including(
CallOps::SEND_INITIAL_METADATA =>
metadata)).once)
@client_call.send_initial_metadata
end
it 'explicit sending does nothing if metadata has already been sent' do
call = make_test_call
@client_call = ActiveCall.new(call,
@pass_through,
@pass_through,
deadline)
expect(@client_call.metadata_sent).to eql(true)
blk = proc do
@client_call.send_initial_metadata
end
expect { blk.call }.to_not raise_error
end
end
describe '#merge_metadata_to_send', merge_metadata_to_send: true do
it 'adds to existing metadata when there is existing metadata to send' do
call = make_test_call
starting_metadata = {
k1: 'key1_val',
k2: 'key2_val',
k3: 'key3_val'
}
@client_call = ActiveCall.new(
call,
@pass_through, @pass_through,
deadline,
started: false,
metadata_to_send: starting_metadata)
expect(@client_call.metadata_to_send).to eq(starting_metadata)
@client_call.merge_metadata_to_send(
k3: 'key3_new_val',
k4: 'key4_val')
expected_md_to_send = {
k1: 'key1_val',
k2: 'key2_val',
k3: 'key3_new_val',
k4: 'key4_val' }
expect(@client_call.metadata_to_send).to eq(expected_md_to_send)
@client_call.merge_metadata_to_send(k5: 'key5_val')
expected_md_to_send.merge!(k5: 'key5_val')
expect(@client_call.metadata_to_send).to eq(expected_md_to_send)
end
it 'fails when initial metadata has already been sent' do
call = make_test_call
@client_call = ActiveCall.new(
call,
@pass_through,
@pass_through,
deadline,
started: true)
expect(@client_call.metadata_sent).to eq(true)
blk = proc do
@client_call.merge_metadata_to_send(k1: 'key1_val')
end
expect { blk.call }.to raise_error
end
end
describe '#client_invoke' do
it 'sends metadata to the server when present' do
call = make_test_call
@ -163,7 +307,26 @@ describe GRPC::ActiveCall do
end
end
describe '#remote_read' do
describe '#send_status', send_status: true do
it 'works when no metadata or messages have been sent yet' do
call = make_test_call
ActiveCall.client_invoke(call)
recvd_rpc = @server.request_call
server_call = ActiveCall.new(
recvd_rpc.call,
@pass_through,
@pass_through,
deadline,
started: false)
expect(server_call.metadata_sent).to eq(false)
blk = proc { server_call.send_status(OK) }
expect { blk.call }.to_not raise_error
end
end
describe '#remote_read', remote_read: true do
it 'reads the response sent by a server' do
call = make_test_call
ActiveCall.client_invoke(call)
@ -205,6 +368,31 @@ describe GRPC::ActiveCall do
expect(client_call.metadata).to eq(expected)
end
it 'get a status from server when nothing else sent from server' do
client_call = make_test_call
ActiveCall.client_invoke(client_call)
recvd_rpc = @server.request_call
recvd_call = recvd_rpc.call
server_call = ActiveCall.new(
recvd_call,
@pass_through,
@pass_through,
deadline,
started: false)
server_call.send_status(OK, 'OK')
# Check that we can receive initial metadata and a status
client_call.run_batch(
CallOps::RECV_INITIAL_METADATA => nil)
batch_result = client_call.run_batch(
CallOps::RECV_STATUS_ON_CLIENT => nil)
expect(batch_result.status.code).to eq(OK)
end
it 'get a nil msg before a status when an OK status is sent' do
call = make_test_call
ActiveCall.client_invoke(call)
@ -329,6 +517,86 @@ describe GRPC::ActiveCall do
end
end
# Test sending of the initial metadata in #run_server_bidi
# from the server handler both implicitly and explicitly.
describe '#run_server_bidi metadata sending tests', run_server_bidi: true do
before(:each) do
@requests = ['first message', 'second message']
@server_to_client_metadata = { 'test_key' => 'test_val' }
@server_status = OK
@client_call = make_test_call
@client_call.run_batch(CallOps::SEND_INITIAL_METADATA => {})
recvd_rpc = @server.request_call
recvd_call = recvd_rpc.call
@server_call = ActiveCall.new(
recvd_call,
@pass_through,
@pass_through,
deadline,
metadata_received: true,
started: false,
metadata_to_send: @server_to_client_metadata)
end
after(:each) do
# Send the requests and send a close so the server can send a status
@requests.each do |message|
@client_call.run_batch(CallOps::SEND_MESSAGE => message)
end
@client_call.run_batch(CallOps::SEND_CLOSE_FROM_CLIENT => nil)
@server_thread.join
# Expect that initial metadata was sent,
# the requests were echoed, and a status was sent
batch_result = @client_call.run_batch(
CallOps::RECV_INITIAL_METADATA => nil)
expect(batch_result.metadata).to eq(@server_to_client_metadata)
@requests.each do |message|
batch_result = @client_call.run_batch(
CallOps::RECV_MESSAGE => nil)
expect(batch_result.message).to eq(message)
end
batch_result = @client_call.run_batch(
CallOps::RECV_STATUS_ON_CLIENT => nil)
expect(batch_result.status.code).to eq(@server_status)
end
it 'sends the initial metadata implicitly if not already sent' do
# Server handler that doesn't have access to a "call"
# It echoes the requests
fake_gen_each_reply_with_no_call_param = proc do |msgs|
msgs
end
@server_thread = Thread.new do
@server_call.run_server_bidi(
fake_gen_each_reply_with_no_call_param)
@server_call.send_status(@server_status)
end
end
it 'sends the metadata when sent explicitly and not already sent' do
# Fake server handler that has access to a "call" object and
# uses it to explicitly update and send the initial metadata
fake_gen_each_reply_with_call_param = proc do |msgs, call_param|
call_param.merge_metadata_to_send(@server_to_client_metadata)
call_param.send_initial_metadata
msgs
end
@server_thread = Thread.new do
@server_call.run_server_bidi(
fake_gen_each_reply_with_call_param)
@server_call.send_status(@server_status)
end
end
end
def expect_server_to_receive(sent_text, **kw)
c = expect_server_to_be_invoked(**kw)
expect(c.remote_read).to eq(sent_text)

@ -196,6 +196,9 @@ describe GRPC::RpcDesc do
def fake_svstream(_arg1, _arg2)
end
def fake_three_args(_arg1, _arg2, _arg3)
end
it 'raises when a request_response does not have 2 args' do
[:fake_clstream, :no_arg].each do |mth|
blk = proc do
@ -244,8 +247,8 @@ describe GRPC::RpcDesc do
expect(&blk).to_not raise_error
end
it 'raises when a bidi streamer does not have 1 arg' do
[:fake_svstream, :no_arg].each do |mth|
it 'raises when a bidi streamer does not have 1 or 2 args' do
[:fake_three_args, :no_arg].each do |mth|
blk = proc do
@bidi_streamer.assert_arity_matches(method(mth))
end
@ -259,6 +262,13 @@ describe GRPC::RpcDesc do
end
expect(&blk).to_not raise_error
end
it 'passes when a bidi streamer has 2 args' do
blk = proc do
@bidi_streamer.assert_arity_matches(method(:fake_svstream))
end
expect(&blk).to_not raise_error
end
end
describe '#request_response?' do

@ -33,7 +33,7 @@
"xmlDoc": true
},
"dependencies": {
"Ix-Async": "1.2.5"
"System.Interactive.Async": "3.0.0"
},
"frameworks": {
"net45": { },

@ -1,7 +1,7 @@
%YAML 1.2
--- |
{
<%include file="../build_options.include" args="executable=True"/>
<%include file="../build_options.include" args="executable=True,includeRuntimes=False"/>
"dependencies": {
"Grpc.Examples": {
"target": "project"

@ -1,7 +1,7 @@
%YAML 1.2
--- |
{
<%include file="../build_options.include" args="executable=True"/>
<%include file="../build_options.include" args="executable=True,includeRuntimes=False"/>
"dependencies": {
"Grpc.Examples": {
"target": "project"

@ -1,7 +1,7 @@
%YAML 1.2
--- |
{
<%include file="../build_options.include" args="executable=True,includeData=True"/>
<%include file="../build_options.include" args="executable=True,includeData=True,includeRuntimes=False"/>
"dependencies": {
"Grpc.IntegrationTesting": {
"target": "project"

@ -1,7 +1,7 @@
%YAML 1.2
--- |
{
<%include file="../build_options.include" args="executable=True,includeData=True"/>
<%include file="../build_options.include" args="executable=True,includeData=True,includeRuntimes=False"/>
"dependencies": {
"Grpc.IntegrationTesting": {
"target": "project"

@ -1,4 +1,4 @@
<%page args="executable=False,includeData=False"/>\
<%page args="executable=False,includeData=False,includeRuntimes=True"/>\
"buildOptions": {
% if executable:
"emitEntryPoint": true
@ -51,6 +51,8 @@
}
}
},
%endif
% if includeRuntimes:
"runtimes": {
"win7-x64": { },
"debian.8-x64": { },

@ -14,3 +14,5 @@ RUN apt-get update && apt-get -y dist-upgrade && apt-get install -y ${'\\'}
ca-certificates-mono ${'\\'}
nuget ${'\\'}
&& apt-get clean
RUN nuget update -self

@ -130,7 +130,7 @@ void grpc_run_bad_client_test(
grpc_server_start(a.server);
transport = grpc_create_chttp2_transport(&exec_ctx, NULL, sfd.server, 0);
server_setup_transport(&a, transport);
grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL, 0);
grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL);
grpc_exec_ctx_finish(&exec_ctx);
/* Bind everything into the same pollset */

@ -95,15 +95,13 @@ static void test_define_single_resource(const char *file, const char *name,
}
// Try deleting various resources (both those that exist and those that don't).
static void test_delete_resource() {
static void test_delete_resource(const char *minimal_good, const char *full) {
initialize_resources();
// Try deleting resource before any are defined.
census_delete_resource(0);
// Create and check a couple of resources.
int32_t rid1 = define_resource_from_file(
"test/core/census/data/resource_minimal_good.pb");
int32_t rid2 =
define_resource_from_file("test/core/census/data/resource_full.pb");
int32_t rid1 = define_resource_from_file(minimal_good);
int32_t rid2 = define_resource_from_file(full);
GPR_ASSERT(rid1 >= 0 && rid2 >= 0 && rid1 != rid2);
int32_t rid3 = census_resource_id("minimal_good");
int32_t rid4 = census_resource_id("full_resource");
@ -117,8 +115,7 @@ static void test_delete_resource() {
rid3 = census_resource_id("minimal_good");
GPR_ASSERT(rid3 < 0);
// Check that re-adding works.
rid1 = define_resource_from_file(
"test/core/census/data/resource_minimal_good.pb");
rid1 = define_resource_from_file(minimal_good);
GPR_ASSERT(rid1 >= 0);
rid3 = census_resource_id("minimal_good");
GPR_ASSERT(rid1 == rid3);
@ -136,22 +133,37 @@ static void test_base_resources() {
}
int main(int argc, char **argv) {
const char *resource_empty_name_pb, *resource_full_pb,
*resource_minimal_good_pb, *resource_no_name_pb,
*resource_no_numerator_pb, *resource_no_unit_pb;
if (argc == 7) {
resource_empty_name_pb = argv[1];
resource_full_pb = argv[2];
resource_minimal_good_pb = argv[3];
resource_no_name_pb = argv[4];
resource_no_numerator_pb = argv[5];
resource_no_unit_pb = argv[6];
} else {
GPR_ASSERT(argc == 1);
resource_empty_name_pb = "test/core/census/data/resource_empty_name.pb";
resource_full_pb = "test/core/census/data/resource_full.pb";
resource_minimal_good_pb = "test/core/census/data/resource_minimal_good.pb";
resource_no_name_pb = "test/core/census/data/resource_no_name.pb";
resource_no_numerator_pb = "test/core/census/data/resource_no_numerator.pb";
resource_no_unit_pb = "test/core/census/data/resource_no_unit.pb";
}
grpc_test_init(argc, argv);
test_enable_disable();
test_empty_definition();
test_define_single_resource("test/core/census/data/resource_minimal_good.pb",
"minimal_good", true);
test_define_single_resource("test/core/census/data/resource_full.pb",
"full_resource", true);
test_define_single_resource("test/core/census/data/resource_no_name.pb",
"resource_no_name", false);
test_define_single_resource("test/core/census/data/resource_no_numerator.pb",
"resource_no_numerator", false);
test_define_single_resource("test/core/census/data/resource_no_unit.pb",
"resource_no_unit", false);
test_define_single_resource("test/core/census/data/resource_empty_name.pb",
"resource_empty_name", false);
test_delete_resource();
test_define_single_resource(resource_minimal_good_pb, "minimal_good", true);
test_define_single_resource(resource_full_pb, "full_resource", true);
test_define_single_resource(resource_no_name_pb, "resource_no_name", false);
test_define_single_resource(resource_no_numerator_pb, "resource_no_numerator",
false);
test_define_single_resource(resource_no_unit_pb, "resource_no_unit", false);
test_define_single_resource(resource_empty_name_pb, "resource_empty_name",
false);
test_delete_resource(resource_minimal_good_pb, resource_full_pb);
test_base_resources();
return 0;
}

@ -108,7 +108,7 @@ static void chttp2_init_client_socketpair(grpc_end2end_test_fixture *f,
grpc_create_chttp2_transport(&exec_ctx, client_args, sfd->client, 1);
client_setup_transport(&exec_ctx, &cs, transport);
GPR_ASSERT(f->client);
grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL, 0);
grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL);
grpc_exec_ctx_finish(&exec_ctx);
}
@ -124,7 +124,7 @@ static void chttp2_init_server_socketpair(grpc_end2end_test_fixture *f,
transport =
grpc_create_chttp2_transport(&exec_ctx, server_args, sfd->server, 0);
server_setup_transport(f, transport);
grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL, 0);
grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL);
grpc_exec_ctx_finish(&exec_ctx);
}

@ -107,7 +107,7 @@ static void chttp2_init_client_socketpair(grpc_end2end_test_fixture *f,
grpc_create_chttp2_transport(&exec_ctx, client_args, sfd->client, 1);
client_setup_transport(&exec_ctx, &cs, transport);
GPR_ASSERT(f->client);
grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL, 0);
grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL);
grpc_exec_ctx_finish(&exec_ctx);
}
@ -123,7 +123,7 @@ static void chttp2_init_server_socketpair(grpc_end2end_test_fixture *f,
transport =
grpc_create_chttp2_transport(&exec_ctx, server_args, sfd->server, 0);
server_setup_transport(f, transport);
grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL, 0);
grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL);
grpc_exec_ctx_finish(&exec_ctx);
}

@ -107,7 +107,7 @@ static void chttp2_init_client_socketpair(grpc_end2end_test_fixture *f,
grpc_create_chttp2_transport(&exec_ctx, client_args, sfd->client, 1);
client_setup_transport(&exec_ctx, &cs, transport);
GPR_ASSERT(f->client);
grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL, 0);
grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL);
grpc_exec_ctx_finish(&exec_ctx);
}
@ -123,7 +123,7 @@ static void chttp2_init_server_socketpair(grpc_end2end_test_fixture *f,
transport =
grpc_create_chttp2_transport(&exec_ctx, server_args, sfd->server, 0);
server_setup_transport(f, transport);
grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL, 0);
grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL);
grpc_exec_ctx_finish(&exec_ctx);
}

@ -267,7 +267,7 @@ static void do_connect(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
grpc_transport *transport =
grpc_create_chttp2_transport(exec_ctx, NULL, server, 0);
grpc_server_setup_transport(exec_ctx, g_server, transport, NULL, NULL);
grpc_chttp2_transport_start_reading(exec_ctx, transport, NULL, 0);
grpc_chttp2_transport_start_reading(exec_ctx, transport, NULL);
grpc_exec_ctx_sched(exec_ctx, fc->closure, GRPC_ERROR_NONE, NULL);
} else {

@ -63,7 +63,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
grpc_completion_queue *cq = grpc_completion_queue_create(NULL);
grpc_transport *transport =
grpc_create_chttp2_transport(&exec_ctx, NULL, mock_endpoint, 1);
grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL, 0);
grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL);
grpc_channel *channel = grpc_channel_create(
&exec_ctx, "test-target", NULL, GRPC_CLIENT_DIRECT_CHANNEL, transport);

@ -71,7 +71,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
grpc_transport *transport =
grpc_create_chttp2_transport(&exec_ctx, NULL, mock_endpoint, 0);
grpc_server_setup_transport(&exec_ctx, server, transport, NULL, NULL);
grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL, 0);
grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL);
grpc_call *call1 = NULL;
grpc_call_details call_details1;

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save