mirror of https://github.com/grpc/grpc.git
The C based gRPC (C++, Python, Ruby, Objective-C, PHP, C#)
https://grpc.io/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
437 lines
14 KiB
437 lines
14 KiB
10 years ago
|
/*
|
||
|
*
|
||
10 years ago
|
* Copyright 2015, Google Inc.
|
||
10 years ago
|
* 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.
|
||
|
*
|
||
|
*/
|
||
|
|
||
9 years ago
|
#ifndef GRPCXX_SUPPORT_ASYNC_STREAM_H
|
||
|
#define GRPCXX_SUPPORT_ASYNC_STREAM_H
|
||
10 years ago
|
|
||
9 years ago
|
#include <grpc/support/log.h>
|
||
9 years ago
|
#include <grpc++/channel.h>
|
||
10 years ago
|
#include <grpc++/client_context.h>
|
||
10 years ago
|
#include <grpc++/completion_queue.h>
|
||
10 years ago
|
#include <grpc++/impl/call.h>
|
||
10 years ago
|
#include <grpc++/impl/service_type.h>
|
||
9 years ago
|
#include <grpc++/server_context.h>
|
||
|
#include <grpc++/support/status.h>
|
||
10 years ago
|
|
||
|
namespace grpc {
|
||
|
|
||
10 years ago
|
// Async interfaces
|
||
|
// Common interface for all client side streaming.
|
||
|
class ClientAsyncStreamingInterface {
|
||
|
public:
|
||
|
virtual ~ClientAsyncStreamingInterface() {}
|
||
|
|
||
10 years ago
|
virtual void ReadInitialMetadata(void* tag) = 0;
|
||
|
|
||
10 years ago
|
virtual void Finish(Status* status, void* tag) = 0;
|
||
|
};
|
||
|
|
||
|
// An interface that yields a sequence of R messages.
|
||
|
template <class R>
|
||
|
class AsyncReaderInterface {
|
||
|
public:
|
||
|
virtual ~AsyncReaderInterface() {}
|
||
10 years ago
|
|
||
10 years ago
|
virtual void Read(R* msg, void* tag) = 0;
|
||
|
};
|
||
|
|
||
|
// An interface that can be fed a sequence of W messages.
|
||
|
template <class W>
|
||
|
class AsyncWriterInterface {
|
||
|
public:
|
||
10 years ago
|
virtual ~AsyncWriterInterface() {}
|
||
10 years ago
|
|
||
|
virtual void Write(const W& msg, void* tag) = 0;
|
||
|
};
|
||
|
|
||
|
template <class R>
|
||
10 years ago
|
class ClientAsyncReaderInterface : public ClientAsyncStreamingInterface,
|
||
10 years ago
|
public AsyncReaderInterface<R> {};
|
||
10 years ago
|
|
||
|
template <class R>
|
||
|
class ClientAsyncReader GRPC_FINAL : public ClientAsyncReaderInterface<R> {
|
||
10 years ago
|
public:
|
||
10 years ago
|
// Create a stream and write the first request out.
|
||
10 years ago
|
template <class W>
|
||
9 years ago
|
ClientAsyncReader(Channel* channel, CompletionQueue* cq,
|
||
10 years ago
|
const RpcMethod& method, ClientContext* context,
|
||
10 years ago
|
const W& request, void* tag)
|
||
10 years ago
|
: context_(context), call_(channel->CreateCall(method, context, cq)) {
|
||
10 years ago
|
init_ops_.set_output_tag(tag);
|
||
10 years ago
|
init_ops_.SendInitialMetadata(context->send_initial_metadata_);
|
||
10 years ago
|
// TODO(ctiller): don't assert
|
||
10 years ago
|
GPR_ASSERT(init_ops_.SendMessage(request).ok());
|
||
10 years ago
|
init_ops_.ClientSendClose();
|
||
|
call_.PerformOps(&init_ops_);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
void ReadInitialMetadata(void* tag) GRPC_OVERRIDE {
|
||
10 years ago
|
GPR_ASSERT(!context_->initial_metadata_received_);
|
||
|
|
||
10 years ago
|
meta_ops_.set_output_tag(tag);
|
||
10 years ago
|
meta_ops_.RecvInitialMetadata(context_);
|
||
|
call_.PerformOps(&meta_ops_);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
void Read(R* msg, void* tag) GRPC_OVERRIDE {
|
||
10 years ago
|
read_ops_.set_output_tag(tag);
|
||
10 years ago
|
if (!context_->initial_metadata_received_) {
|
||
10 years ago
|
read_ops_.RecvInitialMetadata(context_);
|
||
10 years ago
|
}
|
||
10 years ago
|
read_ops_.RecvMessage(msg);
|
||
|
call_.PerformOps(&read_ops_);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
void Finish(Status* status, void* tag) GRPC_OVERRIDE {
|
||
10 years ago
|
finish_ops_.set_output_tag(tag);
|
||
10 years ago
|
if (!context_->initial_metadata_received_) {
|
||
10 years ago
|
finish_ops_.RecvInitialMetadata(context_);
|
||
10 years ago
|
}
|
||
10 years ago
|
finish_ops_.ClientRecvStatus(context_, status);
|
||
|
call_.PerformOps(&finish_ops_);
|
||
10 years ago
|
}
|
||
|
|
||
|
private:
|
||
10 years ago
|
ClientContext* context_;
|
||
10 years ago
|
Call call_;
|
||
10 years ago
|
CallOpSet<CallOpSendInitialMetadata, CallOpSendMessage, CallOpClientSendClose>
|
||
|
init_ops_;
|
||
10 years ago
|
CallOpSet<CallOpRecvInitialMetadata> meta_ops_;
|
||
|
CallOpSet<CallOpRecvInitialMetadata, CallOpRecvMessage<R>> read_ops_;
|
||
|
CallOpSet<CallOpRecvInitialMetadata, CallOpClientRecvStatus> finish_ops_;
|
||
10 years ago
|
};
|
||
|
|
||
10 years ago
|
template <class W>
|
||
10 years ago
|
class ClientAsyncWriterInterface : public ClientAsyncStreamingInterface,
|
||
|
public AsyncWriterInterface<W> {
|
||
|
public:
|
||
|
virtual void WritesDone(void* tag) = 0;
|
||
|
};
|
||
|
|
||
|
template <class W>
|
||
|
class ClientAsyncWriter GRPC_FINAL : public ClientAsyncWriterInterface<W> {
|
||
10 years ago
|
public:
|
||
10 years ago
|
template <class R>
|
||
9 years ago
|
ClientAsyncWriter(Channel* channel, CompletionQueue* cq,
|
||
10 years ago
|
const RpcMethod& method, ClientContext* context,
|
||
10 years ago
|
R* response, void* tag)
|
||
10 years ago
|
: context_(context), call_(channel->CreateCall(method, context, cq)) {
|
||
10 years ago
|
finish_ops_.RecvMessage(response);
|
||
|
|
||
10 years ago
|
init_ops_.set_output_tag(tag);
|
||
10 years ago
|
init_ops_.SendInitialMetadata(context->send_initial_metadata_);
|
||
|
call_.PerformOps(&init_ops_);
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
void ReadInitialMetadata(void* tag) GRPC_OVERRIDE {
|
||
10 years ago
|
GPR_ASSERT(!context_->initial_metadata_received_);
|
||
|
|
||
10 years ago
|
meta_ops_.set_output_tag(tag);
|
||
10 years ago
|
meta_ops_.RecvInitialMetadata(context_);
|
||
|
call_.PerformOps(&meta_ops_);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
void Write(const W& msg, void* tag) GRPC_OVERRIDE {
|
||
10 years ago
|
write_ops_.set_output_tag(tag);
|
||
10 years ago
|
// TODO(ctiller): don't assert
|
||
10 years ago
|
GPR_ASSERT(write_ops_.SendMessage(msg).ok());
|
||
10 years ago
|
call_.PerformOps(&write_ops_);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
void WritesDone(void* tag) GRPC_OVERRIDE {
|
||
10 years ago
|
writes_done_ops_.set_output_tag(tag);
|
||
10 years ago
|
writes_done_ops_.ClientSendClose();
|
||
|
call_.PerformOps(&writes_done_ops_);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
void Finish(Status* status, void* tag) GRPC_OVERRIDE {
|
||
10 years ago
|
finish_ops_.set_output_tag(tag);
|
||
10 years ago
|
if (!context_->initial_metadata_received_) {
|
||
10 years ago
|
finish_ops_.RecvInitialMetadata(context_);
|
||
10 years ago
|
}
|
||
10 years ago
|
finish_ops_.ClientRecvStatus(context_, status);
|
||
|
call_.PerformOps(&finish_ops_);
|
||
10 years ago
|
}
|
||
|
|
||
|
private:
|
||
10 years ago
|
ClientContext* context_;
|
||
10 years ago
|
Call call_;
|
||
10 years ago
|
CallOpSet<CallOpSendInitialMetadata> init_ops_;
|
||
|
CallOpSet<CallOpRecvInitialMetadata> meta_ops_;
|
||
|
CallOpSet<CallOpSendMessage> write_ops_;
|
||
|
CallOpSet<CallOpClientSendClose> writes_done_ops_;
|
||
10 years ago
|
CallOpSet<CallOpRecvInitialMetadata, CallOpGenericRecvMessage,
|
||
|
CallOpClientRecvStatus> finish_ops_;
|
||
10 years ago
|
};
|
||
|
|
||
10 years ago
|
// Client-side interface for bi-directional streaming.
|
||
|
template <class W, class R>
|
||
10 years ago
|
class ClientAsyncReaderWriterInterface : public ClientAsyncStreamingInterface,
|
||
|
public AsyncWriterInterface<W>,
|
||
|
public AsyncReaderInterface<R> {
|
||
|
public:
|
||
|
virtual void WritesDone(void* tag) = 0;
|
||
|
};
|
||
|
|
||
|
template <class W, class R>
|
||
|
class ClientAsyncReaderWriter GRPC_FINAL
|
||
|
: public ClientAsyncReaderWriterInterface<W, R> {
|
||
10 years ago
|
public:
|
||
9 years ago
|
ClientAsyncReaderWriter(Channel* channel, CompletionQueue* cq,
|
||
10 years ago
|
const RpcMethod& method, ClientContext* context,
|
||
|
void* tag)
|
||
10 years ago
|
: context_(context), call_(channel->CreateCall(method, context, cq)) {
|
||
10 years ago
|
init_ops_.set_output_tag(tag);
|
||
10 years ago
|
init_ops_.SendInitialMetadata(context->send_initial_metadata_);
|
||
|
call_.PerformOps(&init_ops_);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
void ReadInitialMetadata(void* tag) GRPC_OVERRIDE {
|
||
10 years ago
|
GPR_ASSERT(!context_->initial_metadata_received_);
|
||
10 years ago
|
|
||
10 years ago
|
meta_ops_.set_output_tag(tag);
|
||
10 years ago
|
meta_ops_.RecvInitialMetadata(context_);
|
||
|
call_.PerformOps(&meta_ops_);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
void Read(R* msg, void* tag) GRPC_OVERRIDE {
|
||
10 years ago
|
read_ops_.set_output_tag(tag);
|
||
10 years ago
|
if (!context_->initial_metadata_received_) {
|
||
10 years ago
|
read_ops_.RecvInitialMetadata(context_);
|
||
10 years ago
|
}
|
||
10 years ago
|
read_ops_.RecvMessage(msg);
|
||
10 years ago
|
call_.PerformOps(&read_ops_);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
void Write(const W& msg, void* tag) GRPC_OVERRIDE {
|
||
10 years ago
|
write_ops_.set_output_tag(tag);
|
||
10 years ago
|
// TODO(ctiller): don't assert
|
||
10 years ago
|
GPR_ASSERT(write_ops_.SendMessage(msg).ok());
|
||
10 years ago
|
call_.PerformOps(&write_ops_);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
void WritesDone(void* tag) GRPC_OVERRIDE {
|
||
10 years ago
|
writes_done_ops_.set_output_tag(tag);
|
||
10 years ago
|
writes_done_ops_.ClientSendClose();
|
||
|
call_.PerformOps(&writes_done_ops_);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
void Finish(Status* status, void* tag) GRPC_OVERRIDE {
|
||
10 years ago
|
finish_ops_.set_output_tag(tag);
|
||
10 years ago
|
if (!context_->initial_metadata_received_) {
|
||
10 years ago
|
finish_ops_.RecvInitialMetadata(context_);
|
||
10 years ago
|
}
|
||
10 years ago
|
finish_ops_.ClientRecvStatus(context_, status);
|
||
|
call_.PerformOps(&finish_ops_);
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
|
private:
|
||
10 years ago
|
ClientContext* context_;
|
||
10 years ago
|
Call call_;
|
||
10 years ago
|
CallOpSet<CallOpSendInitialMetadata> init_ops_;
|
||
|
CallOpSet<CallOpRecvInitialMetadata> meta_ops_;
|
||
|
CallOpSet<CallOpRecvInitialMetadata, CallOpRecvMessage<R>> read_ops_;
|
||
|
CallOpSet<CallOpSendMessage> write_ops_;
|
||
|
CallOpSet<CallOpClientSendClose> writes_done_ops_;
|
||
|
CallOpSet<CallOpRecvInitialMetadata, CallOpClientRecvStatus> finish_ops_;
|
||
10 years ago
|
};
|
||
|
|
||
10 years ago
|
template <class W, class R>
|
||
10 years ago
|
class ServerAsyncReader GRPC_FINAL : public ServerAsyncStreamingInterface,
|
||
|
public AsyncReaderInterface<R> {
|
||
10 years ago
|
public:
|
||
10 years ago
|
explicit ServerAsyncReader(ServerContext* ctx)
|
||
|
: call_(nullptr, nullptr, nullptr), ctx_(ctx) {}
|
||
10 years ago
|
|
||
10 years ago
|
void SendInitialMetadata(void* tag) GRPC_OVERRIDE {
|
||
10 years ago
|
GPR_ASSERT(!ctx_->sent_initial_metadata_);
|
||
10 years ago
|
|
||
10 years ago
|
meta_ops_.set_output_tag(tag);
|
||
10 years ago
|
meta_ops_.SendInitialMetadata(ctx_->initial_metadata_);
|
||
10 years ago
|
ctx_->sent_initial_metadata_ = true;
|
||
10 years ago
|
call_.PerformOps(&meta_ops_);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
void Read(R* msg, void* tag) GRPC_OVERRIDE {
|
||
10 years ago
|
read_ops_.set_output_tag(tag);
|
||
10 years ago
|
read_ops_.RecvMessage(msg);
|
||
|
call_.PerformOps(&read_ops_);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
void Finish(const W& msg, const Status& status, void* tag) {
|
||
10 years ago
|
finish_ops_.set_output_tag(tag);
|
||
10 years ago
|
if (!ctx_->sent_initial_metadata_) {
|
||
10 years ago
|
finish_ops_.SendInitialMetadata(ctx_->initial_metadata_);
|
||
10 years ago
|
ctx_->sent_initial_metadata_ = true;
|
||
|
}
|
||
10 years ago
|
// The response is dropped if the status is not OK.
|
||
10 years ago
|
if (status.ok()) {
|
||
9 years ago
|
finish_ops_.ServerSendStatus(ctx_->trailing_metadata_,
|
||
|
finish_ops_.SendMessage(msg));
|
||
10 years ago
|
} else {
|
||
|
finish_ops_.ServerSendStatus(ctx_->trailing_metadata_, status);
|
||
10 years ago
|
}
|
||
10 years ago
|
call_.PerformOps(&finish_ops_);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
void FinishWithError(const Status& status, void* tag) {
|
||
10 years ago
|
GPR_ASSERT(!status.ok());
|
||
10 years ago
|
finish_ops_.set_output_tag(tag);
|
||
10 years ago
|
if (!ctx_->sent_initial_metadata_) {
|
||
10 years ago
|
finish_ops_.SendInitialMetadata(ctx_->initial_metadata_);
|
||
10 years ago
|
ctx_->sent_initial_metadata_ = true;
|
||
|
}
|
||
10 years ago
|
finish_ops_.ServerSendStatus(ctx_->trailing_metadata_, status);
|
||
|
call_.PerformOps(&finish_ops_);
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
private:
|
||
10 years ago
|
void BindCall(Call* call) GRPC_OVERRIDE { call_ = *call; }
|
||
10 years ago
|
|
||
|
Call call_;
|
||
10 years ago
|
ServerContext* ctx_;
|
||
10 years ago
|
CallOpSet<CallOpSendInitialMetadata> meta_ops_;
|
||
|
CallOpSet<CallOpRecvMessage<R>> read_ops_;
|
||
10 years ago
|
CallOpSet<CallOpSendInitialMetadata, CallOpSendMessage,
|
||
|
CallOpServerSendStatus> finish_ops_;
|
||
10 years ago
|
};
|
||
|
|
||
|
template <class W>
|
||
10 years ago
|
class ServerAsyncWriter GRPC_FINAL : public ServerAsyncStreamingInterface,
|
||
|
public AsyncWriterInterface<W> {
|
||
10 years ago
|
public:
|
||
10 years ago
|
explicit ServerAsyncWriter(ServerContext* ctx)
|
||
|
: call_(nullptr, nullptr, nullptr), ctx_(ctx) {}
|
||
10 years ago
|
|
||
10 years ago
|
void SendInitialMetadata(void* tag) GRPC_OVERRIDE {
|
||
10 years ago
|
GPR_ASSERT(!ctx_->sent_initial_metadata_);
|
||
|
|
||
10 years ago
|
meta_ops_.set_output_tag(tag);
|
||
10 years ago
|
meta_ops_.SendInitialMetadata(ctx_->initial_metadata_);
|
||
10 years ago
|
ctx_->sent_initial_metadata_ = true;
|
||
10 years ago
|
call_.PerformOps(&meta_ops_);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
void Write(const W& msg, void* tag) GRPC_OVERRIDE {
|
||
10 years ago
|
write_ops_.set_output_tag(tag);
|
||
10 years ago
|
if (!ctx_->sent_initial_metadata_) {
|
||
10 years ago
|
write_ops_.SendInitialMetadata(ctx_->initial_metadata_);
|
||
10 years ago
|
ctx_->sent_initial_metadata_ = true;
|
||
|
}
|
||
10 years ago
|
// TODO(ctiller): don't assert
|
||
10 years ago
|
GPR_ASSERT(write_ops_.SendMessage(msg).ok());
|
||
10 years ago
|
call_.PerformOps(&write_ops_);
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
void Finish(const Status& status, void* tag) {
|
||
10 years ago
|
finish_ops_.set_output_tag(tag);
|
||
10 years ago
|
if (!ctx_->sent_initial_metadata_) {
|
||
10 years ago
|
finish_ops_.SendInitialMetadata(ctx_->initial_metadata_);
|
||
10 years ago
|
ctx_->sent_initial_metadata_ = true;
|
||
|
}
|
||
10 years ago
|
finish_ops_.ServerSendStatus(ctx_->trailing_metadata_, status);
|
||
|
call_.PerformOps(&finish_ops_);
|
||
10 years ago
|
}
|
||
|
|
||
|
private:
|
||
10 years ago
|
void BindCall(Call* call) GRPC_OVERRIDE { call_ = *call; }
|
||
10 years ago
|
|
||
|
Call call_;
|
||
10 years ago
|
ServerContext* ctx_;
|
||
10 years ago
|
CallOpSet<CallOpSendInitialMetadata> meta_ops_;
|
||
|
CallOpSet<CallOpSendInitialMetadata, CallOpSendMessage> write_ops_;
|
||
|
CallOpSet<CallOpSendInitialMetadata, CallOpServerSendStatus> finish_ops_;
|
||
10 years ago
|
};
|
||
|
|
||
|
// Server-side interface for bi-directional streaming.
|
||
|
template <class W, class R>
|
||
10 years ago
|
class ServerAsyncReaderWriter GRPC_FINAL : public ServerAsyncStreamingInterface,
|
||
|
public AsyncWriterInterface<W>,
|
||
|
public AsyncReaderInterface<R> {
|
||
10 years ago
|
public:
|
||
10 years ago
|
explicit ServerAsyncReaderWriter(ServerContext* ctx)
|
||
|
: call_(nullptr, nullptr, nullptr), ctx_(ctx) {}
|
||
10 years ago
|
|
||
10 years ago
|
void SendInitialMetadata(void* tag) GRPC_OVERRIDE {
|
||
10 years ago
|
GPR_ASSERT(!ctx_->sent_initial_metadata_);
|
||
|
|
||
10 years ago
|
meta_ops_.set_output_tag(tag);
|
||
10 years ago
|
meta_ops_.SendInitialMetadata(ctx_->initial_metadata_);
|
||
10 years ago
|
ctx_->sent_initial_metadata_ = true;
|
||
10 years ago
|
call_.PerformOps(&meta_ops_);
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
void Read(R* msg, void* tag) GRPC_OVERRIDE {
|
||
10 years ago
|
read_ops_.set_output_tag(tag);
|
||
|
read_ops_.RecvMessage(msg);
|
||
10 years ago
|
call_.PerformOps(&read_ops_);
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
void Write(const W& msg, void* tag) GRPC_OVERRIDE {
|
||
10 years ago
|
write_ops_.set_output_tag(tag);
|
||
10 years ago
|
if (!ctx_->sent_initial_metadata_) {
|
||
10 years ago
|
write_ops_.SendInitialMetadata(ctx_->initial_metadata_);
|
||
10 years ago
|
ctx_->sent_initial_metadata_ = true;
|
||
|
}
|
||
10 years ago
|
// TODO(ctiller): don't assert
|
||
10 years ago
|
GPR_ASSERT(write_ops_.SendMessage(msg).ok());
|
||
10 years ago
|
call_.PerformOps(&write_ops_);
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
10 years ago
|
void Finish(const Status& status, void* tag) {
|
||
10 years ago
|
finish_ops_.set_output_tag(tag);
|
||
10 years ago
|
if (!ctx_->sent_initial_metadata_) {
|
||
10 years ago
|
finish_ops_.SendInitialMetadata(ctx_->initial_metadata_);
|
||
10 years ago
|
ctx_->sent_initial_metadata_ = true;
|
||
|
}
|
||
10 years ago
|
finish_ops_.ServerSendStatus(ctx_->trailing_metadata_, status);
|
||
|
call_.PerformOps(&finish_ops_);
|
||
10 years ago
|
}
|
||
|
|
||
|
private:
|
||
9 years ago
|
friend class ::grpc::Server;
|
||
|
|
||
10 years ago
|
void BindCall(Call* call) GRPC_OVERRIDE { call_ = *call; }
|
||
10 years ago
|
|
||
|
Call call_;
|
||
10 years ago
|
ServerContext* ctx_;
|
||
10 years ago
|
CallOpSet<CallOpSendInitialMetadata> meta_ops_;
|
||
|
CallOpSet<CallOpRecvMessage<R>> read_ops_;
|
||
|
CallOpSet<CallOpSendInitialMetadata, CallOpSendMessage> write_ops_;
|
||
|
CallOpSet<CallOpSendInitialMetadata, CallOpServerSendStatus> finish_ops_;
|
||
10 years ago
|
};
|
||
|
|
||
10 years ago
|
} // namespace grpc
|
||
|
|
||
9 years ago
|
#endif // GRPCXX_SUPPORT_ASYNC_STREAM_H
|