mirror of https://github.com/grpc/grpc.git
commit
909dd6ec8b
363 changed files with 21818 additions and 3493 deletions
@ -0,0 +1,77 @@ |
|||||||
|
# gRPC command line tool |
||||||
|
|
||||||
|
## Overview |
||||||
|
|
||||||
|
This document describes the command line tool that comes with gRPC repository. It is desireable to have command line |
||||||
|
tools written in other languages to roughly follow the same syntax and flags. |
||||||
|
|
||||||
|
At this point, the tool needs to be built from source, and it should be moved out to grpc-tools repository as a stand |
||||||
|
alone application once it is mature enough. |
||||||
|
|
||||||
|
## Core functionality |
||||||
|
|
||||||
|
The command line tool can do the following things: |
||||||
|
|
||||||
|
- Send unary rpc. |
||||||
|
- Attach metadata and display received metadata. |
||||||
|
- Handle common authentication to server. |
||||||
|
- Find the request/response types from a given proto file. |
||||||
|
- Read proto request in text form. |
||||||
|
- Read request in wire form (for protobuf messages, this means serialized binary form). |
||||||
|
- Display proto response in text form. |
||||||
|
- Write response in wire form to a file. |
||||||
|
|
||||||
|
The command line tool should support the following things: |
||||||
|
|
||||||
|
- List server services and methods through server reflection. |
||||||
|
- Infer request/response types from server reflection result. |
||||||
|
- Fine-grained auth control (such as, use this oauth token to talk to the server). |
||||||
|
- Send streaming rpc. |
||||||
|
|
||||||
|
## Code location |
||||||
|
|
||||||
|
To use the tool, you need to get the grpc repository and in the grpc directory execute |
||||||
|
|
||||||
|
``` |
||||||
|
$ make grpc_cli |
||||||
|
``` |
||||||
|
|
||||||
|
The main file can be found at |
||||||
|
https://github.com/grpc/grpc/blob/master/test/cpp/util/grpc_cli.cc |
||||||
|
|
||||||
|
## Usage |
||||||
|
|
||||||
|
### Basic usage |
||||||
|
|
||||||
|
Send a rpc to a helloworld server at `localhost:50051`: |
||||||
|
|
||||||
|
``` |
||||||
|
$ bins/opt/grpc_cli call localhost:50051 SayHello examples/protos/helloworld.proto \ |
||||||
|
"name: 'world'" --enable_ssl=false |
||||||
|
``` |
||||||
|
|
||||||
|
On success, the tool will print out |
||||||
|
|
||||||
|
``` |
||||||
|
Rpc succeeded with OK status |
||||||
|
Response: |
||||||
|
message: "Hello world" |
||||||
|
``` |
||||||
|
|
||||||
|
The `localhost:50051` part indicates the server you are connecting to. `SayHello` is (part of) the |
||||||
|
gRPC method string. Then there is the path to the proto file containing the service definition, |
||||||
|
if it is not under current directory, you can use `--proto_path` to specify a new search root. |
||||||
|
`"name: 'world'"` is the text format of the request proto message. |
||||||
|
We are not using ssl here by `--enable_ssl=false`. For information on more |
||||||
|
flags, look at the comments of `grpc_cli.cc`. |
||||||
|
|
||||||
|
### Send non-proto rpc |
||||||
|
|
||||||
|
For using gRPC with protocols other than probobuf, you will need the exact method name string |
||||||
|
and a file containing the raw bytes to be sent on the wire |
||||||
|
|
||||||
|
``` |
||||||
|
$ bins/opt/grpc_cli call localhost:50051 /helloworld.Greeter/SayHello --input_binary_file=input.bin \ |
||||||
|
--output_binary_file=output.bin |
||||||
|
``` |
||||||
|
On success, you will need to read or decode the response from the `output.bin` file. |
@ -0,0 +1,85 @@ |
|||||||
|
GRPC C++ STYLE GUIDE |
||||||
|
===================== |
||||||
|
|
||||||
|
Background |
||||||
|
---------- |
||||||
|
|
||||||
|
Here we document style rules for C++ usage in the gRPC C++ bindings |
||||||
|
and tests. |
||||||
|
|
||||||
|
General |
||||||
|
------- |
||||||
|
|
||||||
|
- The majority of gRPC's C++ requirements are drawn from the [Google C++ style |
||||||
|
guide] (https://google.github.io/styleguide/cppguide.html) |
||||||
|
- However, gRPC has some additional requirements to maintain |
||||||
|
[portability] (#portability) |
||||||
|
- As in C, layout rules are defined by clang-format, and all code |
||||||
|
should be passed through clang-format. A (docker-based) script to do |
||||||
|
so is included in [tools/distrib/clang\_format\_code.sh] |
||||||
|
(../tools/distrib/clang_format_code.sh). |
||||||
|
|
||||||
|
<a name="portability"></a> |
||||||
|
Portability Restrictions |
||||||
|
------------------- |
||||||
|
|
||||||
|
gRPC supports a large number of compilers, ranging from those that are |
||||||
|
missing many key C++11 features to those that have quite detailed |
||||||
|
analysis. As a result, gRPC compiles with a high level of warnings and |
||||||
|
treat all warnings as errors. gRPC also forbids the use of some common |
||||||
|
C++11 constructs. Here are some guidelines, to be extended as needed: |
||||||
|
- Do not use range-based for. Expressions of the form |
||||||
|
```c |
||||||
|
for (auto& i: vec) { |
||||||
|
// code |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
are not allowed and should be replaced with code such as |
||||||
|
```c |
||||||
|
for (auto it = vec.begin; it != vec.end(); it++) { |
||||||
|
auto& i = *it; |
||||||
|
// code |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
- Do not use lambda of any kind (no capture, explicit capture, or |
||||||
|
default capture). Other C++ functional features such as |
||||||
|
`std::function` or `std::bind` are allowed |
||||||
|
- Do not use brace-list initializers. |
||||||
|
- Do not compare a pointer to `nullptr` . This is because gcc 4.4 |
||||||
|
does not support `nullptr` directly and gRPC implements a subset of |
||||||
|
its features in [include/grpc++/impl/codegen/config.h] |
||||||
|
(../include/grpc++/impl/codegen/config.h). Instead, pointers should |
||||||
|
be checked for validity using their implicit conversion to `bool`. |
||||||
|
In other words, use `if (p)` rather than `if (p != nullptr)` |
||||||
|
- Do not use `final` or `override` as these are not supported by some |
||||||
|
compilers. Instead use `GRPC_FINAL` and `GRPC_OVERRIDE` . These |
||||||
|
compile down to the traditional C++ forms for compilers that support |
||||||
|
them but are just elided if the compiler does not support those features. |
||||||
|
- In the [include] (../../../tree/master/include/grpc++) and [src] |
||||||
|
(../../../tree/master/src/cpp) directory trees, you should also not |
||||||
|
use certain STL objects like `std::mutex`, `std::lock_guard`, |
||||||
|
`std::unique_lock`, `std::nullptr`, `std::thread` . Instead, use |
||||||
|
`grpc::mutex`, `grpc::lock_guard`, etc., which are gRPC |
||||||
|
implementations of the prominent features of these objects that are |
||||||
|
not always available. You can use the `std` versions of those in [test] |
||||||
|
(../../../tree/master/test/cpp) |
||||||
|
- Similarly, in the same directories, do not use `std::chrono` unless |
||||||
|
it is guarded by `#ifndef GRPC_CXX0X_NO_CHRONO` . For platforms that |
||||||
|
lack`std::chrono,` there is a C-language timer called gpr_timespec that can |
||||||
|
be used instead. |
||||||
|
- `std::unique_ptr` must be used with extreme care in any kind of |
||||||
|
collection. For example `vector<std::unique_ptr>` does not work in |
||||||
|
gcc 4.4 if the vector is constructed to its full size at |
||||||
|
initialization but does work if elements are added to the vector |
||||||
|
using functions like `push_back`. `map` and other pair-based |
||||||
|
collections do not work with `unique_ptr` under gcc 4.4. The issue |
||||||
|
is that many of these collection implementations assume a copy |
||||||
|
constructor |
||||||
|
to be available. |
||||||
|
- Don't use `std::this_thread` . Use `gpr_sleep_until` for sleeping a thread. |
||||||
|
- [Some adjacent character combinations cause problems] |
||||||
|
(https://en.wikipedia.org/wiki/Digraphs_and_trigraphs#C). If declaring a |
||||||
|
template against some class relative to the global namespace, |
||||||
|
`<::name` will be non-portable. Separate the `<` from the `:` and use `< ::name`. |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,57 @@ |
|||||||
|
/*
|
||||||
|
* |
||||||
|
* 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_CREATE_CHANNEL_POSIX_H |
||||||
|
#define GRPCXX_CREATE_CHANNEL_POSIX_H |
||||||
|
|
||||||
|
#include <memory> |
||||||
|
|
||||||
|
#include <grpc++/channel.h> |
||||||
|
#include <grpc/support/port_platform.h> |
||||||
|
|
||||||
|
namespace grpc { |
||||||
|
|
||||||
|
#ifdef GPR_SUPPORT_CHANNELS_FROM_FD |
||||||
|
|
||||||
|
/// Create a new \a Channel communicating over given file descriptor
|
||||||
|
///
|
||||||
|
/// \param target The name of the target.
|
||||||
|
/// \param fd The file descriptor representing a socket.
|
||||||
|
std::shared_ptr<Channel> CreateInsecureChannelFromFd(const grpc::string& target, |
||||||
|
int fd); |
||||||
|
|
||||||
|
#endif // GPR_SUPPORT_CHANNELS_FROM_FD
|
||||||
|
|
||||||
|
} // namespace grpc
|
||||||
|
|
||||||
|
#endif // GRPCXX_CREATE_CHANNEL_POSIX_H
|
@ -0,0 +1,69 @@ |
|||||||
|
/*
|
||||||
|
* |
||||||
|
* 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. |
||||||
|
* |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef GRPCXX_EXT_PROTO_SERVER_REFLECTION_PLUGIN_H |
||||||
|
#define GRPCXX_EXT_PROTO_SERVER_REFLECTION_PLUGIN_H |
||||||
|
|
||||||
|
#include <grpc++/impl/server_builder_plugin.h> |
||||||
|
#include <grpc++/support/config.h> |
||||||
|
|
||||||
|
namespace grpc { |
||||||
|
class ServerInitializer; |
||||||
|
class ProtoServerReflection; |
||||||
|
} // namespace grpc
|
||||||
|
|
||||||
|
namespace grpc { |
||||||
|
namespace reflection { |
||||||
|
|
||||||
|
class ProtoServerReflectionPlugin : public ::grpc::ServerBuilderPlugin { |
||||||
|
public: |
||||||
|
ProtoServerReflectionPlugin(); |
||||||
|
::grpc::string name() GRPC_OVERRIDE; |
||||||
|
void InitServer(::grpc::ServerInitializer* si) GRPC_OVERRIDE; |
||||||
|
void Finish(::grpc::ServerInitializer* si) GRPC_OVERRIDE; |
||||||
|
void ChangeArguments(const ::grpc::string& name, void* value) GRPC_OVERRIDE; |
||||||
|
bool has_async_methods() const GRPC_OVERRIDE; |
||||||
|
bool has_sync_methods() const GRPC_OVERRIDE; |
||||||
|
|
||||||
|
private: |
||||||
|
std::shared_ptr<::grpc::ProtoServerReflection> reflection_service_; |
||||||
|
}; |
||||||
|
|
||||||
|
// Add proto reflection plugin to ServerBuilder. This function should be called
|
||||||
|
// at the static initialization time.
|
||||||
|
void InitProtoReflectionServerBuilderPlugin(); |
||||||
|
|
||||||
|
} // namespace reflection
|
||||||
|
} // namespace grpc
|
||||||
|
|
||||||
|
#endif // GRPCXX_EXT_PROTO_SERVER_REFLECTION_PLUGIN_H
|
@ -0,0 +1,184 @@ |
|||||||
|
/*
|
||||||
|
* |
||||||
|
* 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. |
||||||
|
* |
||||||
|
*/ |
||||||
|
|
||||||
|
|
||||||
|
// Generated by the gRPC protobuf plugin.
|
||||||
|
// If you make any local change, they will be lost.
|
||||||
|
// source: reflection.proto
|
||||||
|
// Original file comments:
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
// Service exported by server reflection
|
||||||
|
//
|
||||||
|
#ifndef GRPC_reflection_2eproto__INCLUDED |
||||||
|
#define GRPC_reflection_2eproto__INCLUDED |
||||||
|
|
||||||
|
#include <grpc++/ext/reflection.pb.h> |
||||||
|
|
||||||
|
#include <grpc++/impl/codegen/async_stream.h> |
||||||
|
#include <grpc++/impl/codegen/async_unary_call.h> |
||||||
|
#include <grpc++/impl/codegen/proto_utils.h> |
||||||
|
#include <grpc++/impl/codegen/rpc_method.h> |
||||||
|
#include <grpc++/impl/codegen/service_type.h> |
||||||
|
#include <grpc++/impl/codegen/status.h> |
||||||
|
#include <grpc++/impl/codegen/stub_options.h> |
||||||
|
#include <grpc++/impl/codegen/sync_stream.h> |
||||||
|
|
||||||
|
namespace grpc { |
||||||
|
class CompletionQueue; |
||||||
|
class Channel; |
||||||
|
class RpcService; |
||||||
|
class ServerCompletionQueue; |
||||||
|
class ServerContext; |
||||||
|
} // namespace grpc
|
||||||
|
|
||||||
|
namespace grpc { |
||||||
|
namespace reflection { |
||||||
|
namespace v1alpha { |
||||||
|
|
||||||
|
class ServerReflection GRPC_FINAL { |
||||||
|
public: |
||||||
|
class StubInterface { |
||||||
|
public: |
||||||
|
virtual ~StubInterface() {} |
||||||
|
// The reflection service is structured as a bidirectional stream, ensuring
|
||||||
|
// all related requests go to a single server.
|
||||||
|
std::unique_ptr< ::grpc::ClientReaderWriterInterface< ::grpc::reflection::v1alpha::ServerReflectionRequest, ::grpc::reflection::v1alpha::ServerReflectionResponse>> ServerReflectionInfo(::grpc::ClientContext* context) { |
||||||
|
return std::unique_ptr< ::grpc::ClientReaderWriterInterface< ::grpc::reflection::v1alpha::ServerReflectionRequest, ::grpc::reflection::v1alpha::ServerReflectionResponse>>(ServerReflectionInfoRaw(context)); |
||||||
|
} |
||||||
|
std::unique_ptr< ::grpc::ClientAsyncReaderWriterInterface< ::grpc::reflection::v1alpha::ServerReflectionRequest, ::grpc::reflection::v1alpha::ServerReflectionResponse>> AsyncServerReflectionInfo(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag) { |
||||||
|
return std::unique_ptr< ::grpc::ClientAsyncReaderWriterInterface< ::grpc::reflection::v1alpha::ServerReflectionRequest, ::grpc::reflection::v1alpha::ServerReflectionResponse>>(AsyncServerReflectionInfoRaw(context, cq, tag)); |
||||||
|
} |
||||||
|
private: |
||||||
|
virtual ::grpc::ClientReaderWriterInterface< ::grpc::reflection::v1alpha::ServerReflectionRequest, ::grpc::reflection::v1alpha::ServerReflectionResponse>* ServerReflectionInfoRaw(::grpc::ClientContext* context) = 0; |
||||||
|
virtual ::grpc::ClientAsyncReaderWriterInterface< ::grpc::reflection::v1alpha::ServerReflectionRequest, ::grpc::reflection::v1alpha::ServerReflectionResponse>* AsyncServerReflectionInfoRaw(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag) = 0; |
||||||
|
}; |
||||||
|
class Stub GRPC_FINAL : public StubInterface { |
||||||
|
public: |
||||||
|
Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel); |
||||||
|
std::unique_ptr< ::grpc::ClientReaderWriter< ::grpc::reflection::v1alpha::ServerReflectionRequest, ::grpc::reflection::v1alpha::ServerReflectionResponse>> ServerReflectionInfo(::grpc::ClientContext* context) { |
||||||
|
return std::unique_ptr< ::grpc::ClientReaderWriter< ::grpc::reflection::v1alpha::ServerReflectionRequest, ::grpc::reflection::v1alpha::ServerReflectionResponse>>(ServerReflectionInfoRaw(context)); |
||||||
|
} |
||||||
|
std::unique_ptr< ::grpc::ClientAsyncReaderWriter< ::grpc::reflection::v1alpha::ServerReflectionRequest, ::grpc::reflection::v1alpha::ServerReflectionResponse>> AsyncServerReflectionInfo(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag) { |
||||||
|
return std::unique_ptr< ::grpc::ClientAsyncReaderWriter< ::grpc::reflection::v1alpha::ServerReflectionRequest, ::grpc::reflection::v1alpha::ServerReflectionResponse>>(AsyncServerReflectionInfoRaw(context, cq, tag)); |
||||||
|
} |
||||||
|
|
||||||
|
private: |
||||||
|
std::shared_ptr< ::grpc::ChannelInterface> channel_; |
||||||
|
::grpc::ClientReaderWriter< ::grpc::reflection::v1alpha::ServerReflectionRequest, ::grpc::reflection::v1alpha::ServerReflectionResponse>* ServerReflectionInfoRaw(::grpc::ClientContext* context) GRPC_OVERRIDE; |
||||||
|
::grpc::ClientAsyncReaderWriter< ::grpc::reflection::v1alpha::ServerReflectionRequest, ::grpc::reflection::v1alpha::ServerReflectionResponse>* AsyncServerReflectionInfoRaw(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag) GRPC_OVERRIDE; |
||||||
|
const ::grpc::RpcMethod rpcmethod_ServerReflectionInfo_; |
||||||
|
}; |
||||||
|
static std::unique_ptr<Stub> NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options = ::grpc::StubOptions()); |
||||||
|
|
||||||
|
class Service : public ::grpc::Service { |
||||||
|
public: |
||||||
|
Service(); |
||||||
|
virtual ~Service(); |
||||||
|
// The reflection service is structured as a bidirectional stream, ensuring
|
||||||
|
// all related requests go to a single server.
|
||||||
|
virtual ::grpc::Status ServerReflectionInfo(::grpc::ServerContext* context, ::grpc::ServerReaderWriter< ::grpc::reflection::v1alpha::ServerReflectionResponse, ::grpc::reflection::v1alpha::ServerReflectionRequest>* stream); |
||||||
|
}; |
||||||
|
template <class BaseClass> |
||||||
|
class WithAsyncMethod_ServerReflectionInfo : public BaseClass { |
||||||
|
private: |
||||||
|
void BaseClassMustBeDerivedFromService(const Service *service) {} |
||||||
|
public: |
||||||
|
WithAsyncMethod_ServerReflectionInfo() { |
||||||
|
::grpc::Service::MarkMethodAsync(0); |
||||||
|
} |
||||||
|
~WithAsyncMethod_ServerReflectionInfo() GRPC_OVERRIDE { |
||||||
|
BaseClassMustBeDerivedFromService(this); |
||||||
|
} |
||||||
|
// disable synchronous version of this method
|
||||||
|
::grpc::Status ServerReflectionInfo(::grpc::ServerContext* context, ::grpc::ServerReaderWriter< ::grpc::reflection::v1alpha::ServerReflectionResponse, ::grpc::reflection::v1alpha::ServerReflectionRequest>* stream) GRPC_FINAL GRPC_OVERRIDE { |
||||||
|
abort(); |
||||||
|
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); |
||||||
|
} |
||||||
|
void RequestServerReflectionInfo(::grpc::ServerContext* context, ::grpc::ServerAsyncReaderWriter< ::grpc::reflection::v1alpha::ServerReflectionResponse, ::grpc::reflection::v1alpha::ServerReflectionRequest>* stream, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { |
||||||
|
::grpc::Service::RequestAsyncBidiStreaming(0, context, stream, new_call_cq, notification_cq, tag); |
||||||
|
} |
||||||
|
}; |
||||||
|
typedef WithAsyncMethod_ServerReflectionInfo<Service > AsyncService; |
||||||
|
template <class BaseClass> |
||||||
|
class WithGenericMethod_ServerReflectionInfo : public BaseClass { |
||||||
|
private: |
||||||
|
void BaseClassMustBeDerivedFromService(const Service *service) {} |
||||||
|
public: |
||||||
|
WithGenericMethod_ServerReflectionInfo() { |
||||||
|
::grpc::Service::MarkMethodGeneric(0); |
||||||
|
} |
||||||
|
~WithGenericMethod_ServerReflectionInfo() GRPC_OVERRIDE { |
||||||
|
BaseClassMustBeDerivedFromService(this); |
||||||
|
} |
||||||
|
// disable synchronous version of this method
|
||||||
|
::grpc::Status ServerReflectionInfo(::grpc::ServerContext* context, ::grpc::ServerReaderWriter< ::grpc::reflection::v1alpha::ServerReflectionResponse, ::grpc::reflection::v1alpha::ServerReflectionRequest>* stream) GRPC_FINAL GRPC_OVERRIDE { |
||||||
|
abort(); |
||||||
|
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); |
||||||
|
} |
||||||
|
}; |
||||||
|
}; |
||||||
|
|
||||||
|
} // namespace v1alpha
|
||||||
|
} // namespace reflection
|
||||||
|
} // namespace grpc
|
||||||
|
|
||||||
|
|
||||||
|
#endif // GRPC_reflection_2eproto__INCLUDED
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,56 @@ |
|||||||
|
/*
|
||||||
|
* |
||||||
|
* 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_SERVER_POSIX_H |
||||||
|
#define GRPCXX_SERVER_POSIX_H |
||||||
|
|
||||||
|
#include <memory> |
||||||
|
|
||||||
|
#include <grpc++/server.h> |
||||||
|
#include <grpc/support/port_platform.h> |
||||||
|
|
||||||
|
namespace grpc { |
||||||
|
|
||||||
|
#ifdef GPR_SUPPORT_CHANNELS_FROM_FD |
||||||
|
|
||||||
|
/// Adds new client to a \a Server communicating over given file descriptor
|
||||||
|
///
|
||||||
|
/// \param server The server to add a client to.
|
||||||
|
/// \param fd The file descriptor representing a socket.
|
||||||
|
void AddInsecureChannelFromFd(Server* server, int fd); |
||||||
|
|
||||||
|
#endif // GPR_SUPPORT_CHANNELS_FROM_FD
|
||||||
|
|
||||||
|
} // namespace grpc
|
||||||
|
|
||||||
|
#endif // GRPCXX_SERVER_POSIX_H
|
@ -0,0 +1,70 @@ |
|||||||
|
/*
|
||||||
|
* |
||||||
|
* 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_GRPC_POSIX_H |
||||||
|
#define GRPC_GRPC_POSIX_H |
||||||
|
|
||||||
|
#include <grpc/impl/codegen/grpc_types.h> |
||||||
|
#include <grpc/support/port_platform.h> |
||||||
|
|
||||||
|
#include <stddef.h> |
||||||
|
|
||||||
|
#ifdef __cplusplus |
||||||
|
extern "C" { |
||||||
|
#endif |
||||||
|
|
||||||
|
/*! \mainpage GRPC Core POSIX
|
||||||
|
* |
||||||
|
* The GRPC Core POSIX library provides some POSIX-specific low-level |
||||||
|
* functionality on top of GRPC Core. |
||||||
|
*/ |
||||||
|
|
||||||
|
/** Create a client channel to 'target' using file descriptor 'fd'. The 'target'
|
||||||
|
argument will be used to indicate the name for this channel. See the comment |
||||||
|
for grpc_insecure_channel_create for description of 'args' argument. */ |
||||||
|
GRPCAPI grpc_channel *grpc_insecure_channel_create_from_fd( |
||||||
|
const char *target, int fd, const grpc_channel_args *args); |
||||||
|
|
||||||
|
/** Add the connected communication channel based on file descriptor 'fd' to the
|
||||||
|
'server'. The 'fd' must be an open file descriptor corresponding to a |
||||||
|
connected socket. The 'cq' is a completion queue that will be getting events |
||||||
|
from that descriptor. */ |
||||||
|
GRPCAPI void grpc_server_add_insecure_channel_from_fd(grpc_server *server, |
||||||
|
grpc_completion_queue *cq, |
||||||
|
int fd); |
||||||
|
|
||||||
|
#ifdef __cplusplus |
||||||
|
} |
||||||
|
#endif |
||||||
|
|
||||||
|
#endif /* GRPC_GRPC_POSIX_H */ |
@ -0,0 +1,95 @@ |
|||||||
|
/*
|
||||||
|
* |
||||||
|
* 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/grpc.h> |
||||||
|
#include <grpc/grpc_posix.h> |
||||||
|
#include <grpc/support/log.h> |
||||||
|
#include <grpc/support/port_platform.h> |
||||||
|
|
||||||
|
#ifdef GPR_SUPPORT_CHANNELS_FROM_FD |
||||||
|
|
||||||
|
#include <fcntl.h> |
||||||
|
|
||||||
|
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" |
||||||
|
#include "src/core/lib/channel/channel_args.h" |
||||||
|
#include "src/core/lib/iomgr/endpoint.h" |
||||||
|
#include "src/core/lib/iomgr/exec_ctx.h" |
||||||
|
#include "src/core/lib/iomgr/tcp_posix.h" |
||||||
|
#include "src/core/lib/surface/api_trace.h" |
||||||
|
#include "src/core/lib/surface/channel.h" |
||||||
|
#include "src/core/lib/transport/transport.h" |
||||||
|
|
||||||
|
grpc_channel *grpc_insecure_channel_create_from_fd( |
||||||
|
const char *target, int fd, const grpc_channel_args *args) { |
||||||
|
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
||||||
|
GRPC_API_TRACE("grpc_insecure_channel_create(target=%p, fd=%d, args=%p)", 3, |
||||||
|
(target, fd, args)); |
||||||
|
|
||||||
|
grpc_arg default_authority_arg; |
||||||
|
default_authority_arg.type = GRPC_ARG_STRING; |
||||||
|
default_authority_arg.key = GRPC_ARG_DEFAULT_AUTHORITY; |
||||||
|
default_authority_arg.value.string = "test.authority"; |
||||||
|
grpc_channel_args *final_args = |
||||||
|
grpc_channel_args_copy_and_add(args, &default_authority_arg, 1); |
||||||
|
|
||||||
|
int flags = fcntl(fd, F_GETFL, 0); |
||||||
|
GPR_ASSERT(fcntl(fd, F_SETFL, flags | O_NONBLOCK) == 0); |
||||||
|
|
||||||
|
grpc_endpoint *client = |
||||||
|
grpc_tcp_create(grpc_fd_create(fd, "client"), |
||||||
|
GRPC_TCP_DEFAULT_READ_SLICE_SIZE, "fd-client"); |
||||||
|
|
||||||
|
grpc_transport *transport = |
||||||
|
grpc_create_chttp2_transport(&exec_ctx, final_args, client, 1); |
||||||
|
GPR_ASSERT(transport); |
||||||
|
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_exec_ctx_finish(&exec_ctx); |
||||||
|
|
||||||
|
return channel != NULL ? channel : grpc_lame_client_channel_create( |
||||||
|
target, GRPC_STATUS_INTERNAL, |
||||||
|
"Failed to create client channel"); |
||||||
|
} |
||||||
|
|
||||||
|
#else // !GPR_SUPPORT_CHANNELS_FROM_FD
|
||||||
|
|
||||||
|
grpc_channel *grpc_insecure_channel_create_from_fd( |
||||||
|
const char *target, int fd, const grpc_channel_args *args) { |
||||||
|
GPR_ASSERT(0); |
||||||
|
return NULL; |
||||||
|
} |
||||||
|
|
||||||
|
#endif // GPR_SUPPORT_CHANNELS_FROM_FD
|
@ -0,0 +1,82 @@ |
|||||||
|
/*
|
||||||
|
* |
||||||
|
* 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/grpc.h> |
||||||
|
#include <grpc/grpc_posix.h> |
||||||
|
#include <grpc/support/log.h> |
||||||
|
#include <grpc/support/port_platform.h> |
||||||
|
|
||||||
|
#ifdef GPR_SUPPORT_CHANNELS_FROM_FD |
||||||
|
|
||||||
|
#include <grpc/support/alloc.h> |
||||||
|
#include <grpc/support/string_util.h> |
||||||
|
|
||||||
|
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" |
||||||
|
#include "src/core/lib/channel/channel_args.h" |
||||||
|
#include "src/core/lib/iomgr/endpoint.h" |
||||||
|
#include "src/core/lib/iomgr/exec_ctx.h" |
||||||
|
#include "src/core/lib/iomgr/tcp_posix.h" |
||||||
|
#include "src/core/lib/surface/completion_queue.h" |
||||||
|
#include "src/core/lib/surface/server.h" |
||||||
|
|
||||||
|
void grpc_server_add_insecure_channel_from_fd(grpc_server *server, |
||||||
|
grpc_completion_queue *cq, |
||||||
|
int fd) { |
||||||
|
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
||||||
|
|
||||||
|
char *name; |
||||||
|
gpr_asprintf(&name, "fd:%d", fd); |
||||||
|
|
||||||
|
grpc_endpoint *server_endpoint = grpc_tcp_create( |
||||||
|
grpc_fd_create(fd, name), GRPC_TCP_DEFAULT_READ_SLICE_SIZE, name); |
||||||
|
|
||||||
|
gpr_free(name); |
||||||
|
|
||||||
|
const grpc_channel_args *server_args = grpc_server_get_channel_args(server); |
||||||
|
grpc_transport *transport = grpc_create_chttp2_transport( |
||||||
|
&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_exec_ctx_finish(&exec_ctx); |
||||||
|
} |
||||||
|
|
||||||
|
#else // !GPR_SUPPORT_CHANNELS_FROM_FD
|
||||||
|
|
||||||
|
void grpc_server_add_insecure_channel_from_fd(grpc_server *server, |
||||||
|
grpc_completion_queue *cq, |
||||||
|
int fd) { |
||||||
|
GPR_ASSERT(0); |
||||||
|
} |
||||||
|
|
||||||
|
#endif // GPR_SUPPORT_CHANNELS_FROM_FD
|
@ -0,0 +1,232 @@ |
|||||||
|
/*
|
||||||
|
* |
||||||
|
* 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/ext/transport/chttp2/transport/bin_decoder.h" |
||||||
|
#include <grpc/support/alloc.h> |
||||||
|
#include <grpc/support/log.h> |
||||||
|
#include "src/core/lib/support/string.h" |
||||||
|
|
||||||
|
static uint8_t decode_table[] = { |
||||||
|
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, |
||||||
|
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, |
||||||
|
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, |
||||||
|
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 62, 0x40, 0x40, 0x40, 63, |
||||||
|
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0x40, 0x40, |
||||||
|
0x40, 0x40, 0x40, 0x40, 0x40, 0, 1, 2, 3, 4, 5, 6, |
||||||
|
7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, |
||||||
|
19, 20, 21, 22, 23, 24, 25, 0x40, 0x40, 0x40, 0x40, 0x40, |
||||||
|
0x40, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, |
||||||
|
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, |
||||||
|
49, 50, 51, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, |
||||||
|
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, |
||||||
|
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, |
||||||
|
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, |
||||||
|
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, |
||||||
|
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, |
||||||
|
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, |
||||||
|
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, |
||||||
|
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, |
||||||
|
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, |
||||||
|
0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, |
||||||
|
0x40, 0x40, 0x40, 0x40}; |
||||||
|
|
||||||
|
static const uint8_t tail_xtra[4] = {0, 0, 1, 2}; |
||||||
|
|
||||||
|
static bool input_is_valid(uint8_t *input_ptr, size_t length) { |
||||||
|
size_t i; |
||||||
|
|
||||||
|
for (i = 0; i < length; ++i) { |
||||||
|
if ((decode_table[input_ptr[i]] & 0xC0) != 0) { |
||||||
|
gpr_log(GPR_ERROR, |
||||||
|
"Base64 decoding failed, invalid character '%c' in base64 " |
||||||
|
"input.\n", |
||||||
|
(char)(*input_ptr)); |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
#define COMPOSE_OUTPUT_BYTE_0(input_ptr) \ |
||||||
|
(uint8_t)((decode_table[input_ptr[0]] << 2) | \
|
||||||
|
(decode_table[input_ptr[1]] >> 4)) |
||||||
|
|
||||||
|
#define COMPOSE_OUTPUT_BYTE_1(input_ptr) \ |
||||||
|
(uint8_t)((decode_table[input_ptr[1]] << 4) | \
|
||||||
|
(decode_table[input_ptr[2]] >> 2)) |
||||||
|
|
||||||
|
#define COMPOSE_OUTPUT_BYTE_2(input_ptr) \ |
||||||
|
(uint8_t)((decode_table[input_ptr[2]] << 6) | decode_table[input_ptr[3]]) |
||||||
|
|
||||||
|
bool grpc_base64_decode_partial(struct grpc_base64_decode_context *ctx) { |
||||||
|
size_t input_tail; |
||||||
|
|
||||||
|
if (ctx->input_cur > ctx->input_end || ctx->output_cur > ctx->output_end) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
// Process a block of 4 input characters and 3 output bytes
|
||||||
|
while (ctx->input_end >= ctx->input_cur + 4 && |
||||||
|
ctx->output_end >= ctx->output_cur + 3) { |
||||||
|
if (!input_is_valid(ctx->input_cur, 4)) return false; |
||||||
|
ctx->output_cur[0] = COMPOSE_OUTPUT_BYTE_0(ctx->input_cur); |
||||||
|
ctx->output_cur[1] = COMPOSE_OUTPUT_BYTE_1(ctx->input_cur); |
||||||
|
ctx->output_cur[2] = COMPOSE_OUTPUT_BYTE_2(ctx->input_cur); |
||||||
|
ctx->output_cur += 3; |
||||||
|
ctx->input_cur += 4; |
||||||
|
} |
||||||
|
|
||||||
|
// Process the tail of input data
|
||||||
|
input_tail = (size_t)(ctx->input_end - ctx->input_cur); |
||||||
|
if (input_tail == 4) { |
||||||
|
// Process the input data with pad chars
|
||||||
|
if (ctx->input_cur[3] == '=') { |
||||||
|
if (ctx->input_cur[2] == '=' && ctx->output_end >= ctx->output_cur + 1) { |
||||||
|
if (!input_is_valid(ctx->input_cur, 2)) return false; |
||||||
|
*(ctx->output_cur++) = COMPOSE_OUTPUT_BYTE_0(ctx->input_cur); |
||||||
|
ctx->input_cur += 4; |
||||||
|
} else if (ctx->output_end >= ctx->output_cur + 2) { |
||||||
|
if (!input_is_valid(ctx->input_cur, 3)) return false; |
||||||
|
*(ctx->output_cur++) = COMPOSE_OUTPUT_BYTE_0(ctx->input_cur); |
||||||
|
*(ctx->output_cur++) = COMPOSE_OUTPUT_BYTE_1(ctx->input_cur); |
||||||
|
; |
||||||
|
ctx->input_cur += 4; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} else if (ctx->contains_tail && input_tail > 1) { |
||||||
|
// Process the input data without pad chars, but constains_tail is set
|
||||||
|
if (ctx->output_end >= ctx->output_cur + tail_xtra[input_tail]) { |
||||||
|
if (!input_is_valid(ctx->input_cur, input_tail)) return false; |
||||||
|
switch (input_tail) { |
||||||
|
case 3: |
||||||
|
ctx->output_cur[1] = COMPOSE_OUTPUT_BYTE_1(ctx->input_cur); |
||||||
|
case 2: |
||||||
|
ctx->output_cur[0] = COMPOSE_OUTPUT_BYTE_0(ctx->input_cur); |
||||||
|
} |
||||||
|
ctx->output_cur += tail_xtra[input_tail]; |
||||||
|
ctx->input_cur += input_tail; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
gpr_slice grpc_chttp2_base64_decode(gpr_slice input) { |
||||||
|
size_t input_length = GPR_SLICE_LENGTH(input); |
||||||
|
size_t output_length = input_length / 4 * 3; |
||||||
|
struct grpc_base64_decode_context ctx; |
||||||
|
gpr_slice output; |
||||||
|
|
||||||
|
if (input_length % 4 != 0) { |
||||||
|
gpr_log(GPR_ERROR, |
||||||
|
"Base64 decoding failed, input of " |
||||||
|
"grpc_chttp2_base64_decode has a length of %d, which is not a " |
||||||
|
"multiple of 4.\n", |
||||||
|
(int)input_length); |
||||||
|
return gpr_empty_slice(); |
||||||
|
} |
||||||
|
|
||||||
|
if (input_length > 0) { |
||||||
|
uint8_t *input_end = GPR_SLICE_END_PTR(input); |
||||||
|
if (*(--input_end) == '=') { |
||||||
|
output_length--; |
||||||
|
if (*(--input_end) == '=') { |
||||||
|
output_length--; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
output = gpr_slice_malloc(output_length); |
||||||
|
|
||||||
|
ctx.input_cur = GPR_SLICE_START_PTR(input); |
||||||
|
ctx.input_end = GPR_SLICE_END_PTR(input); |
||||||
|
ctx.output_cur = GPR_SLICE_START_PTR(output); |
||||||
|
ctx.output_end = GPR_SLICE_END_PTR(output); |
||||||
|
ctx.contains_tail = false; |
||||||
|
|
||||||
|
if (!grpc_base64_decode_partial(&ctx)) { |
||||||
|
char *s = gpr_dump_slice(input, GPR_DUMP_ASCII); |
||||||
|
gpr_log(GPR_ERROR, "Base64 decoding failed, input string:\n%s\n", s); |
||||||
|
gpr_free(s); |
||||||
|
gpr_slice_unref(output); |
||||||
|
return gpr_empty_slice(); |
||||||
|
} |
||||||
|
GPR_ASSERT(ctx.output_cur == GPR_SLICE_END_PTR(output)); |
||||||
|
GPR_ASSERT(ctx.input_cur == GPR_SLICE_END_PTR(input)); |
||||||
|
return output; |
||||||
|
} |
||||||
|
|
||||||
|
gpr_slice grpc_chttp2_base64_decode_with_length(gpr_slice input, |
||||||
|
size_t output_length) { |
||||||
|
size_t input_length = GPR_SLICE_LENGTH(input); |
||||||
|
gpr_slice output = gpr_slice_malloc(output_length); |
||||||
|
struct grpc_base64_decode_context ctx; |
||||||
|
|
||||||
|
// The length of a base64 string cannot be 4 * n + 1
|
||||||
|
if (input_length % 4 == 1) { |
||||||
|
gpr_log(GPR_ERROR, |
||||||
|
"Base64 decoding failed, input of " |
||||||
|
"grpc_chttp2_base64_decode_with_length has a length of %d, which " |
||||||
|
"has a tail of 1 byte.\n", |
||||||
|
(int)input_length); |
||||||
|
gpr_slice_unref(output); |
||||||
|
return gpr_empty_slice(); |
||||||
|
} |
||||||
|
|
||||||
|
if (output_length > input_length / 4 * 3 + tail_xtra[input_length % 4]) { |
||||||
|
gpr_log(GPR_ERROR, |
||||||
|
"Base64 decoding failed, output_length %d is longer " |
||||||
|
"than the max possible output length %d.\n", |
||||||
|
(int)output_length, |
||||||
|
(int)(input_length / 4 * 3 + tail_xtra[input_length % 4])); |
||||||
|
gpr_slice_unref(output); |
||||||
|
return gpr_empty_slice(); |
||||||
|
} |
||||||
|
|
||||||
|
ctx.input_cur = GPR_SLICE_START_PTR(input); |
||||||
|
ctx.input_end = GPR_SLICE_END_PTR(input); |
||||||
|
ctx.output_cur = GPR_SLICE_START_PTR(output); |
||||||
|
ctx.output_end = GPR_SLICE_END_PTR(output); |
||||||
|
ctx.contains_tail = true; |
||||||
|
|
||||||
|
if (!grpc_base64_decode_partial(&ctx)) { |
||||||
|
char *s = gpr_dump_slice(input, GPR_DUMP_ASCII); |
||||||
|
gpr_log(GPR_ERROR, "Base64 decoding failed, input string:\n%s\n", s); |
||||||
|
gpr_free(s); |
||||||
|
gpr_slice_unref(output); |
||||||
|
return gpr_empty_slice(); |
||||||
|
} |
||||||
|
GPR_ASSERT(ctx.output_cur == GPR_SLICE_END_PTR(output)); |
||||||
|
GPR_ASSERT(ctx.input_cur <= GPR_SLICE_END_PTR(input)); |
||||||
|
return output; |
||||||
|
} |
@ -0,0 +1,66 @@ |
|||||||
|
/*
|
||||||
|
* |
||||||
|
* 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_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_BIN_DECODER_H |
||||||
|
#define GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_BIN_DECODER_H |
||||||
|
|
||||||
|
#include <grpc/support/slice.h> |
||||||
|
#include <stdbool.h> |
||||||
|
|
||||||
|
struct grpc_base64_decode_context { |
||||||
|
/* input/output: */ |
||||||
|
uint8_t *input_cur; |
||||||
|
uint8_t *input_end; |
||||||
|
uint8_t *output_cur; |
||||||
|
uint8_t *output_end; |
||||||
|
/* Indicate if the decoder should handle the tail of input data*/ |
||||||
|
bool contains_tail; |
||||||
|
}; |
||||||
|
|
||||||
|
/* base64 decode a grpc_base64_decode_context util either input_end is reached
|
||||||
|
or output_end is reached. When input_end is reached, (input_end - input_cur) |
||||||
|
is less than 4. When output_end is reached, (output_end - output_cur) is less |
||||||
|
than 3. Returns false if decoding is failed. */ |
||||||
|
bool grpc_base64_decode_partial(struct grpc_base64_decode_context *ctx); |
||||||
|
|
||||||
|
/* base64 decode a slice with pad chars. Returns a new slice, does not take
|
||||||
|
ownership of the input. Returns an empty slice if decoding is failed. */ |
||||||
|
gpr_slice grpc_chttp2_base64_decode(gpr_slice input); |
||||||
|
|
||||||
|
/* base64 decode a slice without pad chars, data length is needed. Returns a new
|
||||||
|
slice, does not take ownership of the input. Returns an empty slice if |
||||||
|
decoding is failed. */ |
||||||
|
gpr_slice grpc_chttp2_base64_decode_with_length(gpr_slice input, |
||||||
|
size_t output_length); |
||||||
|
|
||||||
|
#endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_BIN_DECODER_H */ |
@ -0,0 +1,56 @@ |
|||||||
|
/*
|
||||||
|
* |
||||||
|
* 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++/channel.h> |
||||||
|
#include <grpc++/create_channel.h> |
||||||
|
#include <grpc++/impl/grpc_library.h> |
||||||
|
#include <grpc/grpc.h> |
||||||
|
#include <grpc/grpc_posix.h> |
||||||
|
|
||||||
|
#include "src/cpp/client/create_channel_internal.h" |
||||||
|
|
||||||
|
namespace grpc { |
||||||
|
|
||||||
|
#ifdef GPR_SUPPORT_CHANNELS_FROM_FD |
||||||
|
|
||||||
|
std::shared_ptr<Channel> CreateInsecureChannelFromFd(const grpc::string& target, |
||||||
|
int fd) { |
||||||
|
internal::GrpcLibrary init_lib; |
||||||
|
init_lib.init(); |
||||||
|
return CreateChannelInternal( |
||||||
|
"", grpc_insecure_channel_create_from_fd(target.c_str(), fd, nullptr)); |
||||||
|
} |
||||||
|
|
||||||
|
#endif // GPR_SUPPORT_CHANNELS_FROM_FD
|
||||||
|
|
||||||
|
} // namespace grpc
|
@ -0,0 +1,227 @@ |
|||||||
|
/*
|
||||||
|
* |
||||||
|
* 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 <unordered_set> |
||||||
|
#include <vector> |
||||||
|
|
||||||
|
#include <grpc++/grpc++.h> |
||||||
|
|
||||||
|
#include "src/cpp/ext/proto_server_reflection.h" |
||||||
|
|
||||||
|
using grpc::Status; |
||||||
|
using grpc::StatusCode; |
||||||
|
using grpc::reflection::v1alpha::ServerReflectionRequest; |
||||||
|
using grpc::reflection::v1alpha::ExtensionRequest; |
||||||
|
using grpc::reflection::v1alpha::ServerReflectionResponse; |
||||||
|
using grpc::reflection::v1alpha::ListServiceResponse; |
||||||
|
using grpc::reflection::v1alpha::ServiceResponse; |
||||||
|
using grpc::reflection::v1alpha::ExtensionNumberResponse; |
||||||
|
using grpc::reflection::v1alpha::ErrorResponse; |
||||||
|
using grpc::reflection::v1alpha::FileDescriptorResponse; |
||||||
|
|
||||||
|
namespace grpc { |
||||||
|
|
||||||
|
ProtoServerReflection::ProtoServerReflection() |
||||||
|
: descriptor_pool_(protobuf::DescriptorPool::generated_pool()) {} |
||||||
|
|
||||||
|
void ProtoServerReflection::SetServiceList( |
||||||
|
const std::vector<grpc::string>* services) { |
||||||
|
services_ = services; |
||||||
|
} |
||||||
|
|
||||||
|
Status ProtoServerReflection::ServerReflectionInfo( |
||||||
|
ServerContext* context, |
||||||
|
ServerReaderWriter<ServerReflectionResponse, ServerReflectionRequest>* |
||||||
|
stream) { |
||||||
|
ServerReflectionRequest request; |
||||||
|
ServerReflectionResponse response; |
||||||
|
Status status; |
||||||
|
while (stream->Read(&request)) { |
||||||
|
switch (request.message_request_case()) { |
||||||
|
case ServerReflectionRequest::MessageRequestCase::kFileByFilename: |
||||||
|
status = GetFileByName(context, request.file_by_filename(), &response); |
||||||
|
break; |
||||||
|
case ServerReflectionRequest::MessageRequestCase::kFileContainingSymbol: |
||||||
|
status = GetFileContainingSymbol( |
||||||
|
context, request.file_containing_symbol(), &response); |
||||||
|
break; |
||||||
|
case ServerReflectionRequest::MessageRequestCase:: |
||||||
|
kFileContainingExtension: |
||||||
|
status = GetFileContainingExtension( |
||||||
|
context, &request.file_containing_extension(), &response); |
||||||
|
break; |
||||||
|
case ServerReflectionRequest::MessageRequestCase:: |
||||||
|
kAllExtensionNumbersOfType: |
||||||
|
status = GetAllExtensionNumbers( |
||||||
|
context, request.all_extension_numbers_of_type(), |
||||||
|
response.mutable_all_extension_numbers_response()); |
||||||
|
break; |
||||||
|
case ServerReflectionRequest::MessageRequestCase::kListServices: |
||||||
|
status = |
||||||
|
ListService(context, response.mutable_list_services_response()); |
||||||
|
break; |
||||||
|
default: |
||||||
|
status = Status(StatusCode::UNIMPLEMENTED, ""); |
||||||
|
} |
||||||
|
|
||||||
|
if (!status.ok()) { |
||||||
|
FillErrorResponse(status, response.mutable_error_response()); |
||||||
|
} |
||||||
|
response.set_valid_host(request.host()); |
||||||
|
response.set_allocated_original_request( |
||||||
|
new ServerReflectionRequest(request)); |
||||||
|
stream->Write(response); |
||||||
|
} |
||||||
|
|
||||||
|
return Status::OK; |
||||||
|
} |
||||||
|
|
||||||
|
void ProtoServerReflection::FillErrorResponse(const Status& status, |
||||||
|
ErrorResponse* error_response) { |
||||||
|
error_response->set_error_code(status.error_code()); |
||||||
|
error_response->set_error_message(status.error_message()); |
||||||
|
} |
||||||
|
|
||||||
|
Status ProtoServerReflection::ListService(ServerContext* context, |
||||||
|
ListServiceResponse* response) { |
||||||
|
if (services_ == nullptr) { |
||||||
|
return Status(StatusCode::NOT_FOUND, "Services not found."); |
||||||
|
} |
||||||
|
for (auto it = services_->begin(); it != services_->end(); ++it) { |
||||||
|
ServiceResponse* service_response = response->add_service(); |
||||||
|
service_response->set_name(*it); |
||||||
|
} |
||||||
|
return Status::OK; |
||||||
|
} |
||||||
|
|
||||||
|
Status ProtoServerReflection::GetFileByName( |
||||||
|
ServerContext* context, const grpc::string& filename, |
||||||
|
ServerReflectionResponse* response) { |
||||||
|
if (descriptor_pool_ == nullptr) { |
||||||
|
return Status::CANCELLED; |
||||||
|
} |
||||||
|
|
||||||
|
const protobuf::FileDescriptor* file_desc = |
||||||
|
descriptor_pool_->FindFileByName(filename); |
||||||
|
if (file_desc == nullptr) { |
||||||
|
return Status(StatusCode::NOT_FOUND, "File not found."); |
||||||
|
} |
||||||
|
std::unordered_set<grpc::string> seen_files; |
||||||
|
FillFileDescriptorResponse(file_desc, response, &seen_files); |
||||||
|
return Status::OK; |
||||||
|
} |
||||||
|
|
||||||
|
Status ProtoServerReflection::GetFileContainingSymbol( |
||||||
|
ServerContext* context, const grpc::string& symbol, |
||||||
|
ServerReflectionResponse* response) { |
||||||
|
if (descriptor_pool_ == nullptr) { |
||||||
|
return Status::CANCELLED; |
||||||
|
} |
||||||
|
|
||||||
|
const protobuf::FileDescriptor* file_desc = |
||||||
|
descriptor_pool_->FindFileContainingSymbol(symbol); |
||||||
|
if (file_desc == nullptr) { |
||||||
|
return Status(StatusCode::NOT_FOUND, "Symbol not found."); |
||||||
|
} |
||||||
|
std::unordered_set<grpc::string> seen_files; |
||||||
|
FillFileDescriptorResponse(file_desc, response, &seen_files); |
||||||
|
return Status::OK; |
||||||
|
} |
||||||
|
|
||||||
|
Status ProtoServerReflection::GetFileContainingExtension( |
||||||
|
ServerContext* context, const ExtensionRequest* request, |
||||||
|
ServerReflectionResponse* response) { |
||||||
|
if (descriptor_pool_ == nullptr) { |
||||||
|
return Status::CANCELLED; |
||||||
|
} |
||||||
|
|
||||||
|
const protobuf::Descriptor* desc = |
||||||
|
descriptor_pool_->FindMessageTypeByName(request->containing_type()); |
||||||
|
if (desc == nullptr) { |
||||||
|
return Status(StatusCode::NOT_FOUND, "Type not found."); |
||||||
|
} |
||||||
|
|
||||||
|
const protobuf::FieldDescriptor* field_desc = |
||||||
|
descriptor_pool_->FindExtensionByNumber(desc, |
||||||
|
request->extension_number()); |
||||||
|
if (field_desc == nullptr) { |
||||||
|
return Status(StatusCode::NOT_FOUND, "Extension not found."); |
||||||
|
} |
||||||
|
std::unordered_set<grpc::string> seen_files; |
||||||
|
FillFileDescriptorResponse(field_desc->file(), response, &seen_files); |
||||||
|
return Status::OK; |
||||||
|
} |
||||||
|
|
||||||
|
Status ProtoServerReflection::GetAllExtensionNumbers( |
||||||
|
ServerContext* context, const grpc::string& type, |
||||||
|
ExtensionNumberResponse* response) { |
||||||
|
if (descriptor_pool_ == nullptr) { |
||||||
|
return Status::CANCELLED; |
||||||
|
} |
||||||
|
|
||||||
|
const protobuf::Descriptor* desc = |
||||||
|
descriptor_pool_->FindMessageTypeByName(type); |
||||||
|
if (desc == nullptr) { |
||||||
|
return Status(StatusCode::NOT_FOUND, "Type not found."); |
||||||
|
} |
||||||
|
|
||||||
|
std::vector<const protobuf::FieldDescriptor*> extensions; |
||||||
|
descriptor_pool_->FindAllExtensions(desc, &extensions); |
||||||
|
for (auto extension : extensions) { |
||||||
|
response->add_extension_number(extension->number()); |
||||||
|
} |
||||||
|
response->set_base_type_name(type); |
||||||
|
return Status::OK; |
||||||
|
} |
||||||
|
|
||||||
|
void ProtoServerReflection::FillFileDescriptorResponse( |
||||||
|
const protobuf::FileDescriptor* file_desc, |
||||||
|
ServerReflectionResponse* response, |
||||||
|
std::unordered_set<grpc::string>* seen_files) { |
||||||
|
if (seen_files->find(file_desc->name()) != seen_files->end()) { |
||||||
|
return; |
||||||
|
} |
||||||
|
seen_files->insert(file_desc->name()); |
||||||
|
|
||||||
|
protobuf::FileDescriptorProto file_desc_proto; |
||||||
|
grpc::string data; |
||||||
|
file_desc->CopyTo(&file_desc_proto); |
||||||
|
file_desc_proto.SerializeToString(&data); |
||||||
|
response->mutable_file_descriptor_response()->add_file_descriptor_proto(data); |
||||||
|
|
||||||
|
for (int i = 0; i < file_desc->dependency_count(); ++i) { |
||||||
|
FillFileDescriptorResponse(file_desc->dependency(i), response, seen_files); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} // namespace grpc
|
@ -0,0 +1,94 @@ |
|||||||
|
/*
|
||||||
|
* |
||||||
|
* 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. |
||||||
|
* |
||||||
|
*/ |
||||||
|
#ifndef GRPC_INTERNAL_CPP_EXT_PROTO_SERVER_REFLECTION_H |
||||||
|
#define GRPC_INTERNAL_CPP_EXT_PROTO_SERVER_REFLECTION_H |
||||||
|
|
||||||
|
#include <unordered_set> |
||||||
|
#include <vector> |
||||||
|
|
||||||
|
#include <grpc++/ext/reflection.grpc.pb.h> |
||||||
|
#include <grpc++/grpc++.h> |
||||||
|
|
||||||
|
namespace grpc { |
||||||
|
|
||||||
|
class ProtoServerReflection GRPC_FINAL |
||||||
|
: public reflection::v1alpha::ServerReflection::Service { |
||||||
|
public: |
||||||
|
ProtoServerReflection(); |
||||||
|
|
||||||
|
// Add the full names of registered services
|
||||||
|
void SetServiceList(const std::vector<grpc::string>* services); |
||||||
|
|
||||||
|
// implementation of ServerReflectionInfo(stream ServerReflectionRequest) rpc
|
||||||
|
// in ServerReflection service
|
||||||
|
Status ServerReflectionInfo( |
||||||
|
ServerContext* context, |
||||||
|
ServerReaderWriter<reflection::v1alpha::ServerReflectionResponse, |
||||||
|
reflection::v1alpha::ServerReflectionRequest>* stream) |
||||||
|
GRPC_OVERRIDE; |
||||||
|
|
||||||
|
private: |
||||||
|
Status ListService(ServerContext* context, |
||||||
|
reflection::v1alpha::ListServiceResponse* response); |
||||||
|
|
||||||
|
Status GetFileByName(ServerContext* context, const grpc::string& file_name, |
||||||
|
reflection::v1alpha::ServerReflectionResponse* response); |
||||||
|
|
||||||
|
Status GetFileContainingSymbol( |
||||||
|
ServerContext* context, const grpc::string& symbol, |
||||||
|
reflection::v1alpha::ServerReflectionResponse* response); |
||||||
|
|
||||||
|
Status GetFileContainingExtension( |
||||||
|
ServerContext* context, |
||||||
|
const reflection::v1alpha::ExtensionRequest* request, |
||||||
|
reflection::v1alpha::ServerReflectionResponse* response); |
||||||
|
|
||||||
|
Status GetAllExtensionNumbers( |
||||||
|
ServerContext* context, const grpc::string& type, |
||||||
|
reflection::v1alpha::ExtensionNumberResponse* response); |
||||||
|
|
||||||
|
void FillFileDescriptorResponse( |
||||||
|
const protobuf::FileDescriptor* file_desc, |
||||||
|
reflection::v1alpha::ServerReflectionResponse* response, |
||||||
|
std::unordered_set<grpc::string>* seen_files); |
||||||
|
|
||||||
|
void FillErrorResponse(const Status& status, |
||||||
|
reflection::v1alpha::ErrorResponse* error_response); |
||||||
|
|
||||||
|
const protobuf::DescriptorPool* descriptor_pool_; |
||||||
|
const std::vector<string>* services_; |
||||||
|
}; |
||||||
|
|
||||||
|
} // namespace grpc
|
||||||
|
|
||||||
|
#endif // GRPC_INTERNAL_CPP_EXT_PROTO_SERVER_REFLECTION_H
|
@ -0,0 +1,97 @@ |
|||||||
|
/*
|
||||||
|
* |
||||||
|
* 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++/ext/proto_server_reflection_plugin.h> |
||||||
|
#include <grpc++/impl/server_builder_plugin.h> |
||||||
|
#include <grpc++/impl/server_initializer.h> |
||||||
|
#include <grpc++/server.h> |
||||||
|
|
||||||
|
#include "src/cpp/ext/proto_server_reflection.h" |
||||||
|
|
||||||
|
namespace grpc { |
||||||
|
namespace reflection { |
||||||
|
|
||||||
|
ProtoServerReflectionPlugin::ProtoServerReflectionPlugin() |
||||||
|
: reflection_service_(new grpc::ProtoServerReflection()) {} |
||||||
|
|
||||||
|
grpc::string ProtoServerReflectionPlugin::name() { |
||||||
|
return "proto_server_reflection"; |
||||||
|
} |
||||||
|
|
||||||
|
void ProtoServerReflectionPlugin::InitServer(grpc::ServerInitializer* si) { |
||||||
|
si->RegisterService(reflection_service_); |
||||||
|
} |
||||||
|
|
||||||
|
void ProtoServerReflectionPlugin::Finish(grpc::ServerInitializer* si) { |
||||||
|
reflection_service_->SetServiceList(si->GetServiceList()); |
||||||
|
} |
||||||
|
|
||||||
|
void ProtoServerReflectionPlugin::ChangeArguments(const grpc::string& name, |
||||||
|
void* value) {} |
||||||
|
|
||||||
|
bool ProtoServerReflectionPlugin::has_sync_methods() const { |
||||||
|
if (reflection_service_ != nullptr) { |
||||||
|
return reflection_service_->has_synchronous_methods(); |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
bool ProtoServerReflectionPlugin::has_async_methods() const { |
||||||
|
if (reflection_service_ != nullptr) { |
||||||
|
return reflection_service_->has_async_methods(); |
||||||
|
} |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
static std::unique_ptr<::grpc::ServerBuilderPlugin> CreateProtoReflection() { |
||||||
|
return std::unique_ptr<::grpc::ServerBuilderPlugin>( |
||||||
|
new ProtoServerReflectionPlugin()); |
||||||
|
} |
||||||
|
|
||||||
|
void InitProtoReflectionServerBuilderPlugin() { |
||||||
|
static bool already_here = false; |
||||||
|
if (already_here) return; |
||||||
|
already_here = true; |
||||||
|
::grpc::ServerBuilder::InternalAddPluginFactory(&CreateProtoReflection); |
||||||
|
} |
||||||
|
|
||||||
|
// Force InitProtoReflectionServerBuilderPlugin() to be called at static
|
||||||
|
// initialization time.
|
||||||
|
struct StaticProtoReflectionPluginInitializer { |
||||||
|
StaticProtoReflectionPluginInitializer() { |
||||||
|
InitProtoReflectionServerBuilderPlugin(); |
||||||
|
} |
||||||
|
} static_proto_reflection_plugin_initializer; |
||||||
|
|
||||||
|
} // namespace reflection
|
||||||
|
} // namespace grpc
|
@ -0,0 +1,97 @@ |
|||||||
|
/*
|
||||||
|
* |
||||||
|
* 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. |
||||||
|
* |
||||||
|
*/ |
||||||
|
|
||||||
|
|
||||||
|
// Generated by the gRPC protobuf plugin.
|
||||||
|
// If you make any local change, they will be lost.
|
||||||
|
// source: reflection.proto
|
||||||
|
|
||||||
|
#include <grpc++/ext/reflection.pb.h> |
||||||
|
#include <grpc++/ext/reflection.grpc.pb.h> |
||||||
|
|
||||||
|
#include <grpc++/impl/codegen/async_stream.h> |
||||||
|
#include <grpc++/impl/codegen/async_unary_call.h> |
||||||
|
#include <grpc++/impl/codegen/channel_interface.h> |
||||||
|
#include <grpc++/impl/codegen/client_unary_call.h> |
||||||
|
#include <grpc++/impl/codegen/method_handler_impl.h> |
||||||
|
#include <grpc++/impl/codegen/rpc_service_method.h> |
||||||
|
#include <grpc++/impl/codegen/service_type.h> |
||||||
|
#include <grpc++/impl/codegen/sync_stream.h> |
||||||
|
namespace grpc { |
||||||
|
namespace reflection { |
||||||
|
namespace v1alpha { |
||||||
|
|
||||||
|
static const char* ServerReflection_method_names[] = { |
||||||
|
"/grpc.reflection.v1alpha.ServerReflection/ServerReflectionInfo", |
||||||
|
}; |
||||||
|
|
||||||
|
std::unique_ptr< ServerReflection::Stub> ServerReflection::NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options) { |
||||||
|
std::unique_ptr< ServerReflection::Stub> stub(new ServerReflection::Stub(channel)); |
||||||
|
return stub; |
||||||
|
} |
||||||
|
|
||||||
|
ServerReflection::Stub::Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel) |
||||||
|
: channel_(channel), rpcmethod_ServerReflectionInfo_(ServerReflection_method_names[0], ::grpc::RpcMethod::BIDI_STREAMING, channel) |
||||||
|
{} |
||||||
|
|
||||||
|
::grpc::ClientReaderWriter< ::grpc::reflection::v1alpha::ServerReflectionRequest, ::grpc::reflection::v1alpha::ServerReflectionResponse>* ServerReflection::Stub::ServerReflectionInfoRaw(::grpc::ClientContext* context) { |
||||||
|
return new ::grpc::ClientReaderWriter< ::grpc::reflection::v1alpha::ServerReflectionRequest, ::grpc::reflection::v1alpha::ServerReflectionResponse>(channel_.get(), rpcmethod_ServerReflectionInfo_, context); |
||||||
|
} |
||||||
|
|
||||||
|
::grpc::ClientAsyncReaderWriter< ::grpc::reflection::v1alpha::ServerReflectionRequest, ::grpc::reflection::v1alpha::ServerReflectionResponse>* ServerReflection::Stub::AsyncServerReflectionInfoRaw(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, void* tag) { |
||||||
|
return new ::grpc::ClientAsyncReaderWriter< ::grpc::reflection::v1alpha::ServerReflectionRequest, ::grpc::reflection::v1alpha::ServerReflectionResponse>(channel_.get(), cq, rpcmethod_ServerReflectionInfo_, context, tag); |
||||||
|
} |
||||||
|
|
||||||
|
ServerReflection::Service::Service() { |
||||||
|
(void)ServerReflection_method_names; |
||||||
|
AddMethod(new ::grpc::RpcServiceMethod( |
||||||
|
ServerReflection_method_names[0], |
||||||
|
::grpc::RpcMethod::BIDI_STREAMING, |
||||||
|
new ::grpc::BidiStreamingHandler< ServerReflection::Service, ::grpc::reflection::v1alpha::ServerReflectionRequest, ::grpc::reflection::v1alpha::ServerReflectionResponse>( |
||||||
|
std::mem_fn(&ServerReflection::Service::ServerReflectionInfo), this))); |
||||||
|
} |
||||||
|
|
||||||
|
ServerReflection::Service::~Service() { |
||||||
|
} |
||||||
|
|
||||||
|
::grpc::Status ServerReflection::Service::ServerReflectionInfo(::grpc::ServerContext* context, ::grpc::ServerReaderWriter< ::grpc::reflection::v1alpha::ServerReflectionResponse, ::grpc::reflection::v1alpha::ServerReflectionRequest>* stream) { |
||||||
|
(void) context; |
||||||
|
(void) stream; |
||||||
|
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} // namespace grpc
|
||||||
|
} // namespace reflection
|
||||||
|
} // namespace v1alpha
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,49 @@ |
|||||||
|
/*
|
||||||
|
* |
||||||
|
* 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++/server_posix.h> |
||||||
|
|
||||||
|
#include <grpc/grpc_posix.h> |
||||||
|
|
||||||
|
namespace grpc { |
||||||
|
|
||||||
|
#ifdef GPR_SUPPORT_CHANNELS_FROM_FD |
||||||
|
|
||||||
|
void AddInsecureChannelFromFd(Server* server, int fd) { |
||||||
|
grpc_server_add_insecure_channel_from_fd( |
||||||
|
server->c_server(), server->completion_queue()->cq(), fd); |
||||||
|
} |
||||||
|
|
||||||
|
#endif // GPR_SUPPORT_CHANNELS_FROM_FD
|
||||||
|
|
||||||
|
} // namespace grpc
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue