Hey Sree, thank you for sharing this. Can you please check this out: https://groups.google.com/g/grpc-io/c/3LMvM62SAo0 ?
Thank you in advance! В 9:50:58 UTC+2на сряда, 25 януари 2017 г. Sree Kuchibhotla написа: > Glad to know if worked. Thanks :) > > -Sree > > On Tue, Jan 24, 2017 at 10:07 PM, <[email protected]> wrote: > >> Thank you Sree! It is working now. I really appreciate your help. You >> guys are awesome! >> >> Sree Kuchibhotla於 2017年1月24日星期二 UTC-8下午9時07分51秒寫道: >> >>> Hi, >>> You are incorrectly using the async streaming API on the server side. >>> >>> In the following code, stream_.Read(), stream_.Write() and >>> stream_.Finish() >>> are three *Async* calls -and would return immediately. You should have >>> done a cq_.Next() after each call to make sure the async operations >>> actually completed. >>> >>> --- >>> std::string prefix("Hello "); >>> stream_.Read(&request_, this); >>> >>> //*** SREE: You should wait for cq_.Next() to return the tag >>> (i.e 'this') before proceeding *** >>> // It is not safe to proceed without that >>> >>> std::cout << "Greeter server received: " << request_.message() >>> << std::endl; >>> reply_.set_message(prefix + request_.message()); >>> std::cout << "Greeter server replied: " << reply_.message() << >>> std::endl; >>> stream_.Write(reply_, this); >>> >>> //*** SREE: You should wait for cq_.Next() to return the tag (i.e >>> 'this') before proceeding *** >>> >>> // 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; >>> stream_.Finish(Status::OK, this); >>> --- >>> >>> The correct way to do it is: >>> >>> 1) Expand your state-machine in CallData. i.e change enum CallStatus >>> { CREATE, PROCESS, FINISH }; >>> to enum CallStatus { CREATE, PROCESS, READ_CALLED, WRITE_CALLED, FINISH >>> }; >>> >>> 2) Change your Proceed() function to something like below: >>> >>> void Proceed() { >>> switch(status_) { >>> case CREATE: { >>> service_->RequestSayHello(&ctx_, &stream_, cq_, cq_, this); >>> status_ = PROCESS; >>> break; >>> } >>> case PROCESS: { >>> new CallData(service_, cq_); >>> >>> std::string prefix("Hello "); >>> stream_.Read(&request_, this); >>> status_ = READ_CALLED; >>> break; >>> } >>> case READ_CALLED: { >>> std::cout << "Greeter server received: " << request_.message() >>> << std::endl; >>> reply_.set_message(prefix + request_.message()); >>> std::cout << "Greeter server replied: " << reply_.message() << >>> std::endl; >>> stream_.Write(reply_, this); >>> >>> status_ = WRITE_CALLED; >>> break; >>> } >>> case WRITE_CALLED: { >>> stream_.Finish(Status::OK, this); >>> status_ = FINISH; >>> break; >>> } >>> case FINISH: { >>> delete this; >>> } >>> } >>> >>> >>> Hope this helps, >>> >>> thanks, >>> Sree >>> >>> -- >> 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 post to this group, send email to [email protected]. >> Visit this group at https://groups.google.com/group/grpc-io. >> > To view this discussion on the web visit >> https://groups.google.com/d/msgid/grpc-io/b1582036-1946-4707-8ef3-b49688e2cd18%40googlegroups.com >> >> <https://groups.google.com/d/msgid/grpc-io/b1582036-1946-4707-8ef3-b49688e2cd18%40googlegroups.com?utm_medium=email&utm_source=footer> >> . > > >> For more options, visit https://groups.google.com/d/optout. >> > -- 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/c8a9f40d-df88-4dae-b691-6453e9abfa34n%40googlegroups.com.
