I'm trying to implement async RPC for multiple methods and going by their 
async greeter [server][1]/[client][2] example, it's not entirely clear how 
the server handles different methods as the example only implements a 
single method for the server, `SayHello` and there's no corresponding 
method named `SayHello` on the server like there is for the [synchronous 
version][2].

Instead, the logic for handling `SayHello` seems to be handled in the 
`Proceed` function. If I wanted to create another method, do I just handle 
it all in Proceed? And if so, how would I do that?

    void Proceed() {
          if (status_ == CREATE) {
            // Make this instance progress to the PROCESS state.
            status_ = PROCESS;
    
            // As part of the initial CREATE state, we *request* that the 
system
            // start processing SayHello requests. In this request, "this" 
acts are
            // the tag uniquely identifying the request (so that different 
CallData
            // instances can serve different requests concurrently), in 
this case
            // the memory address of this CallData instance.
            service_->RequestSayHello(&ctx_, &request_, &responder_, cq_, 
cq_,
                                      this);
          } else if (status_ == PROCESS) {
            // Spawn a new CallData instance to serve new clients while we 
process
            // the one for this CallData. The instance will deallocate 
itself as
            // part of its FINISH state.
            new CallData(service_, cq_);
    
            // The actual processing.
            std::string prefix("Hello ");
            reply_.set_message(prefix + request_.name());
    
            // And we are done! Let the gRPC runtime know we've finished, 
using the
            // memory address of this instance as the uniquely identifying 
tag for
            // the event.
            status_ = FINISH;
            responder_.Finish(reply_, Status::OK, this);
          } else {
            GPR_ASSERT(status_ == FINISH);
            // Once in the FINISH state, deallocate ourselves (CallData).
            delete this;
          }
        }


  [1]: 
https://github.com/grpc/grpc/blob/v1.33.2/examples/cpp/helloworld/greeter_async_server.cc
  [2]: 
https://github.com/grpc/grpc/blob/v1.33.2/examples/cpp/helloworld/greeter_async_client.cc

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/017936fc-7df7-4dc5-999c-a4d7b6e3bf90n%40googlegroups.com.

Reply via email to