commit
ac119ba887
391 changed files with 29193 additions and 10488 deletions
After Width: | Height: | Size: 62 KiB |
@ -0,0 +1,92 @@ |
||||
# Stress Test framework for gRPC |
||||
|
||||
(Sree Kuchibhotla - sreek@) |
||||
|
||||
> Status: This is implemented. More details at [README.md](https://github.com/grpc/grpc/blob/master/tools/run_tests/stress_test/README.md) |
||||
|
||||
|
||||
**I. GOALS** |
||||
|
||||
1) Build a stress test suite for gRPC: |
||||
|
||||
* Build a stress test suite that can Identify bugs by testing the system (gRPC server/client) under extreme conditions: |
||||
* High load |
||||
* High concurrency |
||||
* Limited resources |
||||
* Intermittent failures |
||||
* Should be integrated with Jenkins CI |
||||
|
||||
2) Make it generic enough (i.e build a generic test framework) that can be used for: |
||||
|
||||
* Executing M instances of a client against N instances of a server with an arbitrarily defined connection matrix |
||||
* Execute heterogenous test configurations - for example: Java stress test clients against C++ servers or Node clients against Python servers or TSAN C++ clients vs ASAN C++ Servers etc. |
||||
* Easy and Flexible enough that Devs can use it to recreate complex test scenarios |
||||
|
||||
The implementation effort is divided into two parts: |
||||
|
||||
* Building a "Stress Test Framework" to run the stress test suites- More details in **Section II** (The idea is that the Stress Test framework is generic enough that it would be easier to modify it to run other suites like interop-tests or custom test scenarios) |
||||
* Building a 'Stress test suite' - More details in **section III** |
||||
|
||||
**Terminology:** |
||||
|
||||
GCE - Google compute engine |
||||
GKE - Google Container engine |
||||
Kubernetes - Google's open source service scheduler / orchestrator. |
||||
|
||||
**Note:** The terms GKE and Kubernetes are used interchangeably in this document |
||||
|
||||
# II. STRESS TEST FRAMEWORK |
||||
|
||||
(The details of each step are explained below)) |
||||
 |
||||
**Figure 1** |
||||
|
||||
### Step 1 Read the test config, generate base docker images |
||||
|
||||
**_Test Config:_** The test configuration contains the following information: |
||||
|
||||
* _GKE info:_ GKE project and cluster info |
||||
* _Docker images:_ Instructions to build docker images |
||||
* _Client templates:_ One or more client templates each containing the following information: |
||||
* Which docker image to use |
||||
* Path to the client program to launch (within the docker image) |
||||
* Parameters to the client program |
||||
* _Server templates:_ Similar to Client templates - except that these are for servers |
||||
* Test matrix containing the following: |
||||
* _Server groups:_ One or more groups of servers containing the following info for each group |
||||
* Which server template to use |
||||
* How many instances to launch |
||||
* _Client groups:_ One or more groups of clients containing the following (for each group): |
||||
* Which client template to use |
||||
* How many instances to launch |
||||
* Which server group to talk to (all clients in this group will talk to all servers in the server group) |
||||
|
||||
The first step is to read the test config and build the docker images |
||||
|
||||
**_Stress server docker image:_** The following are the main files in the server docker images |
||||
|
||||
* _Interop_server:_ The server program |
||||
* `run_server.py`: This is a python script which is the entry point of the docker image (i.e this is the script that is called when the docker image is run in GKE). This script launches the interop server and also updates the status in BigQuery. If the interop_server fails for whatever reason, the script launch_server.py logs that status in BigQuery |
||||
|
||||
**_Stress client docker image:_** |
||||
|
||||
* Stress client: The stress test client. In addition to talking to the interop_server, the stress client also exports metrics (which can be queried by the metrics_client described below) |
||||
* Metrics client: Metrics client connects to the stress_client to get the current qps metrics. |
||||
* `run_client.py`: This is a python script which is the entry point of the docker image (i.e this is the script that is called when the docker image is run in GKE). This script launches the stress client and also updates the status in BigQuery. The script then periodically launches metrics client to query the qps from the stress client and then uploads the qps to BigQuery. |
||||
|
||||
### Step 2) Upload the docker images to GKE |
||||
The docker images are uploaded to the GKE registry |
||||
|
||||
### Step 3) Launch the tests in GKE |
||||
The test driver reads the test matrix (described in step 1) and creates the necessary server and client pods in GKE. |
||||
|
||||
### Step 4) Tests are run in GKE |
||||
GKE starts running the tests by calling the entry points in *each* docker image (i.e `run_server.py` or `run_client.py` depending on whcih docker image it is) |
||||
|
||||
### Step 5) Upload the status to GKE and Monitor the status in GKE |
||||
* 5.1 The tests periodically update their status in BigQuery |
||||
* 5.2 The test driver periodically checks the status in Bigquery to see if any tests failed. If any tests failed, the driver immediately stops the tests. If not, the driver continues to run the tests for a configurable amount of time. |
||||
|
||||
### Step 6) Create a summary report |
||||
The test driver creates a final summary report containing details about any test failures and information about how to connect the failed pods in GKE for debugging. |
||||
|
@ -1,188 +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. |
||||
* |
||||
*/ |
||||
|
||||
|
||||
// Generated by tools/codegen/extensions/gen_reflection_proto.sh
|
||||
// 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/method_handler_impl.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, ""); |
||||
} |
||||
}; |
||||
typedef Service StreamedUnaryService; |
||||
typedef Service SplitStreamedService; |
||||
typedef Service StreamedService; |
||||
}; |
||||
|
||||
} // namespace v1alpha
|
||||
} // namespace reflection
|
||||
} // namespace grpc
|
||||
|
||||
|
||||
#endif // GRPC_reflection_2eproto__INCLUDED
|
File diff suppressed because it is too large
Load Diff
@ -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 GRPCXX_RESOURCE_QUOTA_H |
||||
#define GRPCXX_RESOURCE_QUOTA_H |
||||
|
||||
struct grpc_resource_quota; |
||||
|
||||
#include <grpc++/impl/codegen/config.h> |
||||
|
||||
namespace grpc { |
||||
|
||||
/// ResourceQuota represents a bound on memory usage by the gRPC library.
|
||||
/// A ResourceQuota can be attached to a server (via ServerBuilder), or a client
|
||||
/// channel (via ChannelArguments). gRPC will attempt to keep memory used by
|
||||
/// all attached entities below the ResourceQuota bound.
|
||||
class ResourceQuota GRPC_FINAL { |
||||
public: |
||||
explicit ResourceQuota(const grpc::string& name); |
||||
ResourceQuota(); |
||||
~ResourceQuota(); |
||||
|
||||
/// Resize this ResourceQuota to a new size. If new_size is smaller than the
|
||||
/// current size of the pool, memory usage will be monotonically decreased
|
||||
/// until it falls under new_size. No time bound is given for this to occur
|
||||
/// however.
|
||||
ResourceQuota& Resize(size_t new_size); |
||||
|
||||
grpc_resource_quota* c_resource_quota() const { return impl_; } |
||||
|
||||
private: |
||||
ResourceQuota(const ResourceQuota& rhs); |
||||
ResourceQuota& operator=(const ResourceQuota& rhs); |
||||
|
||||
grpc_resource_quota* const impl_; |
||||
}; |
||||
|
||||
} // namespace grpc
|
||||
|
||||
#endif // GRPCXX_RESOURCE_QUOTA_H
|
@ -1,94 +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 "src/core/ext/client_channel/resolver_result.h" |
||||
|
||||
#include <string.h> |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/string_util.h> |
||||
|
||||
#include "src/core/lib/channel/channel_args.h" |
||||
|
||||
struct grpc_resolver_result { |
||||
gpr_refcount refs; |
||||
char* server_name; |
||||
grpc_lb_addresses* addresses; |
||||
char* lb_policy_name; |
||||
grpc_channel_args* lb_policy_args; |
||||
}; |
||||
|
||||
grpc_resolver_result* grpc_resolver_result_create( |
||||
const char* server_name, grpc_lb_addresses* addresses, |
||||
const char* lb_policy_name, grpc_channel_args* lb_policy_args) { |
||||
grpc_resolver_result* result = gpr_malloc(sizeof(*result)); |
||||
memset(result, 0, sizeof(*result)); |
||||
gpr_ref_init(&result->refs, 1); |
||||
result->server_name = gpr_strdup(server_name); |
||||
result->addresses = addresses; |
||||
result->lb_policy_name = gpr_strdup(lb_policy_name); |
||||
result->lb_policy_args = lb_policy_args; |
||||
return result; |
||||
} |
||||
|
||||
void grpc_resolver_result_ref(grpc_resolver_result* result) { |
||||
gpr_ref(&result->refs); |
||||
} |
||||
|
||||
void grpc_resolver_result_unref(grpc_exec_ctx* exec_ctx, |
||||
grpc_resolver_result* result) { |
||||
if (gpr_unref(&result->refs)) { |
||||
gpr_free(result->server_name); |
||||
grpc_lb_addresses_destroy(result->addresses, NULL /* user_data_destroy */); |
||||
gpr_free(result->lb_policy_name); |
||||
grpc_channel_args_destroy(result->lb_policy_args); |
||||
gpr_free(result); |
||||
} |
||||
} |
||||
|
||||
const char* grpc_resolver_result_get_server_name(grpc_resolver_result* result) { |
||||
return result->server_name; |
||||
} |
||||
|
||||
grpc_lb_addresses* grpc_resolver_result_get_addresses( |
||||
grpc_resolver_result* result) { |
||||
return result->addresses; |
||||
} |
||||
|
||||
const char* grpc_resolver_result_get_lb_policy_name( |
||||
grpc_resolver_result* result) { |
||||
return result->lb_policy_name; |
||||
} |
||||
|
||||
grpc_channel_args* grpc_resolver_result_get_lb_policy_args( |
||||
grpc_resolver_result* result) { |
||||
return result->lb_policy_args; |
||||
} |
@ -1,68 +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.
|
||||
//
|
||||
|
||||
#ifndef GRPC_CORE_EXT_CLIENT_CHANNEL_RESOLVER_RESULT_H |
||||
#define GRPC_CORE_EXT_CLIENT_CHANNEL_RESOLVER_RESULT_H |
||||
|
||||
#include "src/core/ext/client_channel/lb_policy_factory.h" |
||||
|
||||
// TODO(roth, ctiller): In the long term, we are considering replacing
|
||||
// the resolver_result data structure with grpc_channel_args. The idea is
|
||||
// that the resolver will return a set of channel args that contains the
|
||||
// information that is currently in the resolver_result struct. For
|
||||
// example, there will be specific args indicating the set of addresses
|
||||
// and the name of the LB policy to instantiate. Note that if we did
|
||||
// this, we would probably want to change the data structure of
|
||||
// grpc_channel_args such to a hash table or AVL or some other data
|
||||
// structure that does not require linear search to find keys.
|
||||
|
||||
/// Results reported from a grpc_resolver.
|
||||
typedef struct grpc_resolver_result grpc_resolver_result; |
||||
|
||||
/// Takes ownership of \a addresses and \a lb_policy_args.
|
||||
grpc_resolver_result* grpc_resolver_result_create( |
||||
const char* server_name, grpc_lb_addresses* addresses, |
||||
const char* lb_policy_name, grpc_channel_args* lb_policy_args); |
||||
|
||||
void grpc_resolver_result_ref(grpc_resolver_result* result); |
||||
void grpc_resolver_result_unref(grpc_exec_ctx* exec_ctx, |
||||
grpc_resolver_result* result); |
||||
|
||||
/// Accessors. Caller does NOT take ownership of results.
|
||||
const char* grpc_resolver_result_get_server_name(grpc_resolver_result* result); |
||||
grpc_lb_addresses* grpc_resolver_result_get_addresses( |
||||
grpc_resolver_result* result); |
||||
const char* grpc_resolver_result_get_lb_policy_name( |
||||
grpc_resolver_result* result); |
||||
grpc_channel_args* grpc_resolver_result_get_lb_policy_args( |
||||
grpc_resolver_result* result); |
||||
|
||||
#endif /* GRPC_CORE_EXT_CLIENT_CHANNEL_RESOLVER_RESULT_H */ |
@ -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 "src/core/lib/iomgr/port.h" |
||||
|
||||
#ifdef GRPC_UV |
||||
|
||||
#include "src/core/lib/debug/trace.h" |
||||
#include "src/core/lib/iomgr/pollset_uv.h" |
||||
#include "src/core/lib/iomgr/tcp_uv.h" |
||||
|
||||
void grpc_iomgr_platform_init(void) { |
||||
grpc_pollset_global_init(); |
||||
grpc_register_tracer("tcp", &grpc_tcp_trace); |
||||
} |
||||
void grpc_iomgr_platform_flush(void) {} |
||||
void grpc_iomgr_platform_shutdown(void) { grpc_pollset_global_shutdown(); } |
||||
|
||||
#endif /* GRPC_UV */ |
@ -0,0 +1,62 @@ |
||||
/*
|
||||
* |
||||
* 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/lib/iomgr/port.h" |
||||
|
||||
#ifdef GRPC_UV |
||||
|
||||
#include "src/core/lib/iomgr/pollset_set.h" |
||||
|
||||
grpc_pollset_set* grpc_pollset_set_create(void) { |
||||
return (grpc_pollset_set*)((intptr_t)0xdeafbeef); |
||||
} |
||||
|
||||
void grpc_pollset_set_destroy(grpc_pollset_set* pollset_set) {} |
||||
|
||||
void grpc_pollset_set_add_pollset(grpc_exec_ctx* exec_ctx, |
||||
grpc_pollset_set* pollset_set, |
||||
grpc_pollset* pollset) {} |
||||
|
||||
void grpc_pollset_set_del_pollset(grpc_exec_ctx* exec_ctx, |
||||
grpc_pollset_set* pollset_set, |
||||
grpc_pollset* pollset) {} |
||||
|
||||
void grpc_pollset_set_add_pollset_set(grpc_exec_ctx* exec_ctx, |
||||
grpc_pollset_set* bag, |
||||
grpc_pollset_set* item) {} |
||||
|
||||
void grpc_pollset_set_del_pollset_set(grpc_exec_ctx* exec_ctx, |
||||
grpc_pollset_set* bag, |
||||
grpc_pollset_set* item) {} |
||||
|
||||
#endif /* GRPC_UV */ |
@ -0,0 +1,142 @@ |
||||
/*
|
||||
* |
||||
* 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/lib/iomgr/port.h" |
||||
|
||||
#ifdef GRPC_UV |
||||
|
||||
#include <uv.h> |
||||
|
||||
#include <string.h> |
||||
|
||||
#include <grpc/support/log.h> |
||||
#include <grpc/support/sync.h> |
||||
|
||||
#include "src/core/lib/iomgr/pollset.h" |
||||
#include "src/core/lib/iomgr/pollset_uv.h" |
||||
|
||||
struct grpc_pollset { |
||||
uv_timer_t timer; |
||||
int shutting_down; |
||||
}; |
||||
|
||||
/* Indicates that grpc_pollset_work should run an iteration of the UV loop
|
||||
before running callbacks. This defaults to 1, and should be disabled if |
||||
grpc_pollset_work will be called within the callstack of uv_run */ |
||||
int grpc_pollset_work_run_loop; |
||||
|
||||
gpr_mu grpc_polling_mu; |
||||
|
||||
size_t grpc_pollset_size() { return sizeof(grpc_pollset); } |
||||
|
||||
void grpc_pollset_global_init(void) { |
||||
gpr_mu_init(&grpc_polling_mu); |
||||
grpc_pollset_work_run_loop = 1; |
||||
} |
||||
|
||||
void grpc_pollset_global_shutdown(void) { gpr_mu_destroy(&grpc_polling_mu); } |
||||
|
||||
void grpc_pollset_init(grpc_pollset *pollset, gpr_mu **mu) { |
||||
*mu = &grpc_polling_mu; |
||||
memset(pollset, 0, sizeof(grpc_pollset)); |
||||
uv_timer_init(uv_default_loop(), &pollset->timer); |
||||
pollset->shutting_down = 0; |
||||
} |
||||
|
||||
static void timer_close_cb(uv_handle_t *handle) { handle->data = (void *)1; } |
||||
|
||||
void grpc_pollset_shutdown(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, |
||||
grpc_closure *closure) { |
||||
GPR_ASSERT(!pollset->shutting_down); |
||||
pollset->shutting_down = 1; |
||||
if (grpc_pollset_work_run_loop) { |
||||
// Drain any pending UV callbacks without blocking
|
||||
uv_run(uv_default_loop(), UV_RUN_NOWAIT); |
||||
} |
||||
grpc_exec_ctx_sched(exec_ctx, closure, GRPC_ERROR_NONE, NULL); |
||||
} |
||||
|
||||
void grpc_pollset_destroy(grpc_pollset *pollset) { |
||||
uv_close((uv_handle_t *)&pollset->timer, timer_close_cb); |
||||
// timer.data is a boolean indicating that the timer has finished closing
|
||||
pollset->timer.data = (void *)0; |
||||
if (grpc_pollset_work_run_loop) { |
||||
while (!pollset->timer.data) { |
||||
uv_run(uv_default_loop(), UV_RUN_NOWAIT); |
||||
} |
||||
} |
||||
} |
||||
|
||||
void grpc_pollset_reset(grpc_pollset *pollset) { |
||||
GPR_ASSERT(pollset->shutting_down); |
||||
pollset->shutting_down = 0; |
||||
} |
||||
|
||||
static void timer_run_cb(uv_timer_t *timer) {} |
||||
|
||||
grpc_error *grpc_pollset_work(grpc_exec_ctx *exec_ctx, grpc_pollset *pollset, |
||||
grpc_pollset_worker **worker_hdl, |
||||
gpr_timespec now, gpr_timespec deadline) { |
||||
uint64_t timeout; |
||||
gpr_mu_unlock(&grpc_polling_mu); |
||||
if (grpc_pollset_work_run_loop) { |
||||
if (gpr_time_cmp(deadline, now) >= 0) { |
||||
timeout = (uint64_t)gpr_time_to_millis(gpr_time_sub(deadline, now)); |
||||
} else { |
||||
timeout = 0; |
||||
} |
||||
/* We special-case timeout=0 so that we don't bother with the timer when
|
||||
the loop won't block anyway */ |
||||
if (timeout > 0) { |
||||
uv_timer_start(&pollset->timer, timer_run_cb, timeout, 0); |
||||
/* Run until there is some I/O activity or the timer triggers. It doesn't
|
||||
matter which happens */ |
||||
uv_run(uv_default_loop(), UV_RUN_ONCE); |
||||
uv_timer_stop(&pollset->timer); |
||||
} else { |
||||
uv_run(uv_default_loop(), UV_RUN_NOWAIT); |
||||
} |
||||
} |
||||
if (!grpc_closure_list_empty(exec_ctx->closure_list)) { |
||||
grpc_exec_ctx_flush(exec_ctx); |
||||
} |
||||
gpr_mu_lock(&grpc_polling_mu); |
||||
return GRPC_ERROR_NONE; |
||||
} |
||||
|
||||
grpc_error *grpc_pollset_kick(grpc_pollset *pollset, |
||||
grpc_pollset_worker *specific_worker) { |
||||
return GRPC_ERROR_NONE; |
||||
} |
||||
|
||||
#endif /* GRPC_UV */ |
@ -0,0 +1,42 @@ |
||||
/*
|
||||
* |
||||
* 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_LIB_IOMGR_POLLSET_UV_H |
||||
#define GRPC_CORE_LIB_IOMGR_POLLSET_UV_H |
||||
|
||||
extern int grpc_pollset_work_run_loop; |
||||
|
||||
void grpc_pollset_global_init(void); |
||||
void grpc_pollset_global_shutdown(void); |
||||
|
||||
#endif /* GRPC_CORE_LIB_IOMGR_POLLSET_UV_H */ |
@ -0,0 +1,129 @@ |
||||
/*
|
||||
* |
||||
* 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/support/port_platform.h> |
||||
|
||||
#ifndef GRPC_CORE_LIB_IOMGR_PORT_H |
||||
#define GRPC_CORE_LIB_IOMGR_PORT_H |
||||
|
||||
#if defined(GRPC_UV) |
||||
// Do nothing
|
||||
#elif defined(GPR_MANYLINUX1) |
||||
#define GRPC_HAVE_IPV6_RECVPKTINFO 1 |
||||
#define GRPC_HAVE_IP_PKTINFO 1 |
||||
#define GRPC_HAVE_MSG_NOSIGNAL 1 |
||||
#define GRPC_HAVE_UNIX_SOCKET 1 |
||||
#define GRPC_POSIX_NO_SPECIAL_WAKEUP_FD 1 |
||||
#define GRPC_POSIX_SOCKET 1 |
||||
#define GRPC_POSIX_SOCKETADDR 1 |
||||
#define GRPC_POSIX_SOCKETUTILS 1 |
||||
#define GRPC_POSIX_WAKEUP_FD 1 |
||||
#define GRPC_TIMER_USE_GENERIC 1 |
||||
#elif defined(GPR_WINDOWS) |
||||
#define GRPC_TIMER_USE_GENERIC 1 |
||||
#define GRPC_WINSOCK_SOCKET 1 |
||||
#define GRPC_WINDOWS_SOCKETUTILS 1 |
||||
#elif defined(GPR_ANDROID) |
||||
#define GRPC_HAVE_IPV6_RECVPKTINFO 1 |
||||
#define GRPC_HAVE_IP_PKTINFO 1 |
||||
#define GRPC_HAVE_MSG_NOSIGNAL 1 |
||||
#define GRPC_HAVE_UNIX_SOCKET 1 |
||||
#define GRPC_LINUX_EVENTFD 1 |
||||
#define GRPC_POSIX_SOCKET 1 |
||||
#define GRPC_POSIX_SOCKETADDR 1 |
||||
#define GRPC_POSIX_SOCKETUTILS 1 |
||||
#define GRPC_POSIX_WAKEUP_FD 1 |
||||
#define GRPC_TIMER_USE_GENERIC 1 |
||||
#elif defined(GPR_LINUX) |
||||
#define GRPC_HAVE_IPV6_RECVPKTINFO 1 |
||||
#define GRPC_HAVE_IP_PKTINFO 1 |
||||
#define GRPC_HAVE_MSG_NOSIGNAL 1 |
||||
#define GRPC_HAVE_UNIX_SOCKET 1 |
||||
#define GRPC_LINUX_MULTIPOLL_WITH_EPOLL 1 |
||||
#define GRPC_POSIX_SOCKET 1 |
||||
#define GRPC_POSIX_SOCKETADDR 1 |
||||
#define GRPC_POSIX_WAKEUP_FD 1 |
||||
#define GRPC_TIMER_USE_GENERIC 1 |
||||
#ifdef __GLIBC_PREREQ |
||||
#if __GLIBC_PREREQ(2, 9) |
||||
#define GRPC_LINUX_EPOLL 1 |
||||
#define GRPC_LINUX_EVENTFD 1 |
||||
#endif |
||||
#if __GLIBC_PREREQ(2, 10) |
||||
#define GRPC_LINUX_SOCKETUTILS 1 |
||||
#endif |
||||
#endif |
||||
#ifndef GRPC_LINUX_EVENTFD |
||||
#define GRPC_POSIX_NO_SPECIAL_WAKEUP_FD 1 |
||||
#endif |
||||
#ifndef GRPC_LINUX_SOCKETUTILS |
||||
#define GRPC_POSIX_SOCKETUTILS |
||||
#endif |
||||
#elif defined(GPR_APPLE) |
||||
#define GRPC_HAVE_SO_NOSIGPIPE 1 |
||||
#define GRPC_HAVE_UNIX_SOCKET 1 |
||||
#define GRPC_MSG_IOVLEN_TYPE int |
||||
#define GRPC_POSIX_NO_SPECIAL_WAKEUP_FD 1 |
||||
#define GRPC_POSIX_SOCKET 1 |
||||
#define GRPC_POSIX_SOCKETADDR 1 |
||||
#define GRPC_POSIX_SOCKETUTILS 1 |
||||
#define GRPC_POSIX_WAKEUP_FD 1 |
||||
#define GRPC_TIMER_USE_GENERIC 1 |
||||
#elif defined(GPR_FREEBSD) |
||||
#define GRPC_HAVE_IPV6_RECVPKTINFO 1 |
||||
#define GRPC_HAVE_SO_NOSIGPIPE 1 |
||||
#define GRPC_HAVE_UNIX_SOCKET 1 |
||||
#define GRPC_POSIX_NO_SPECIAL_WAKEUP_FD 1 |
||||
#define GRPC_POSIX_SOCKET 1 |
||||
#define GRPC_POSIX_SOCKETADDR 1 |
||||
#define GRPC_POSIX_SOCKETUTILS 1 |
||||
#define GRPC_POSIX_WAKEUP_FD 1 |
||||
#define GRPC_TIMER_USE_GENERIC 1 |
||||
#elif defined(GPR_NACL) |
||||
#define GRPC_POSIX_NO_SPECIAL_WAKEUP_FD 1 |
||||
#define GRPC_POSIX_SOCKET 1 |
||||
#define GRPC_POSIX_SOCKETADDR 1 |
||||
#define GRPC_POSIX_SOCKETUTILS 1 |
||||
#define GRPC_POSIX_WAKEUP_FD 1 |
||||
#define GRPC_TIMER_USE_GENERIC 1 |
||||
#elif !defined(GPR_NO_AUTODETECT_PLATFORM) |
||||
#error "Platform not recognized" |
||||
#endif |
||||
|
||||
#if defined(GRPC_POSIX_SOCKET) + defined(GRPC_WINSOCK_SOCKET) + \ |
||||
defined(GRPC_CUSTOM_SOCKET) + defined(GRPC_UV) != \
|
||||
1 |
||||
#error Must define exactly one of GRPC_POSIX_SOCKET, GRPC_WINSOCK_SOCKET, GPR_CUSTOM_SOCKET |
||||
#endif |
||||
|
||||
#endif /* GRPC_CORE_LIB_IOMGR_PORT_H */ |
@ -0,0 +1,231 @@ |
||||
/*
|
||||
* |
||||
* 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/lib/iomgr/port.h" |
||||
#ifdef GRPC_UV |
||||
|
||||
#include <uv.h> |
||||
|
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/host_port.h> |
||||
#include <grpc/support/log.h> |
||||
#include <grpc/support/string_util.h> |
||||
|
||||
#include "src/core/lib/iomgr/closure.h" |
||||
#include "src/core/lib/iomgr/error.h" |
||||
#include "src/core/lib/iomgr/exec_ctx.h" |
||||
#include "src/core/lib/iomgr/resolve_address.h" |
||||
#include "src/core/lib/iomgr/sockaddr.h" |
||||
#include "src/core/lib/iomgr/sockaddr_utils.h" |
||||
|
||||
#include <string.h> |
||||
|
||||
typedef struct request { |
||||
grpc_closure *on_done; |
||||
grpc_resolved_addresses **addresses; |
||||
struct addrinfo *hints; |
||||
} request; |
||||
|
||||
static grpc_error *handle_addrinfo_result(int status, struct addrinfo *result, |
||||
grpc_resolved_addresses **addresses) { |
||||
struct addrinfo *resp; |
||||
size_t i; |
||||
if (status != 0) { |
||||
grpc_error *error; |
||||
*addresses = NULL; |
||||
error = GRPC_ERROR_CREATE("getaddrinfo failed"); |
||||
error = |
||||
grpc_error_set_str(error, GRPC_ERROR_STR_OS_ERROR, uv_strerror(status)); |
||||
return error; |
||||
} |
||||
(*addresses) = gpr_malloc(sizeof(grpc_resolved_addresses)); |
||||
(*addresses)->naddrs = 0; |
||||
for (resp = result; resp != NULL; resp = resp->ai_next) { |
||||
(*addresses)->naddrs++; |
||||
} |
||||
(*addresses)->addrs = |
||||
gpr_malloc(sizeof(grpc_resolved_address) * (*addresses)->naddrs); |
||||
i = 0; |
||||
for (resp = result; resp != NULL; resp = resp->ai_next) { |
||||
memcpy(&(*addresses)->addrs[i].addr, resp->ai_addr, resp->ai_addrlen); |
||||
(*addresses)->addrs[i].len = resp->ai_addrlen; |
||||
i++; |
||||
} |
||||
|
||||
{ |
||||
for (i = 0; i < (*addresses)->naddrs; i++) { |
||||
char *buf; |
||||
grpc_sockaddr_to_string(&buf, &(*addresses)->addrs[i], 0); |
||||
gpr_free(buf); |
||||
} |
||||
} |
||||
return GRPC_ERROR_NONE; |
||||
} |
||||
|
||||
static void getaddrinfo_callback(uv_getaddrinfo_t *req, int status, |
||||
struct addrinfo *res) { |
||||
request *r = (request *)req->data; |
||||
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; |
||||
grpc_error *error; |
||||
error = handle_addrinfo_result(status, res, r->addresses); |
||||
grpc_exec_ctx_sched(&exec_ctx, r->on_done, error, NULL); |
||||
grpc_exec_ctx_finish(&exec_ctx); |
||||
|
||||
gpr_free(r->hints); |
||||
gpr_free(r); |
||||
gpr_free(req); |
||||
uv_freeaddrinfo(res); |
||||
} |
||||
|
||||
static grpc_error *try_split_host_port(const char *name, |
||||
const char *default_port, char **host, |
||||
char **port) { |
||||
/* parse name, splitting it into host and port parts */ |
||||
grpc_error *error; |
||||
gpr_split_host_port(name, host, port); |
||||
if (host == NULL) { |
||||
char *msg; |
||||
gpr_asprintf(&msg, "unparseable host:port: '%s'", name); |
||||
error = GRPC_ERROR_CREATE(msg); |
||||
gpr_free(msg); |
||||
return error; |
||||
} |
||||
if (port == NULL) { |
||||
if (default_port == NULL) { |
||||
char *msg; |
||||
gpr_asprintf(&msg, "no port in name '%s'", name); |
||||
error = GRPC_ERROR_CREATE(msg); |
||||
gpr_free(msg); |
||||
return error; |
||||
} |
||||
*port = gpr_strdup(default_port); |
||||
} |
||||
return GRPC_ERROR_NONE; |
||||
} |
||||
|
||||
static grpc_error *blocking_resolve_address_impl( |
||||
const char *name, const char *default_port, |
||||
grpc_resolved_addresses **addresses) { |
||||
char *host; |
||||
char *port; |
||||
struct addrinfo hints; |
||||
uv_getaddrinfo_t req; |
||||
int s; |
||||
grpc_error *err; |
||||
|
||||
req.addrinfo = NULL; |
||||
|
||||
err = try_split_host_port(name, default_port, &host, &port); |
||||
if (err != GRPC_ERROR_NONE) { |
||||
goto done; |
||||
} |
||||
|
||||
/* Call getaddrinfo */ |
||||
memset(&hints, 0, sizeof(hints)); |
||||
hints.ai_family = AF_UNSPEC; /* ipv4 or ipv6 */ |
||||
hints.ai_socktype = SOCK_STREAM; /* stream socket */ |
||||
hints.ai_flags = AI_PASSIVE; /* for wildcard IP address */ |
||||
|
||||
s = uv_getaddrinfo(uv_default_loop(), &req, NULL, host, port, &hints); |
||||
err = handle_addrinfo_result(s, req.addrinfo, addresses); |
||||
|
||||
done: |
||||
gpr_free(host); |
||||
gpr_free(port); |
||||
if (req.addrinfo) { |
||||
uv_freeaddrinfo(req.addrinfo); |
||||
} |
||||
return err; |
||||
} |
||||
|
||||
grpc_error *(*grpc_blocking_resolve_address)( |
||||
const char *name, const char *default_port, |
||||
grpc_resolved_addresses **addresses) = blocking_resolve_address_impl; |
||||
|
||||
void grpc_resolved_addresses_destroy(grpc_resolved_addresses *addrs) { |
||||
if (addrs != NULL) { |
||||
gpr_free(addrs->addrs); |
||||
} |
||||
gpr_free(addrs); |
||||
} |
||||
|
||||
static void resolve_address_impl(grpc_exec_ctx *exec_ctx, const char *name, |
||||
const char *default_port, |
||||
grpc_closure *on_done, |
||||
grpc_resolved_addresses **addrs) { |
||||
uv_getaddrinfo_t *req; |
||||
request *r; |
||||
struct addrinfo *hints; |
||||
char *host; |
||||
char *port; |
||||
grpc_error *err; |
||||
int s; |
||||
err = try_split_host_port(name, default_port, &host, &port); |
||||
if (err != GRPC_ERROR_NONE) { |
||||
grpc_exec_ctx_sched(exec_ctx, on_done, err, NULL); |
||||
return; |
||||
} |
||||
r = gpr_malloc(sizeof(request)); |
||||
r->on_done = on_done; |
||||
r->addresses = addrs; |
||||
req = gpr_malloc(sizeof(uv_getaddrinfo_t)); |
||||
req->data = r; |
||||
|
||||
/* Call getaddrinfo */ |
||||
hints = gpr_malloc(sizeof(struct addrinfo)); |
||||
memset(hints, 0, sizeof(struct addrinfo)); |
||||
hints->ai_family = AF_UNSPEC; /* ipv4 or ipv6 */ |
||||
hints->ai_socktype = SOCK_STREAM; /* stream socket */ |
||||
hints->ai_flags = AI_PASSIVE; /* for wildcard IP address */ |
||||
r->hints = hints; |
||||
|
||||
s = uv_getaddrinfo(uv_default_loop(), req, getaddrinfo_callback, host, port, |
||||
hints); |
||||
|
||||
if (s != 0) { |
||||
*addrs = NULL; |
||||
err = GRPC_ERROR_CREATE("getaddrinfo failed"); |
||||
err = grpc_error_set_str(err, GRPC_ERROR_STR_OS_ERROR, uv_strerror(s)); |
||||
grpc_exec_ctx_sched(exec_ctx, on_done, err, NULL); |
||||
gpr_free(r); |
||||
gpr_free(req); |
||||
gpr_free(hints); |
||||
} |
||||
} |
||||
|
||||
void (*grpc_resolve_address)(grpc_exec_ctx *exec_ctx, const char *name, |
||||
const char *default_port, grpc_closure *on_done, |
||||
grpc_resolved_addresses **addrs) = |
||||
resolve_address_impl; |
||||
|
||||
#endif /* GRPC_UV */ |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue