aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/grpc++
diff options
context:
space:
mode:
authorGravatar yang-g <yangg@google.com>2015-08-24 15:54:07 -0700
committerGravatar yang-g <yangg@google.com>2015-08-24 15:54:07 -0700
commit3e4bd9598bc8b5740317227c8a7a8e38f519dabe (patch)
tree6b9399f3fd91ea545bb6cc4ffba3e72eda24303b /include/grpc++
parent9fb35a53320a7b958739ce01ed50de087e6c5ee9 (diff)
parent8c4549aec780e2cdeb72f028d9a44ad9fd853c33 (diff)
merge with head
Diffstat (limited to 'include/grpc++')
-rw-r--r--include/grpc++/impl/call.h3
-rw-r--r--include/grpc++/impl/rpc_service_method.h16
-rw-r--r--include/grpc++/server.h17
-rw-r--r--include/grpc++/server_builder.h8
-rw-r--r--include/grpc++/support/async_stream.h2
-rw-r--r--include/grpc++/support/dynamic_thread_pool.h82
-rw-r--r--include/grpc++/support/fixed_size_thread_pool.h66
-rw-r--r--include/grpc++/support/thread_pool_interface.h54
8 files changed, 28 insertions, 220 deletions
diff --git a/include/grpc++/impl/call.h b/include/grpc++/impl/call.h
index ed3110fdb7..e5da6c9e2a 100644
--- a/include/grpc++/impl/call.h
+++ b/include/grpc++/impl/call.h
@@ -540,8 +540,7 @@ class CallOpSet : public CallOpSetInterface,
template <class Op1 = CallNoOp<1>, class Op2 = CallNoOp<2>,
class Op3 = CallNoOp<3>, class Op4 = CallNoOp<4>,
class Op5 = CallNoOp<5>, class Op6 = CallNoOp<6>>
-class SneakyCallOpSet GRPC_FINAL
- : public CallOpSet<Op1, Op2, Op3, Op4, Op5, Op6> {
+class SneakyCallOpSet : public CallOpSet<Op1, Op2, Op3, Op4, Op5, Op6> {
public:
bool FinalizeResult(void** tag, bool* status) GRPC_OVERRIDE {
typedef CallOpSet<Op1, Op2, Op3, Op4, Op5, Op6> Base;
diff --git a/include/grpc++/impl/rpc_service_method.h b/include/grpc++/impl/rpc_service_method.h
index 597798c203..fcb0b7ccce 100644
--- a/include/grpc++/impl/rpc_service_method.h
+++ b/include/grpc++/impl/rpc_service_method.h
@@ -211,13 +211,19 @@ class BidiStreamingHandler : public MethodHandler {
// Handle unknown method by returning UNIMPLEMENTED error.
class UnknownMethodHandler : public MethodHandler {
public:
- void RunHandler(const HandlerParameter& param) GRPC_FINAL {
+ template <class T>
+ static void FillOps(ServerContext* context, T* ops) {
Status status(StatusCode::UNIMPLEMENTED, "");
- CallOpSet<CallOpSendInitialMetadata, CallOpServerSendStatus> ops;
- if (!param.server_context->sent_initial_metadata_) {
- ops.SendInitialMetadata(param.server_context->initial_metadata_);
+ if (!context->sent_initial_metadata_) {
+ ops->SendInitialMetadata(context->initial_metadata_);
+ context->sent_initial_metadata_ = true;
}
- ops.ServerSendStatus(param.server_context->trailing_metadata_, status);
+ ops->ServerSendStatus(context->trailing_metadata_, status);
+ }
+
+ void RunHandler(const HandlerParameter& param) GRPC_FINAL {
+ CallOpSet<CallOpSendInitialMetadata, CallOpServerSendStatus> ops;
+ FillOps(param.server_context, &ops);
param.call->PerformOps(&ops);
param.call->cq()->Pluck(&ops);
}
diff --git a/include/grpc++/server.h b/include/grpc++/server.h
index 183cbc4692..c8979e433c 100644
--- a/include/grpc++/server.h
+++ b/include/grpc++/server.h
@@ -98,7 +98,7 @@ class Server GRPC_FINAL : public GrpcLibrary, private CallHook {
// Add a listening port. Can be called multiple times.
int AddListeningPort(const grpc::string& addr, ServerCredentials* creds);
// Start the server.
- bool Start();
+ bool Start(ServerCompletionQueue** cqs, size_t num_cqs);
void HandleQueueClosed();
void RunRpc();
@@ -112,7 +112,8 @@ class Server GRPC_FINAL : public GrpcLibrary, private CallHook {
public:
BaseAsyncRequest(Server* server, ServerContext* context,
ServerAsyncStreamingInterface* stream,
- CompletionQueue* call_cq, void* tag);
+ CompletionQueue* call_cq, void* tag,
+ bool delete_on_finalize);
virtual ~BaseAsyncRequest();
bool FinalizeResult(void** tag, bool* status) GRPC_OVERRIDE;
@@ -123,6 +124,7 @@ class Server GRPC_FINAL : public GrpcLibrary, private CallHook {
ServerAsyncStreamingInterface* const stream_;
CompletionQueue* const call_cq_;
void* const tag_;
+ const bool delete_on_finalize_;
grpc_call* call_;
grpc_metadata_array initial_metadata_array_;
};
@@ -184,12 +186,13 @@ class Server GRPC_FINAL : public GrpcLibrary, private CallHook {
Message* const request_;
};
- class GenericAsyncRequest GRPC_FINAL : public BaseAsyncRequest {
+ class GenericAsyncRequest : public BaseAsyncRequest {
public:
GenericAsyncRequest(Server* server, GenericServerContext* context,
ServerAsyncStreamingInterface* stream,
CompletionQueue* call_cq,
- ServerCompletionQueue* notification_cq, void* tag);
+ ServerCompletionQueue* notification_cq, void* tag,
+ bool delete_on_finalize);
bool FinalizeResult(void** tag, bool* status) GRPC_OVERRIDE;
@@ -197,6 +200,10 @@ class Server GRPC_FINAL : public GrpcLibrary, private CallHook {
grpc_call_details call_details_;
};
+ class UnimplementedAsyncRequestContext;
+ class UnimplementedAsyncRequest;
+ class UnimplementedAsyncResponse;
+
template <class Message>
void RequestAsyncCall(void* registered_method, ServerContext* context,
ServerAsyncStreamingInterface* stream,
@@ -221,7 +228,7 @@ class Server GRPC_FINAL : public GrpcLibrary, private CallHook {
ServerCompletionQueue* notification_cq,
void* tag) {
new GenericAsyncRequest(this, context, stream, call_cq, notification_cq,
- tag);
+ tag, true);
}
const int max_message_size_;
diff --git a/include/grpc++/server_builder.h b/include/grpc++/server_builder.h
index 95325915a1..8cd2048592 100644
--- a/include/grpc++/server_builder.h
+++ b/include/grpc++/server_builder.h
@@ -96,13 +96,9 @@ class ServerBuilder {
std::shared_ptr<ServerCredentials> creds,
int* selected_port = nullptr);
- // Set the thread pool used for running appliation rpc handlers.
- // Does not take ownership.
- void SetThreadPool(ThreadPoolInterface* thread_pool);
-
// Add a completion queue for handling asynchronous services
- // Caller is required to keep this completion queue live until calling
- // BuildAndStart()
+ // Caller is required to keep this completion queue live until
+ // the server is destroyed.
std::unique_ptr<ServerCompletionQueue> AddCompletionQueue();
// Return a running server which is ready for processing rpcs.
diff --git a/include/grpc++/support/async_stream.h b/include/grpc++/support/async_stream.h
index 8380731556..4c12fda12f 100644
--- a/include/grpc++/support/async_stream.h
+++ b/include/grpc++/support/async_stream.h
@@ -419,6 +419,8 @@ class ServerAsyncReaderWriter GRPC_FINAL : public ServerAsyncStreamingInterface,
}
private:
+ friend class ::grpc::Server;
+
void BindCall(Call* call) GRPC_OVERRIDE { call_ = *call; }
Call call_;
diff --git a/include/grpc++/support/dynamic_thread_pool.h b/include/grpc++/support/dynamic_thread_pool.h
deleted file mode 100644
index 6062705129..0000000000
--- a/include/grpc++/support/dynamic_thread_pool.h
+++ /dev/null
@@ -1,82 +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 GRPCXX_SUPPORT_DYNAMIC_THREAD_POOL_H
-#define GRPCXX_SUPPORT_DYNAMIC_THREAD_POOL_H
-
-#include <list>
-#include <memory>
-#include <queue>
-
-#include <grpc++/impl/sync.h>
-#include <grpc++/impl/thd.h>
-#include <grpc++/support/config.h>
-#include <grpc++/support/thread_pool_interface.h>
-
-namespace grpc {
-
-class DynamicThreadPool GRPC_FINAL : public ThreadPoolInterface {
- public:
- explicit DynamicThreadPool(int reserve_threads);
- ~DynamicThreadPool();
-
- void Add(const std::function<void()>& callback) GRPC_OVERRIDE;
-
- private:
- class DynamicThread {
- public:
- DynamicThread(DynamicThreadPool* pool);
- ~DynamicThread();
-
- private:
- DynamicThreadPool* pool_;
- std::unique_ptr<grpc::thread> thd_;
- void ThreadFunc();
- };
- grpc::mutex mu_;
- grpc::condition_variable cv_;
- grpc::condition_variable shutdown_cv_;
- bool shutdown_;
- std::queue<std::function<void()>> callbacks_;
- int reserve_threads_;
- int nthreads_;
- int threads_waiting_;
- std::list<DynamicThread*> dead_threads_;
-
- void ThreadFunc();
- static void ReapThreads(std::list<DynamicThread*>* tlist);
-};
-
-} // namespace grpc
-
-#endif // GRPCXX_SUPPORT_DYNAMIC_THREAD_POOL_H
diff --git a/include/grpc++/support/fixed_size_thread_pool.h b/include/grpc++/support/fixed_size_thread_pool.h
deleted file mode 100644
index 46ed745eff..0000000000
--- a/include/grpc++/support/fixed_size_thread_pool.h
+++ /dev/null
@@ -1,66 +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 GRPCXX_SUPPORT_FIXED_SIZE_THREAD_POOL_H
-#define GRPCXX_SUPPORT_FIXED_SIZE_THREAD_POOL_H
-
-#include <queue>
-#include <vector>
-
-#include <grpc++/impl/sync.h>
-#include <grpc++/impl/thd.h>
-#include <grpc++/support/config.h>
-#include <grpc++/support/thread_pool_interface.h>
-
-namespace grpc {
-
-class FixedSizeThreadPool GRPC_FINAL : public ThreadPoolInterface {
- public:
- explicit FixedSizeThreadPool(int num_threads);
- ~FixedSizeThreadPool();
-
- void Add(const std::function<void()>& callback) GRPC_OVERRIDE;
-
- private:
- grpc::mutex mu_;
- grpc::condition_variable cv_;
- bool shutdown_;
- std::queue<std::function<void()>> callbacks_;
- std::vector<grpc::thread*> threads_;
-
- void ThreadFunc();
-};
-
-} // namespace grpc
-
-#endif // GRPCXX_SUPPORT_FIXED_SIZE_THREAD_POOL_H
diff --git a/include/grpc++/support/thread_pool_interface.h b/include/grpc++/support/thread_pool_interface.h
deleted file mode 100644
index 6528e7276f..0000000000
--- a/include/grpc++/support/thread_pool_interface.h
+++ /dev/null
@@ -1,54 +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 GRPCXX_SUPPORT_THREAD_POOL_INTERFACE_H
-#define GRPCXX_SUPPORT_THREAD_POOL_INTERFACE_H
-
-#include <functional>
-
-namespace grpc {
-
-// A thread pool interface for running callbacks.
-class ThreadPoolInterface {
- public:
- virtual ~ThreadPoolInterface() {}
-
- // Schedule the given callback for execution.
- virtual void Add(const std::function<void()>& callback) = 0;
-};
-
-ThreadPoolInterface* CreateDefaultThreadPool();
-
-} // namespace grpc
-
-#endif // GRPCXX_SUPPORT_THREAD_POOL_INTERFACE_H