我有一个双向的RPC流式传输RPC,它正在我的c ++ grpc异步服务器中处理。下面是代码:
class MessageTransferService : public GenericCallData {
public:
MessageTransferService (ServiceHandler* service, ServerCompletionQueue* cq)
: service_(service), cq_(cq), stream_(&ctx_), status_(CREATE) {
Proceed();
}
void Proceed() {
if (status_ == CREATE) {
status_ = PROCESS;
service_->RequestMessageTransfer(&ctx_, &stream_, cq_, cq_, this);
} else if (status_ == PROCESS) {
new MessageTransferService (service_, cq_);
Request indication;
stream_.Read(&indication, this);
std::cout<<"Identity"<< indication.identity()<<std::endl; // O/p shows 0
std::cout<<"Payload"<< indication.message()<<std::endl; //Payload appears empty
//Create Response
} else {
GPR_ASSERT(status_ == FINISH);
}
}
private:
ServiceHandler *service_;
ServerCompletionQueue *cq_;
ServerContext ctx_;
Request request_;
Response response_;
ServerAsyncReaderWriter<Request , Response> stream_;
enum CallStatus { CREATE, READ, WRITE, PROCESS, FINISH };
CallStatus status_; // The current serving state.
};
在收到请求并尝试打印请求中包含的信息时,我看到内容全为0,这是不正确的。有人可以帮忙指出这段代码中可能出什么问题。