aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/cpp/server
diff options
context:
space:
mode:
authorGravatar David Garcia Quintas <dgq@google.com>2015-07-15 14:07:18 -0700
committerGravatar David Garcia Quintas <dgq@google.com>2015-07-15 14:07:18 -0700
commite0d581b6ad1023635598d9de95bd951cd04b0354 (patch)
treea0601b1315a1dc7b499998a95adba61322825f3c /src/cpp/server
parent658b6087cc07f8706d270ee0e31f28bbf732ec3d (diff)
parent3e5d61670e23b040ed47b2df1e4c87ee2cfec4aa (diff)
Merge branch 'master' of github.com:grpc/grpc into decompression
# Conflicts: # Makefile # include/grpc++/client_context.h # include/grpc++/server_context.h # src/cpp/client/client_context.cc # src/cpp/server/server_context.cc # vsprojects/Grpc.mak
Diffstat (limited to 'src/cpp/server')
-rw-r--r--src/cpp/server/async_server_context.cc99
-rw-r--r--src/cpp/server/server.cc4
-rw-r--r--src/cpp/server/server_context.cc13
3 files changed, 15 insertions, 101 deletions
diff --git a/src/cpp/server/async_server_context.cc b/src/cpp/server/async_server_context.cc
deleted file mode 100644
index e1f29452a4..0000000000
--- a/src/cpp/server/async_server_context.cc
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- *
- * Copyright 2015, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#include <grpc++/async_server_context.h>
-
-#include <grpc/grpc.h>
-#include <grpc/support/log.h>
-#include "src/cpp/proto/proto_utils.h"
-#include <grpc++/config.h>
-#include <grpc++/status.h>
-
-namespace grpc {
-
-AsyncServerContext::AsyncServerContext(
- grpc_call* call, const grpc::string& method, const grpc::string& host,
- system_clock::time_point absolute_deadline)
- : method_(method),
- host_(host),
- absolute_deadline_(absolute_deadline),
- request_(nullptr),
- call_(call) {}
-
-AsyncServerContext::~AsyncServerContext() { grpc_call_destroy(call_); }
-
-void AsyncServerContext::Accept(grpc_completion_queue* cq) {
- GPR_ASSERT(grpc_call_server_accept_old(call_, cq, this) == GRPC_CALL_OK);
- GPR_ASSERT(grpc_call_server_end_initial_metadata_old(
- call_, GRPC_WRITE_BUFFER_HINT) == GRPC_CALL_OK);
-}
-
-bool AsyncServerContext::StartRead(grpc::protobuf::Message* request) {
- GPR_ASSERT(request);
- request_ = request;
- grpc_call_error err = grpc_call_start_read_old(call_, this);
- return err == GRPC_CALL_OK;
-}
-
-bool AsyncServerContext::StartWrite(const grpc::protobuf::Message& response,
- int flags) {
- grpc_byte_buffer* buffer = nullptr;
- GRPC_TIMER_MARK(SER_PROTO_BEGIN, call_->call());
- if (!SerializeProto(response, &buffer)) {
- return false;
- }
- GRPC_TIMER_MARK(SER_PROTO_END, call_->call());
- grpc_call_error err = grpc_call_start_write_old(call_, buffer, this, flags);
- grpc_byte_buffer_destroy(buffer);
- return err == GRPC_CALL_OK;
-}
-
-bool AsyncServerContext::StartWriteStatus(const Status& status) {
- grpc_call_error err = grpc_call_start_write_status_old(
- call_, static_cast<grpc_status_code>(status.code()),
- status.details().empty() ? nullptr
- : const_cast<char*>(status.details().c_str()),
- this);
- return err == GRPC_CALL_OK;
-}
-
-bool AsyncServerContext::ParseRead(grpc_byte_buffer* read_buffer) {
- GPR_ASSERT(request_);
- GRPC_TIMER_MARK(DESER_PROTO_BEGIN, call_->call());
- bool success = DeserializeProto(read_buffer, request_);
- GRPC_TIMER_MARK(DESER_PROTO_END, call_->call());
- request_ = nullptr;
- return success;
-}
-
-} // namespace grpc
diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc
index f9d20ff579..e6761d6244 100644
--- a/src/cpp/server/server.cc
+++ b/src/cpp/server/server.cc
@@ -118,7 +118,7 @@ class Server::SyncRequest GRPC_FINAL : public CompletionQueueTag {
has_request_payload_(mrd->has_request_payload_),
request_payload_(mrd->request_payload_),
method_(mrd->method_) {
- ctx_.call_ = mrd->call_;
+ ctx_.set_call(mrd->call_);
ctx_.cq_ = &cq_;
GPR_ASSERT(mrd->in_flight_);
mrd->in_flight_ = false;
@@ -326,7 +326,7 @@ bool Server::BaseAsyncRequest::FinalizeResult(void** tag, bool* status) {
}
}
grpc_metadata_array_destroy(&initial_metadata_array_);
- context_->call_ = call_;
+ context_->set_call(call_);
context_->cq_ = call_cq_;
Call call(call_, server_, call_cq_, server_->max_message_size_);
if (*status && call_) {
diff --git a/src/cpp/server/server_context.cc b/src/cpp/server/server_context.cc
index 087e28d33a..e028b9dc02 100644
--- a/src/cpp/server/server_context.cc
+++ b/src/cpp/server/server_context.cc
@@ -40,6 +40,7 @@
#include <grpc++/time.h>
#include "src/core/channel/compress_filter.h"
+#include "src/cpp/common/create_auth_context.h"
namespace grpc {
@@ -166,4 +167,16 @@ void ServerContext::set_compression_algorithm(
AddInitialMetadata(GRPC_COMPRESS_REQUEST_ALGORITHM_KEY, algorithm_name);
}
+void ServerContext::set_call(grpc_call* call) {
+ call_ = call;
+ auth_context_ = CreateAuthContext(call);
+}
+
+std::shared_ptr<const AuthContext> ServerContext::auth_context() const {
+ if (auth_context_.get() == nullptr) {
+ auth_context_ = CreateAuthContext(call_);
+ }
+ return auth_context_;
+}
+
} // namespace grpc