Add a way to override channel arguments for server creation

pull/5287/head
yang-g 9 years ago
parent b4b7324e4c
commit eb62c94338
  1. 6
      include/grpc++/server.h
  2. 14
      src/cpp/server/server.cc
  3. 2
      src/cpp/server/server_builder.cc

@ -79,6 +79,8 @@ class Server GRPC_FINAL : public ServerInterface, private GrpcLibrary {
class GlobalCallbacks { class GlobalCallbacks {
public: public:
virtual ~GlobalCallbacks() {} virtual ~GlobalCallbacks() {}
/// Called before server is created.
virtual void UpdateArguments(ChannelArguments* args) {}
/// Called before application callback for each synchronous server request /// Called before application callback for each synchronous server request
virtual void PreSynchronousRequest(ServerContext* context) = 0; virtual void PreSynchronousRequest(ServerContext* context) = 0;
/// Called after application callback for each synchronous server request /// Called after application callback for each synchronous server request
@ -108,7 +110,7 @@ class Server GRPC_FINAL : public ServerInterface, private GrpcLibrary {
/// \param max_message_size Maximum message length that the channel can /// \param max_message_size Maximum message length that the channel can
/// receive. /// receive.
Server(ThreadPoolInterface* thread_pool, bool thread_pool_owned, Server(ThreadPoolInterface* thread_pool, bool thread_pool_owned,
int max_message_size, const ChannelArguments& args); int max_message_size, ChannelArguments* args);
/// Register a service. This call does not take ownership of the service. /// Register a service. This call does not take ownership of the service.
/// The service must exist for the lifetime of the Server instance. /// The service must exist for the lifetime of the Server instance.
@ -177,7 +179,7 @@ class Server GRPC_FINAL : public ServerInterface, private GrpcLibrary {
bool has_generic_service_; bool has_generic_service_;
// Pointer to the c grpc server. // Pointer to the c grpc server.
grpc_server* const server_; grpc_server* server_;
ThreadPoolInterface* thread_pool_; ThreadPoolInterface* thread_pool_;
// Whether the thread pool is created and owned by the server. // Whether the thread pool is created and owned by the server.

@ -272,27 +272,25 @@ class Server::SyncRequest GRPC_FINAL : public CompletionQueueTag {
grpc_completion_queue* cq_; grpc_completion_queue* cq_;
}; };
static grpc_server* CreateServer(const ChannelArguments& args) {
grpc_channel_args channel_args;
args.SetChannelArgs(&channel_args);
return grpc_server_create(&channel_args, nullptr);
}
static internal::GrpcLibraryInitializer g_gli_initializer; static internal::GrpcLibraryInitializer g_gli_initializer;
Server::Server(ThreadPoolInterface* thread_pool, bool thread_pool_owned, Server::Server(ThreadPoolInterface* thread_pool, bool thread_pool_owned,
int max_message_size, const ChannelArguments& args) int max_message_size, ChannelArguments* args)
: max_message_size_(max_message_size), : max_message_size_(max_message_size),
started_(false), started_(false),
shutdown_(false), shutdown_(false),
num_running_cb_(0), num_running_cb_(0),
sync_methods_(new std::list<SyncRequest>), sync_methods_(new std::list<SyncRequest>),
has_generic_service_(false), has_generic_service_(false),
server_(CreateServer(args)), server_(nullptr),
thread_pool_(thread_pool), thread_pool_(thread_pool),
thread_pool_owned_(thread_pool_owned) { thread_pool_owned_(thread_pool_owned) {
g_gli_initializer.summon(); g_gli_initializer.summon();
gpr_once_init(&g_once_init_callbacks, InitGlobalCallbacks); gpr_once_init(&g_once_init_callbacks, InitGlobalCallbacks);
global_callbacks_ = g_callbacks; global_callbacks_ = g_callbacks;
global_callbacks_->UpdateArguments(args);
grpc_channel_args channel_args;
args->SetChannelArgs(&channel_args);
server_ = grpc_server_create(&channel_args, nullptr);
grpc_server_register_completion_queue(server_, cq_.cq(), nullptr); grpc_server_register_completion_queue(server_, cq_.cq(), nullptr);
} }

@ -103,7 +103,7 @@ std::unique_ptr<Server> ServerBuilder::BuildAndStart() {
args.SetInt(GRPC_COMPRESSION_ALGORITHM_STATE_ARG, args.SetInt(GRPC_COMPRESSION_ALGORITHM_STATE_ARG,
compression_options_.enabled_algorithms_bitset); compression_options_.enabled_algorithms_bitset);
std::unique_ptr<Server> server( std::unique_ptr<Server> server(
new Server(thread_pool.release(), true, max_message_size_, args)); new Server(thread_pool.release(), true, max_message_size_, &args));
for (auto cq = cqs_.begin(); cq != cqs_.end(); ++cq) { for (auto cq = cqs_.begin(); cq != cqs_.end(); ++cq) {
grpc_server_register_completion_queue(server->server_, (*cq)->cq(), grpc_server_register_completion_queue(server->server_, (*cq)->cq(),
nullptr); nullptr);

Loading…
Cancel
Save