commit
2c247433b8
256 changed files with 8212 additions and 3822 deletions
@ -1,217 +0,0 @@ |
||||
These instructions only cover building grpc C and C++ libraries under |
||||
typical unix systems. If you need more information, please try grpc's |
||||
wiki pages: |
||||
|
||||
https://github.com/google/grpc/wiki |
||||
|
||||
|
||||
************************* |
||||
* If you are in a hurry * |
||||
************************* |
||||
|
||||
On Linux (Debian): |
||||
|
||||
Note: you will need to add the Debian 'jessie-backports' distribution to your sources |
||||
file first. |
||||
|
||||
Add the following line to your `/etc/apt/sources.list` file: |
||||
|
||||
deb http://http.debian.net/debian jessie-backports main |
||||
|
||||
Install the gRPC library: |
||||
|
||||
$ [sudo] apt-get install libgrpc-dev |
||||
|
||||
OR |
||||
|
||||
$ git clone https://github.com/grpc/grpc.git |
||||
$ cd grpc |
||||
$ git submodule update --init |
||||
$ make |
||||
$ [sudo] make install |
||||
|
||||
You don't need anything else than GNU Make, gcc and autotools. Under a Debian |
||||
or Ubuntu system, this should boil down to the following packages: |
||||
|
||||
$ [sudo] apt-get install build-essential autoconf libtool |
||||
|
||||
Building the python wrapper requires the following: |
||||
|
||||
$ [sudo] apt-get install python-all-dev python-virtualenv |
||||
|
||||
If you want to install in a different directory than the default /usr/lib, you can |
||||
override it on the command line: |
||||
|
||||
$ [sudo] make install prefix=/opt |
||||
|
||||
|
||||
******************************* |
||||
* More detailled instructions * |
||||
******************************* |
||||
|
||||
Setting up dependencies |
||||
======================= |
||||
|
||||
Dependencies to compile the libraries |
||||
------------------------------------- |
||||
|
||||
grpc libraries have few external dependencies. If you need to compile and |
||||
install them, they are present in the third_party directory if you have |
||||
cloned the github repository recursively. If you didn't clone recursively, |
||||
you can still get them later by running the following command: |
||||
|
||||
$ git submodule update --init |
||||
|
||||
Note that the Makefile makes it much easier for you to compile from sources |
||||
if you were to clone recursively our git repository: it will automatically |
||||
compile zlib and OpenSSL, which are core requirements for grpc. Note this |
||||
creates grpc libraries that will have zlib and OpenSSL built-in inside of them, |
||||
which significantly increases the libraries' size. |
||||
|
||||
In order to decrease that size, you can manually install zlib and OpenSSL on |
||||
your system, so that the Makefile can use them instead. |
||||
|
||||
Under a Debian or Ubuntu system, one can acquire the development package |
||||
for zlib this way: |
||||
|
||||
# apt-get install zlib1g-dev |
||||
|
||||
To the best of our knowledge, no distribution has an OpenSSL package that |
||||
supports ALPN yet, so you would still have to depend on installing from source |
||||
for that particular dependency if you want to reduce the libraries' size. |
||||
|
||||
The recommended version of OpenSSL that provides ALPN support is available |
||||
at this URL: |
||||
|
||||
https://www.openssl.org/source/openssl-1.0.2.tar.gz |
||||
|
||||
|
||||
Dependencies to compile and run the tests |
||||
----------------------------------------- |
||||
|
||||
Compiling and running grpc plain-C tests dont't require any more dependency. |
||||
|
||||
|
||||
Compiling and running grpc C++ tests depend on protobuf 3.0.0, gtest and |
||||
gflags. Although gflags is provided in third_party, you will need to manually |
||||
install that dependency on your system to run these tests. |
||||
|
||||
Under a Debian or Ubuntu system, you can install the gtests and gflags packages |
||||
using apt-get: |
||||
|
||||
# apt-get install libgflags-dev libgtest-dev |
||||
|
||||
However, protobuf 3.0.0 isn't in a debian package yet, but the Makefile will |
||||
automatically try and compile the one present in third_party if you cloned the |
||||
repository recursively, and that it detects your system is lacking it. |
||||
|
||||
Compiling and installing protobuf 3.0.0 requires a few more dependencies in |
||||
itself, notably the autoconf suite. If you have apt-get, you can install |
||||
these dependencies this way: |
||||
|
||||
# apt-get install autoconf libtool |
||||
|
||||
If you want to run the tests using one of the sanitized configurations, you |
||||
will need clang and its instrumented libc++: |
||||
|
||||
# apt-get install clang libc++-dev |
||||
|
||||
Mac-specific notes: |
||||
------------------- |
||||
|
||||
For a Mac system, git is not available by default. You will first need to |
||||
install Xcode from the Mac AppStore and then run the following command from a |
||||
terminal: |
||||
|
||||
$ sudo xcode-select --install |
||||
|
||||
You should also install "port" following the instructions at |
||||
https://www.macports.org . This will reside in /opt/local/bin/port for |
||||
most Mac installations. Do the "git submodule" command listed above. |
||||
|
||||
Then execute the following for all the needed build dependencies |
||||
|
||||
$ sudo /opt/local/bin/port install autoconf automake libtool gflags cmake |
||||
$ mkdir ~/gtest-svn |
||||
$ svn checkout http://googletest.googlecode.com/svn/trunk/ gtest-svn |
||||
$ mkdir mybuild |
||||
$ cd mybuild |
||||
$ cmake ../gtest-svn |
||||
$ make |
||||
$ make gtest.a gtest_main.a |
||||
$ sudo cp libgtest.a libgtest_main.a /opt/local/lib |
||||
$ sudo mkdir /opt/local/include/gtest |
||||
$ sudo cp -pr ../gtest-svn/include/gtest /opt/local/include/gtest |
||||
|
||||
If you are going to make changes and need to regenerate the projects file, |
||||
you will need to install certain modules for python. |
||||
|
||||
$ sudo easy_install simplejson mako |
||||
|
||||
Mingw-specific notes: |
||||
--------------------- |
||||
|
||||
While gRPC compiles properly under mingw, some more preparation work is needed. |
||||
The recommendation is to use msys2. The installation instructions are available |
||||
at that address: http://msys2.github.io/ |
||||
|
||||
Once this is installed, make sure you are using the following: MinGW-w64 Win64. |
||||
You'll be required to install a few more packages: |
||||
|
||||
$ pacman -S make mingw-w64-x86_64-gcc mingw-w64-x86_64-zlib autoconf automake libtool |
||||
|
||||
Please also install OpenSSL from that website: |
||||
|
||||
http://slproweb.com/products/Win32OpenSSL.html |
||||
|
||||
The package Win64 OpenSSL v1.0.2a should do. At that point you should be able |
||||
to compile gRPC with the following: |
||||
|
||||
$ export LDFLAGS="-L/mingw64/lib -L/c/OpenSSL-Win64" |
||||
$ export CPPFLAGS="-I/mingw64/include -I/c/OpenSSL-Win64/include" |
||||
$ make |
||||
|
||||
A word on OpenSSL |
||||
----------------- |
||||
|
||||
Secure HTTP2 requires the TLS extension ALPN (see rfc 7301 and |
||||
http://http2.github.io/http2-spec/ section 3.3). Our HTTP2 implementation |
||||
relies on OpenSSL's implementation. OpenSSL 1.0.2 is the first released version |
||||
of OpenSSL that has ALPN support, and this explains our dependency on it. |
||||
|
||||
Note that the Makefile supports compiling only the unsecure elements of grpc, |
||||
and if you do not have OpenSSL and do not want it, you can still proceed |
||||
with installing only the elements you require. However, we strongly recommend |
||||
the use of encryption for all network traffic, and discourage the use of grpc |
||||
without TLS. |
||||
|
||||
|
||||
Compiling |
||||
========= |
||||
|
||||
If you have all the dependencies mentioned above, you should simply be able |
||||
to go ahead and run "make" to compile grpc's C and C++ libraries: |
||||
|
||||
$ make |
||||
|
||||
|
||||
Testing |
||||
======= |
||||
|
||||
To build and run the tests, you can run the command: |
||||
|
||||
$ make test |
||||
|
||||
If you want to be able to run them in parallel, and get better output, you can |
||||
also use the python tool we have written: |
||||
|
||||
$ ./tools/run_tests/run_tests.py |
||||
|
||||
|
||||
Installing |
||||
========== |
||||
|
||||
Once everything is compiled, you should be able to install grpc C and C++ |
||||
libraries and headers: |
||||
|
||||
# make install |
@ -0,0 +1,57 @@ |
||||
#If you are in a hurry |
||||
|
||||
For language-specific installation instructions for gRPC runtime, please |
||||
refer to these documents |
||||
|
||||
* [C++](examples/cpp): Currently to install gRPC for C++, you need to build from source as described below. |
||||
* [C#](src/csharp): NuGet package `Grpc` |
||||
* [Go](https://github.com/grpc/grpc-go): `go get google.golang.org/grpc` |
||||
* [Java](https://github.com/grpc/grpc-java) |
||||
* [Node](src/node): `npm install grpc` |
||||
* [Objective-C](src/objective-c) |
||||
* [PHP](src/php): `pecl install grpc-beta` |
||||
* [Python](src/python/grpcio): `pip install grpcio` |
||||
* [Ruby](src/ruby): `gem install grpc` |
||||
|
||||
|
||||
#Pre-requisites |
||||
|
||||
##Linux |
||||
|
||||
```sh |
||||
$ [sudo] apt-get install build-essential autoconf libtool |
||||
``` |
||||
|
||||
##Mac OSX |
||||
|
||||
For a Mac system, git is not available by default. You will first need to |
||||
install Xcode from the Mac AppStore and then run the following command from a |
||||
terminal: |
||||
|
||||
```sh |
||||
$ [sudo] xcode-select --install |
||||
``` |
||||
|
||||
##Protoc |
||||
|
||||
By default gRPC uses [protocol buffers](https://github.com/google/protobuf), |
||||
you will need the `protoc` compiler to generate stub server and client code. |
||||
|
||||
If you compile gRPC from source, as described below, the Makefile will |
||||
automatically try and compile the `protoc` in third_party if you cloned the |
||||
repository recursively and it detects that you don't already have it |
||||
installed. |
||||
|
||||
|
||||
#Build from Source |
||||
|
||||
For developers who are interested to contribute, here is how to compile the |
||||
gRPC C Core library. |
||||
|
||||
```sh |
||||
$ git clone https://github.com/grpc/grpc.git |
||||
$ cd grpc |
||||
$ git submodule update --init |
||||
$ make |
||||
$ [sudo] make install |
||||
``` |
@ -1,17 +1,14 @@ |
||||
{ |
||||
"name": "grpc/grpc-demo", |
||||
"description": "gRPC example for PHP", |
||||
"minimum-stability": "dev", |
||||
"repositories": [ |
||||
{ |
||||
"type": "vcs", |
||||
"url": "https://github.com/stanley-cheung/Protobuf-PHP" |
||||
} |
||||
], |
||||
"name": "grpc/grpc-demo", |
||||
"description": "gRPC example for PHP", |
||||
"minimum-stability": "dev", |
||||
"require": { |
||||
"php": ">=5.5.0", |
||||
"datto/protobuf-php": "dev-master", |
||||
"google/auth": "dev-master", |
||||
"grpc/grpc": "dev-release-0_11" |
||||
"grpc/grpc": "dev-release-0_13" |
||||
} |
||||
} |
||||
|
@ -0,0 +1,97 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015-2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPCXX_IMPL_CODEGEN_CORE_CODEGEN_INTERFACE_H |
||||
#define GRPCXX_IMPL_CODEGEN_CORE_CODEGEN_INTERFACE_H |
||||
|
||||
#include <grpc++/impl/codegen/config_protobuf.h> |
||||
#include <grpc++/impl/codegen/status.h> |
||||
#include <grpc/impl/codegen/grpc_types.h> |
||||
|
||||
namespace grpc { |
||||
|
||||
/// Interface between the codegen library and the minimal subset of core
|
||||
/// features required by the generated code.
|
||||
///
|
||||
/// All undocumented methods are simply forwarding the call to their namesakes.
|
||||
/// Please refer to their corresponding documentation for details.
|
||||
///
|
||||
/// \warning This interface should be considered internal and private.
|
||||
class CoreCodegenInterface { |
||||
public: |
||||
// Serialize the msg into a buffer created inside the function. The caller
|
||||
// should destroy the returned buffer when done with it. If serialization
|
||||
// fails,
|
||||
// false is returned and buffer is left unchanged.
|
||||
virtual Status SerializeProto(const grpc::protobuf::Message& msg, |
||||
grpc_byte_buffer** buffer) = 0; |
||||
|
||||
// The caller keeps ownership of buffer and msg.
|
||||
virtual Status DeserializeProto(grpc_byte_buffer* buffer, |
||||
grpc::protobuf::Message* msg, |
||||
int max_message_size) = 0; |
||||
|
||||
/// Upon a failed assertion, log the error.
|
||||
virtual void assert_fail(const char* failed_assertion) = 0; |
||||
|
||||
virtual grpc_completion_queue* grpc_completion_queue_create( |
||||
void* reserved) = 0; |
||||
virtual void grpc_completion_queue_destroy(grpc_completion_queue* cq) = 0; |
||||
virtual grpc_event grpc_completion_queue_pluck(grpc_completion_queue* cq, |
||||
void* tag, |
||||
gpr_timespec deadline, |
||||
void* reserved) = 0; |
||||
|
||||
virtual void* gpr_malloc(size_t size) = 0; |
||||
virtual void gpr_free(void* p) = 0; |
||||
|
||||
virtual void grpc_byte_buffer_destroy(grpc_byte_buffer* bb) = 0; |
||||
virtual void grpc_metadata_array_init(grpc_metadata_array* array) = 0; |
||||
virtual void grpc_metadata_array_destroy(grpc_metadata_array* array) = 0; |
||||
|
||||
virtual gpr_timespec gpr_inf_future(gpr_clock_type type) = 0; |
||||
}; |
||||
|
||||
extern CoreCodegenInterface* g_core_codegen_interface; |
||||
|
||||
/// Codegen specific version of \a GPR_ASSERT.
|
||||
#define GPR_CODEGEN_ASSERT(x) \ |
||||
do { \
|
||||
if (!(x)) { \
|
||||
grpc::g_core_codegen_interface->assert_fail(#x); \
|
||||
} \
|
||||
} while (0) |
||||
|
||||
} // namespace grpc
|
||||
|
||||
#endif // GRPCXX_IMPL_CODEGEN_CORE_CODEGEN_INTERFACE_H
|
@ -0,0 +1,463 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015-2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPCXX_IMPL_CODEGEN_ASYNC_STREAM_H |
||||
#define GRPCXX_IMPL_CODEGEN_ASYNC_STREAM_H |
||||
|
||||
#include <grpc++/impl/codegen/call.h> |
||||
#include <grpc++/impl/codegen/channel_interface.h> |
||||
#include <grpc++/impl/codegen/core_codegen_interface.h> |
||||
#include <grpc++/impl/codegen/server_context.h> |
||||
#include <grpc++/impl/codegen/service_type.h> |
||||
#include <grpc++/impl/codegen/status.h> |
||||
|
||||
namespace grpc { |
||||
|
||||
class CompletionQueue; |
||||
|
||||
/// Common interface for all client side asynchronous streaming.
|
||||
class ClientAsyncStreamingInterface { |
||||
public: |
||||
virtual ~ClientAsyncStreamingInterface() {} |
||||
|
||||
/// Request notification of the reading of the initial metadata. Completion
|
||||
/// will be notified by \a tag on the associated completion queue.
|
||||
///
|
||||
/// \param[in] tag Tag identifying this request.
|
||||
virtual void ReadInitialMetadata(void* tag) = 0; |
||||
|
||||
/// Request notification completion.
|
||||
///
|
||||
/// \param[out] status To be updated with the operation status.
|
||||
/// \param[in] tag Tag identifying this request.
|
||||
virtual void Finish(Status* status, void* tag) = 0; |
||||
}; |
||||
|
||||
/// An interface that yields a sequence of messages of type \a R.
|
||||
template <class R> |
||||
class AsyncReaderInterface { |
||||
public: |
||||
virtual ~AsyncReaderInterface() {} |
||||
|
||||
/// Read a message of type \a R into \a msg. Completion will be notified by \a
|
||||
/// tag on the associated completion queue.
|
||||
///
|
||||
/// \param[out] msg Where to eventually store the read message.
|
||||
/// \param[in] tag The tag identifying the operation.
|
||||
virtual void Read(R* msg, void* tag) = 0; |
||||
}; |
||||
|
||||
/// An interface that can be fed a sequence of messages of type \a W.
|
||||
template <class W> |
||||
class AsyncWriterInterface { |
||||
public: |
||||
virtual ~AsyncWriterInterface() {} |
||||
|
||||
/// Request the writing of \a msg with identifying tag \a tag.
|
||||
///
|
||||
/// Only one write may be outstanding at any given time. This means that
|
||||
/// after calling Write, one must wait to receive \a tag from the completion
|
||||
/// queue BEFORE calling Write again.
|
||||
///
|
||||
/// \param[in] msg The message to be written.
|
||||
/// \param[in] tag The tag identifying the operation.
|
||||
virtual void Write(const W& msg, void* tag) = 0; |
||||
}; |
||||
|
||||
template <class R> |
||||
class ClientAsyncReaderInterface : public ClientAsyncStreamingInterface, |
||||
public AsyncReaderInterface<R> {}; |
||||
|
||||
template <class R> |
||||
class ClientAsyncReader GRPC_FINAL : public ClientAsyncReaderInterface<R> { |
||||
public: |
||||
/// Create a stream and write the first request out.
|
||||
template <class W> |
||||
ClientAsyncReader(ChannelInterface* channel, CompletionQueue* cq, |
||||
const RpcMethod& method, ClientContext* context, |
||||
const W& request, void* tag) |
||||
: context_(context), call_(channel->CreateCall(method, context, cq)) { |
||||
init_ops_.set_output_tag(tag); |
||||
init_ops_.SendInitialMetadata(context->send_initial_metadata_); |
||||
// TODO(ctiller): don't assert
|
||||
GPR_CODEGEN_ASSERT(init_ops_.SendMessage(request).ok()); |
||||
init_ops_.ClientSendClose(); |
||||
call_.PerformOps(&init_ops_); |
||||
} |
||||
|
||||
void ReadInitialMetadata(void* tag) GRPC_OVERRIDE { |
||||
GPR_CODEGEN_ASSERT(!context_->initial_metadata_received_); |
||||
|
||||
meta_ops_.set_output_tag(tag); |
||||
meta_ops_.RecvInitialMetadata(context_); |
||||
call_.PerformOps(&meta_ops_); |
||||
} |
||||
|
||||
void Read(R* msg, void* tag) GRPC_OVERRIDE { |
||||
read_ops_.set_output_tag(tag); |
||||
if (!context_->initial_metadata_received_) { |
||||
read_ops_.RecvInitialMetadata(context_); |
||||
} |
||||
read_ops_.RecvMessage(msg); |
||||
call_.PerformOps(&read_ops_); |
||||
} |
||||
|
||||
void Finish(Status* status, void* tag) GRPC_OVERRIDE { |
||||
finish_ops_.set_output_tag(tag); |
||||
if (!context_->initial_metadata_received_) { |
||||
finish_ops_.RecvInitialMetadata(context_); |
||||
} |
||||
finish_ops_.ClientRecvStatus(context_, status); |
||||
call_.PerformOps(&finish_ops_); |
||||
} |
||||
|
||||
private: |
||||
ClientContext* context_; |
||||
Call call_; |
||||
CallOpSet<CallOpSendInitialMetadata, CallOpSendMessage, CallOpClientSendClose> |
||||
init_ops_; |
||||
CallOpSet<CallOpRecvInitialMetadata> meta_ops_; |
||||
CallOpSet<CallOpRecvInitialMetadata, CallOpRecvMessage<R>> read_ops_; |
||||
CallOpSet<CallOpRecvInitialMetadata, CallOpClientRecvStatus> finish_ops_; |
||||
}; |
||||
|
||||
/// Common interface for client side asynchronous writing.
|
||||
template <class W> |
||||
class ClientAsyncWriterInterface : public ClientAsyncStreamingInterface, |
||||
public AsyncWriterInterface<W> { |
||||
public: |
||||
/// Signal the client is done with the writes.
|
||||
///
|
||||
/// \param[in] tag The tag identifying the operation.
|
||||
virtual void WritesDone(void* tag) = 0; |
||||
}; |
||||
|
||||
template <class W> |
||||
class ClientAsyncWriter GRPC_FINAL : public ClientAsyncWriterInterface<W> { |
||||
public: |
||||
template <class R> |
||||
ClientAsyncWriter(ChannelInterface* channel, CompletionQueue* cq, |
||||
const RpcMethod& method, ClientContext* context, |
||||
R* response, void* tag) |
||||
: context_(context), call_(channel->CreateCall(method, context, cq)) { |
||||
finish_ops_.RecvMessage(response); |
||||
|
||||
init_ops_.set_output_tag(tag); |
||||
init_ops_.SendInitialMetadata(context->send_initial_metadata_); |
||||
call_.PerformOps(&init_ops_); |
||||
} |
||||
|
||||
void ReadInitialMetadata(void* tag) GRPC_OVERRIDE { |
||||
GPR_CODEGEN_ASSERT(!context_->initial_metadata_received_); |
||||
|
||||
meta_ops_.set_output_tag(tag); |
||||
meta_ops_.RecvInitialMetadata(context_); |
||||
call_.PerformOps(&meta_ops_); |
||||
} |
||||
|
||||
void Write(const W& msg, void* tag) GRPC_OVERRIDE { |
||||
write_ops_.set_output_tag(tag); |
||||
// TODO(ctiller): don't assert
|
||||
GPR_CODEGEN_ASSERT(write_ops_.SendMessage(msg).ok()); |
||||
call_.PerformOps(&write_ops_); |
||||
} |
||||
|
||||
void WritesDone(void* tag) GRPC_OVERRIDE { |
||||
writes_done_ops_.set_output_tag(tag); |
||||
writes_done_ops_.ClientSendClose(); |
||||
call_.PerformOps(&writes_done_ops_); |
||||
} |
||||
|
||||
void Finish(Status* status, void* tag) GRPC_OVERRIDE { |
||||
finish_ops_.set_output_tag(tag); |
||||
if (!context_->initial_metadata_received_) { |
||||
finish_ops_.RecvInitialMetadata(context_); |
||||
} |
||||
finish_ops_.ClientRecvStatus(context_, status); |
||||
call_.PerformOps(&finish_ops_); |
||||
} |
||||
|
||||
private: |
||||
ClientContext* context_; |
||||
Call call_; |
||||
CallOpSet<CallOpSendInitialMetadata> init_ops_; |
||||
CallOpSet<CallOpRecvInitialMetadata> meta_ops_; |
||||
CallOpSet<CallOpSendMessage> write_ops_; |
||||
CallOpSet<CallOpClientSendClose> writes_done_ops_; |
||||
CallOpSet<CallOpRecvInitialMetadata, CallOpGenericRecvMessage, |
||||
CallOpClientRecvStatus> finish_ops_; |
||||
}; |
||||
|
||||
/// Client-side interface for asynchronous bi-directional streaming.
|
||||
template <class W, class R> |
||||
class ClientAsyncReaderWriterInterface : public ClientAsyncStreamingInterface, |
||||
public AsyncWriterInterface<W>, |
||||
public AsyncReaderInterface<R> { |
||||
public: |
||||
/// Signal the client is done with the writes.
|
||||
///
|
||||
/// \param[in] tag The tag identifying the operation.
|
||||
virtual void WritesDone(void* tag) = 0; |
||||
}; |
||||
|
||||
template <class W, class R> |
||||
class ClientAsyncReaderWriter GRPC_FINAL |
||||
: public ClientAsyncReaderWriterInterface<W, R> { |
||||
public: |
||||
ClientAsyncReaderWriter(ChannelInterface* channel, CompletionQueue* cq, |
||||
const RpcMethod& method, ClientContext* context, |
||||
void* tag) |
||||
: context_(context), call_(channel->CreateCall(method, context, cq)) { |
||||
init_ops_.set_output_tag(tag); |
||||
init_ops_.SendInitialMetadata(context->send_initial_metadata_); |
||||
call_.PerformOps(&init_ops_); |
||||
} |
||||
|
||||
void ReadInitialMetadata(void* tag) GRPC_OVERRIDE { |
||||
GPR_CODEGEN_ASSERT(!context_->initial_metadata_received_); |
||||
|
||||
meta_ops_.set_output_tag(tag); |
||||
meta_ops_.RecvInitialMetadata(context_); |
||||
call_.PerformOps(&meta_ops_); |
||||
} |
||||
|
||||
void Read(R* msg, void* tag) GRPC_OVERRIDE { |
||||
read_ops_.set_output_tag(tag); |
||||
if (!context_->initial_metadata_received_) { |
||||
read_ops_.RecvInitialMetadata(context_); |
||||
} |
||||
read_ops_.RecvMessage(msg); |
||||
call_.PerformOps(&read_ops_); |
||||
} |
||||
|
||||
void Write(const W& msg, void* tag) GRPC_OVERRIDE { |
||||
write_ops_.set_output_tag(tag); |
||||
// TODO(ctiller): don't assert
|
||||
GPR_CODEGEN_ASSERT(write_ops_.SendMessage(msg).ok()); |
||||
call_.PerformOps(&write_ops_); |
||||
} |
||||
|
||||
void WritesDone(void* tag) GRPC_OVERRIDE { |
||||
writes_done_ops_.set_output_tag(tag); |
||||
writes_done_ops_.ClientSendClose(); |
||||
call_.PerformOps(&writes_done_ops_); |
||||
} |
||||
|
||||
void Finish(Status* status, void* tag) GRPC_OVERRIDE { |
||||
finish_ops_.set_output_tag(tag); |
||||
if (!context_->initial_metadata_received_) { |
||||
finish_ops_.RecvInitialMetadata(context_); |
||||
} |
||||
finish_ops_.ClientRecvStatus(context_, status); |
||||
call_.PerformOps(&finish_ops_); |
||||
} |
||||
|
||||
private: |
||||
ClientContext* context_; |
||||
Call call_; |
||||
CallOpSet<CallOpSendInitialMetadata> init_ops_; |
||||
CallOpSet<CallOpRecvInitialMetadata> meta_ops_; |
||||
CallOpSet<CallOpRecvInitialMetadata, CallOpRecvMessage<R>> read_ops_; |
||||
CallOpSet<CallOpSendMessage> write_ops_; |
||||
CallOpSet<CallOpClientSendClose> writes_done_ops_; |
||||
CallOpSet<CallOpRecvInitialMetadata, CallOpClientRecvStatus> finish_ops_; |
||||
}; |
||||
|
||||
template <class W, class R> |
||||
class ServerAsyncReader GRPC_FINAL : public ServerAsyncStreamingInterface, |
||||
public AsyncReaderInterface<R> { |
||||
public: |
||||
explicit ServerAsyncReader(ServerContext* ctx) |
||||
: call_(nullptr, nullptr, nullptr), ctx_(ctx) {} |
||||
|
||||
void SendInitialMetadata(void* tag) GRPC_OVERRIDE { |
||||
GPR_CODEGEN_ASSERT(!ctx_->sent_initial_metadata_); |
||||
|
||||
meta_ops_.set_output_tag(tag); |
||||
meta_ops_.SendInitialMetadata(ctx_->initial_metadata_); |
||||
ctx_->sent_initial_metadata_ = true; |
||||
call_.PerformOps(&meta_ops_); |
||||
} |
||||
|
||||
void Read(R* msg, void* tag) GRPC_OVERRIDE { |
||||
read_ops_.set_output_tag(tag); |
||||
read_ops_.RecvMessage(msg); |
||||
call_.PerformOps(&read_ops_); |
||||
} |
||||
|
||||
void Finish(const W& msg, const Status& status, void* tag) { |
||||
finish_ops_.set_output_tag(tag); |
||||
if (!ctx_->sent_initial_metadata_) { |
||||
finish_ops_.SendInitialMetadata(ctx_->initial_metadata_); |
||||
ctx_->sent_initial_metadata_ = true; |
||||
} |
||||
// The response is dropped if the status is not OK.
|
||||
if (status.ok()) { |
||||
finish_ops_.ServerSendStatus(ctx_->trailing_metadata_, |
||||
finish_ops_.SendMessage(msg)); |
||||
} else { |
||||
finish_ops_.ServerSendStatus(ctx_->trailing_metadata_, status); |
||||
} |
||||
call_.PerformOps(&finish_ops_); |
||||
} |
||||
|
||||
void FinishWithError(const Status& status, void* tag) { |
||||
GPR_CODEGEN_ASSERT(!status.ok()); |
||||
finish_ops_.set_output_tag(tag); |
||||
if (!ctx_->sent_initial_metadata_) { |
||||
finish_ops_.SendInitialMetadata(ctx_->initial_metadata_); |
||||
ctx_->sent_initial_metadata_ = true; |
||||
} |
||||
finish_ops_.ServerSendStatus(ctx_->trailing_metadata_, status); |
||||
call_.PerformOps(&finish_ops_); |
||||
} |
||||
|
||||
private: |
||||
void BindCall(Call* call) GRPC_OVERRIDE { call_ = *call; } |
||||
|
||||
Call call_; |
||||
ServerContext* ctx_; |
||||
CallOpSet<CallOpSendInitialMetadata> meta_ops_; |
||||
CallOpSet<CallOpRecvMessage<R>> read_ops_; |
||||
CallOpSet<CallOpSendInitialMetadata, CallOpSendMessage, |
||||
CallOpServerSendStatus> finish_ops_; |
||||
}; |
||||
|
||||
template <class W> |
||||
class ServerAsyncWriter GRPC_FINAL : public ServerAsyncStreamingInterface, |
||||
public AsyncWriterInterface<W> { |
||||
public: |
||||
explicit ServerAsyncWriter(ServerContext* ctx) |
||||
: call_(nullptr, nullptr, nullptr), ctx_(ctx) {} |
||||
|
||||
void SendInitialMetadata(void* tag) GRPC_OVERRIDE { |
||||
GPR_CODEGEN_ASSERT(!ctx_->sent_initial_metadata_); |
||||
|
||||
meta_ops_.set_output_tag(tag); |
||||
meta_ops_.SendInitialMetadata(ctx_->initial_metadata_); |
||||
ctx_->sent_initial_metadata_ = true; |
||||
call_.PerformOps(&meta_ops_); |
||||
} |
||||
|
||||
void Write(const W& msg, void* tag) GRPC_OVERRIDE { |
||||
write_ops_.set_output_tag(tag); |
||||
if (!ctx_->sent_initial_metadata_) { |
||||
write_ops_.SendInitialMetadata(ctx_->initial_metadata_); |
||||
ctx_->sent_initial_metadata_ = true; |
||||
} |
||||
// TODO(ctiller): don't assert
|
||||
GPR_CODEGEN_ASSERT(write_ops_.SendMessage(msg).ok()); |
||||
call_.PerformOps(&write_ops_); |
||||
} |
||||
|
||||
void Finish(const Status& status, void* tag) { |
||||
finish_ops_.set_output_tag(tag); |
||||
if (!ctx_->sent_initial_metadata_) { |
||||
finish_ops_.SendInitialMetadata(ctx_->initial_metadata_); |
||||
ctx_->sent_initial_metadata_ = true; |
||||
} |
||||
finish_ops_.ServerSendStatus(ctx_->trailing_metadata_, status); |
||||
call_.PerformOps(&finish_ops_); |
||||
} |
||||
|
||||
private: |
||||
void BindCall(Call* call) GRPC_OVERRIDE { call_ = *call; } |
||||
|
||||
Call call_; |
||||
ServerContext* ctx_; |
||||
CallOpSet<CallOpSendInitialMetadata> meta_ops_; |
||||
CallOpSet<CallOpSendInitialMetadata, CallOpSendMessage> write_ops_; |
||||
CallOpSet<CallOpSendInitialMetadata, CallOpServerSendStatus> finish_ops_; |
||||
}; |
||||
|
||||
/// Server-side interface for asynchronous bi-directional streaming.
|
||||
template <class W, class R> |
||||
class ServerAsyncReaderWriter GRPC_FINAL : public ServerAsyncStreamingInterface, |
||||
public AsyncWriterInterface<W>, |
||||
public AsyncReaderInterface<R> { |
||||
public: |
||||
explicit ServerAsyncReaderWriter(ServerContext* ctx) |
||||
: call_(nullptr, nullptr, nullptr), ctx_(ctx) {} |
||||
|
||||
void SendInitialMetadata(void* tag) GRPC_OVERRIDE { |
||||
GPR_CODEGEN_ASSERT(!ctx_->sent_initial_metadata_); |
||||
|
||||
meta_ops_.set_output_tag(tag); |
||||
meta_ops_.SendInitialMetadata(ctx_->initial_metadata_); |
||||
ctx_->sent_initial_metadata_ = true; |
||||
call_.PerformOps(&meta_ops_); |
||||
} |
||||
|
||||
void Read(R* msg, void* tag) GRPC_OVERRIDE { |
||||
read_ops_.set_output_tag(tag); |
||||
read_ops_.RecvMessage(msg); |
||||
call_.PerformOps(&read_ops_); |
||||
} |
||||
|
||||
void Write(const W& msg, void* tag) GRPC_OVERRIDE { |
||||
write_ops_.set_output_tag(tag); |
||||
if (!ctx_->sent_initial_metadata_) { |
||||
write_ops_.SendInitialMetadata(ctx_->initial_metadata_); |
||||
ctx_->sent_initial_metadata_ = true; |
||||
} |
||||
// TODO(ctiller): don't assert
|
||||
GPR_CODEGEN_ASSERT(write_ops_.SendMessage(msg).ok()); |
||||
call_.PerformOps(&write_ops_); |
||||
} |
||||
|
||||
void Finish(const Status& status, void* tag) { |
||||
finish_ops_.set_output_tag(tag); |
||||
if (!ctx_->sent_initial_metadata_) { |
||||
finish_ops_.SendInitialMetadata(ctx_->initial_metadata_); |
||||
ctx_->sent_initial_metadata_ = true; |
||||
} |
||||
finish_ops_.ServerSendStatus(ctx_->trailing_metadata_, status); |
||||
call_.PerformOps(&finish_ops_); |
||||
} |
||||
|
||||
private: |
||||
friend class ::grpc::Server; |
||||
|
||||
void BindCall(Call* call) GRPC_OVERRIDE { call_ = *call; } |
||||
|
||||
Call call_; |
||||
ServerContext* ctx_; |
||||
CallOpSet<CallOpSendInitialMetadata> meta_ops_; |
||||
CallOpSet<CallOpRecvMessage<R>> read_ops_; |
||||
CallOpSet<CallOpSendInitialMetadata, CallOpSendMessage> write_ops_; |
||||
CallOpSet<CallOpSendInitialMetadata, CallOpServerSendStatus> finish_ops_; |
||||
}; |
||||
|
||||
} // namespace grpc
|
||||
|
||||
#endif // GRPCXX_IMPL_CODEGEN_ASYNC_STREAM_H
|
@ -0,0 +1,152 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPCXX_IMPL_CODEGEN_STATUS_CODE_ENUM_H |
||||
#define GRPCXX_IMPL_CODEGEN_STATUS_CODE_ENUM_H |
||||
|
||||
namespace grpc { |
||||
|
||||
enum StatusCode { |
||||
/// Not an error; returned on success.
|
||||
OK = 0, |
||||
|
||||
/// The operation was cancelled (typically by the caller).
|
||||
CANCELLED = 1, |
||||
|
||||
/// Unknown error. An example of where this error may be returned is if a
|
||||
/// Status value received from another address space belongs to an error-space
|
||||
/// that is not known in this address space. Also errors raised by APIs that
|
||||
/// do not return enough error information may be converted to this error.
|
||||
UNKNOWN = 2, |
||||
|
||||
/// Client specified an invalid argument. Note that this differs from
|
||||
/// FAILED_PRECONDITION. INVALID_ARGUMENT indicates arguments that are
|
||||
/// problematic regardless of the state of the system (e.g., a malformed file
|
||||
/// name).
|
||||
INVALID_ARGUMENT = 3, |
||||
|
||||
/// Deadline expired before operation could complete. For operations that
|
||||
/// change the state of the system, this error may be returned even if the
|
||||
/// operation has completed successfully. For example, a successful response
|
||||
/// from a server could have been delayed long enough for the deadline to
|
||||
/// expire.
|
||||
DEADLINE_EXCEEDED = 4, |
||||
|
||||
/// Some requested entity (e.g., file or directory) was not found.
|
||||
NOT_FOUND = 5, |
||||
|
||||
/// Some entity that we attempted to create (e.g., file or directory) already
|
||||
/// exists.
|
||||
ALREADY_EXISTS = 6, |
||||
|
||||
/// The caller does not have permission to execute the specified operation.
|
||||
/// PERMISSION_DENIED must not be used for rejections caused by exhausting
|
||||
/// some resource (use RESOURCE_EXHAUSTED instead for those errors).
|
||||
/// PERMISSION_DENIED must not be used if the caller can not be identified
|
||||
/// (use UNAUTHENTICATED instead for those errors).
|
||||
PERMISSION_DENIED = 7, |
||||
|
||||
/// The request does not have valid authentication credentials for the
|
||||
/// operation.
|
||||
UNAUTHENTICATED = 16, |
||||
|
||||
/// Some resource has been exhausted, perhaps a per-user quota, or perhaps the
|
||||
/// entire file system is out of space.
|
||||
RESOURCE_EXHAUSTED = 8, |
||||
|
||||
/// Operation was rejected because the system is not in a state required for
|
||||
/// the operation's execution. For example, directory to be deleted may be
|
||||
/// non-empty, an rmdir operation is applied to a non-directory, etc.
|
||||
///
|
||||
/// A litmus test that may help a service implementor in deciding
|
||||
/// between FAILED_PRECONDITION, ABORTED, and UNAVAILABLE:
|
||||
/// (a) Use UNAVAILABLE if the client can retry just the failing call.
|
||||
/// (b) Use ABORTED if the client should retry at a higher-level
|
||||
/// (e.g., restarting a read-modify-write sequence).
|
||||
/// (c) Use FAILED_PRECONDITION if the client should not retry until
|
||||
/// the system state has been explicitly fixed. E.g., if an "rmdir"
|
||||
/// fails because the directory is non-empty, FAILED_PRECONDITION
|
||||
/// should be returned since the client should not retry unless
|
||||
/// they have first fixed up the directory by deleting files from it.
|
||||
/// (d) Use FAILED_PRECONDITION if the client performs conditional
|
||||
/// REST Get/Update/Delete on a resource and the resource on the
|
||||
/// server does not match the condition. E.g., conflicting
|
||||
/// read-modify-write on the same resource.
|
||||
FAILED_PRECONDITION = 9, |
||||
|
||||
/// The operation was aborted, typically due to a concurrency issue like
|
||||
/// sequencer check failures, transaction aborts, etc.
|
||||
///
|
||||
/// See litmus test above for deciding between FAILED_PRECONDITION, ABORTED,
|
||||
/// and UNAVAILABLE.
|
||||
ABORTED = 10, |
||||
|
||||
/// Operation was attempted past the valid range. E.g., seeking or reading
|
||||
/// past end of file.
|
||||
///
|
||||
/// Unlike INVALID_ARGUMENT, this error indicates a problem that may be fixed
|
||||
/// if the system state changes. For example, a 32-bit file system will
|
||||
/// generate INVALID_ARGUMENT if asked to read at an offset that is not in the
|
||||
/// range [0,2^32-1], but it will generate OUT_OF_RANGE if asked to read from
|
||||
/// an offset past the current file size.
|
||||
///
|
||||
/// There is a fair bit of overlap between FAILED_PRECONDITION and
|
||||
/// OUT_OF_RANGE. We recommend using OUT_OF_RANGE (the more specific error)
|
||||
/// when it applies so that callers who are iterating through a space can
|
||||
/// easily look for an OUT_OF_RANGE error to detect when they are done.
|
||||
OUT_OF_RANGE = 11, |
||||
|
||||
/// Operation is not implemented or not supported/enabled in this service.
|
||||
UNIMPLEMENTED = 12, |
||||
|
||||
/// Internal errors. Means some invariants expected by underlying System has
|
||||
/// been broken. If you see one of these errors, Something is very broken.
|
||||
INTERNAL = 13, |
||||
|
||||
/// The service is currently unavailable. This is a most likely a transient
|
||||
/// condition and may be corrected by retrying with a backoff.
|
||||
///
|
||||
/// See litmus test above for deciding between FAILED_PRECONDITION, ABORTED,
|
||||
/// and UNAVAILABLE.
|
||||
UNAVAILABLE = 14, |
||||
|
||||
/// Unrecoverable data loss or corruption.
|
||||
DATA_LOSS = 15, |
||||
|
||||
/// Force users to include a default branch:
|
||||
DO_NOT_USE = -1 |
||||
}; |
||||
|
||||
} // namespace grpc
|
||||
|
||||
#endif // GRPCXX_IMPL_CODEGEN_STATUS_CODE_ENUM_H
|
@ -0,0 +1,45 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015-2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPCXX_IMPL_CODEGEN_SYNC_H |
||||
#define GRPCXX_IMPL_CODEGEN_SYNC_H |
||||
|
||||
#include <grpc++/impl/codegen/config.h> |
||||
|
||||
#ifdef GRPC_CXX0X_NO_THREAD |
||||
#include <grpc++/impl/codegen/sync_no_cxx11.h> |
||||
#else |
||||
#include <grpc++/impl/codegen/sync_cxx11.h> |
||||
#endif |
||||
|
||||
#endif // GRPCXX_IMPL_CODEGEN_SYNC_H
|
@ -0,0 +1,71 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include "src/core/support/backoff.h" |
||||
|
||||
#include <grpc/support/useful.h> |
||||
|
||||
void gpr_backoff_init(gpr_backoff *backoff, double multiplier, double jitter, |
||||
int64_t min_timeout_millis, int64_t max_timeout_millis) { |
||||
backoff->multiplier = multiplier; |
||||
backoff->jitter = jitter; |
||||
backoff->min_timeout_millis = min_timeout_millis; |
||||
backoff->max_timeout_millis = max_timeout_millis; |
||||
backoff->rng_state = (uint32_t)gpr_now(GPR_CLOCK_REALTIME).tv_nsec; |
||||
} |
||||
|
||||
gpr_timespec gpr_backoff_begin(gpr_backoff *backoff, gpr_timespec now) { |
||||
backoff->current_timeout_millis = backoff->min_timeout_millis; |
||||
return gpr_time_add( |
||||
now, gpr_time_from_millis(backoff->current_timeout_millis, GPR_TIMESPAN)); |
||||
} |
||||
|
||||
/* Generate a random number between 0 and 1. */ |
||||
static double generate_uniform_random_number(uint32_t *rng_state) { |
||||
*rng_state = (1103515245 * *rng_state + 12345) % ((uint32_t)1 << 31); |
||||
return *rng_state / (double)((uint32_t)1 << 31); |
||||
} |
||||
|
||||
gpr_timespec gpr_backoff_step(gpr_backoff *backoff, gpr_timespec now) { |
||||
double new_timeout_millis = |
||||
backoff->multiplier * (double)backoff->current_timeout_millis; |
||||
double jitter_range = backoff->jitter * new_timeout_millis; |
||||
double jitter = |
||||
(2 * generate_uniform_random_number(&backoff->rng_state) - 1) * |
||||
jitter_range; |
||||
backoff->current_timeout_millis = |
||||
GPR_CLAMP((int64_t)(new_timeout_millis + jitter), |
||||
backoff->min_timeout_millis, backoff->max_timeout_millis); |
||||
return gpr_time_add( |
||||
now, gpr_time_from_millis(backoff->current_timeout_millis, GPR_TIMESPAN)); |
||||
} |
@ -0,0 +1,65 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef GRPC_INTERNAL_CORE_SUPPORT_BACKOFF_H |
||||
#define GRPC_INTERNAL_CORE_SUPPORT_BACKOFF_H |
||||
|
||||
#include <grpc/support/time.h> |
||||
|
||||
typedef struct { |
||||
/// const: multiplier between retry attempts
|
||||
double multiplier; |
||||
/// const: amount to randomize backoffs
|
||||
double jitter; |
||||
/// const: minimum time between retries in milliseconds
|
||||
int64_t min_timeout_millis; |
||||
/// const: maximum time between retries in milliseconds
|
||||
int64_t max_timeout_millis; |
||||
|
||||
/// random number generator
|
||||
uint32_t rng_state; |
||||
|
||||
/// current retry timeout in milliseconds
|
||||
int64_t current_timeout_millis; |
||||
} gpr_backoff; |
||||
|
||||
/// Initialize backoff machinery - does not need to be destroyed
|
||||
void gpr_backoff_init(gpr_backoff *backoff, double multiplier, double jitter, |
||||
int64_t min_timeout_millis, int64_t max_timeout_millis); |
||||
|
||||
/// Begin retry loop: returns a timespec for the NEXT retry
|
||||
gpr_timespec gpr_backoff_begin(gpr_backoff *backoff, gpr_timespec now); |
||||
/// Step a retry loop: returns a timespec for the NEXT retry
|
||||
gpr_timespec gpr_backoff_step(gpr_backoff *backoff, gpr_timespec now); |
||||
|
||||
#endif // GRPC_INTERNAL_CORE_SUPPORT_BACKOFF_H
|
@ -0,0 +1,45 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include <grpc++/impl/codegen/core_codegen_interface.h> |
||||
#include <grpc++/impl/codegen/grpc_library.h> |
||||
|
||||
/// Initializes the global gRPC variables for the codegen library. These will
|
||||
/// stay null in the absence of of grpc++ library. In this case, no gRPC
|
||||
/// features such as the ability to perform calls will be available. Trying to
|
||||
/// perform them would result in a segmentation fault when trying to deference
|
||||
/// the following nulled globals. These should be associated with actual
|
||||
/// as part of the instantiation of a \a grpc::GrpcLibraryInitializer variable.
|
||||
|
||||
grpc::CoreCodegenInterface* grpc::g_core_codegen_interface = nullptr; |
||||
grpc::GrpcLibraryInterface* grpc::g_glip = nullptr; |
@ -1,92 +0,0 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include <grpc++/impl/call.h> |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc++/channel.h> |
||||
#include <grpc++/client_context.h> |
||||
#include <grpc++/support/byte_buffer.h> |
||||
#include "src/core/profiling/timers.h" |
||||
|
||||
namespace grpc { |
||||
|
||||
void FillMetadataMap( |
||||
grpc_metadata_array* arr, |
||||
std::multimap<grpc::string_ref, grpc::string_ref>* metadata) { |
||||
for (size_t i = 0; i < arr->count; i++) { |
||||
// TODO(yangg) handle duplicates?
|
||||
metadata->insert(std::pair<grpc::string_ref, grpc::string_ref>( |
||||
arr->metadata[i].key, grpc::string_ref(arr->metadata[i].value, |
||||
arr->metadata[i].value_length))); |
||||
} |
||||
grpc_metadata_array_destroy(arr); |
||||
grpc_metadata_array_init(arr); |
||||
} |
||||
|
||||
// TODO(yangg) if the map is changed before we send, the pointers will be a
|
||||
// mess. Make sure it does not happen.
|
||||
grpc_metadata* FillMetadataArray( |
||||
const std::multimap<grpc::string, grpc::string>& metadata) { |
||||
if (metadata.empty()) { |
||||
return nullptr; |
||||
} |
||||
grpc_metadata* metadata_array = |
||||
(grpc_metadata*)gpr_malloc(metadata.size() * sizeof(grpc_metadata)); |
||||
size_t i = 0; |
||||
for (auto iter = metadata.cbegin(); iter != metadata.cend(); ++iter, ++i) { |
||||
metadata_array[i].key = iter->first.c_str(); |
||||
metadata_array[i].value = iter->second.c_str(); |
||||
metadata_array[i].value_length = iter->second.size(); |
||||
} |
||||
return metadata_array; |
||||
} |
||||
|
||||
Call::Call(grpc_call* call, CallHook* call_hook, CompletionQueue* cq) |
||||
: call_hook_(call_hook), cq_(cq), call_(call), max_message_size_(-1) {} |
||||
|
||||
Call::Call(grpc_call* call, CallHook* call_hook, CompletionQueue* cq, |
||||
int max_message_size) |
||||
: call_hook_(call_hook), |
||||
cq_(cq), |
||||
call_(call), |
||||
max_message_size_(max_message_size) {} |
||||
|
||||
void Call::PerformOps(CallOpSetInterface* ops) { |
||||
if (max_message_size_ > 0) { |
||||
ops->set_max_message_size(max_message_size_); |
||||
} |
||||
call_hook_->PerformOpsOnCall(ops, this); |
||||
} |
||||
|
||||
} // namespace grpc
|
@ -0,0 +1,71 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2016, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
// This file should be compiled as part of grpc++.
|
||||
|
||||
#include <grpc++/impl/codegen/core_codegen_interface.h> |
||||
#include <grpc/impl/codegen/grpc_types.h> |
||||
#include <grpc/byte_buffer.h> |
||||
|
||||
namespace grpc { |
||||
|
||||
/// Implementation of the core codegen interface.
|
||||
class CoreCodegen : public CoreCodegenInterface { |
||||
private: |
||||
Status SerializeProto(const grpc::protobuf::Message& msg, |
||||
grpc_byte_buffer** bp) override; |
||||
|
||||
Status DeserializeProto(grpc_byte_buffer* buffer, |
||||
grpc::protobuf::Message* msg, |
||||
int max_message_size) override; |
||||
|
||||
grpc_completion_queue* grpc_completion_queue_create(void* reserved) override; |
||||
void grpc_completion_queue_destroy(grpc_completion_queue* cq) override; |
||||
grpc_event grpc_completion_queue_pluck(grpc_completion_queue* cq, void* tag, |
||||
gpr_timespec deadline, |
||||
void* reserved) override; |
||||
|
||||
void* gpr_malloc(size_t size) override; |
||||
void gpr_free(void* p) override; |
||||
|
||||
void grpc_byte_buffer_destroy(grpc_byte_buffer* bb) override; |
||||
|
||||
void grpc_metadata_array_init(grpc_metadata_array* array) override; |
||||
void grpc_metadata_array_destroy(grpc_metadata_array* array) override; |
||||
|
||||
gpr_timespec gpr_inf_future(gpr_clock_type type) override; |
||||
|
||||
void assert_fail(const char* failed_assertion) override; |
||||
}; |
||||
|
||||
} // namespace grpc
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue