Skip to content

Commit

Permalink
fixup: use helloworld API
Browse files Browse the repository at this point in the history
  • Loading branch information
eugeneo committed Aug 29, 2024
1 parent 9b3f183 commit 7214e38
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
4 changes: 2 additions & 2 deletions examples/cpp/flow_control/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ cc_binary(
deps = [
"//:grpc++",
"//:grpc++_reflection",
"//examples/protos:hellostreamingworld",
"//examples/protos:helloworld_cc_grpc",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/flags:parse",
],
Expand All @@ -34,7 +34,7 @@ cc_binary(
deps = [
"//:grpc++",
"//:grpc++_reflection",
"//examples/protos:hellostreamingworld",
"//examples/protos:helloworld_cc_grpc",
"@com_google_absl//absl/flags:flag",
"@com_google_absl//absl/flags:parse",
],
Expand Down
10 changes: 5 additions & 5 deletions examples/cpp/flow_control/CMakeLists.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions examples/cpp/flow_control/server_flow_control_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
#include <grpcpp/grpcpp.h>

#ifdef BAZEL_BUILD
#include "examples/protos/hellostreamingworld.grpc.pb.h"
#include "examples/protos/helloworld.grpc.pb.h"
#else
#include "hellostreamingworld.grpc.pb.h"
#include "helloworld.grpc.pb.h"
#endif

ABSL_FLAG(std::string, target, "localhost:50051", "Server address");
Expand All @@ -39,8 +39,7 @@ ABSL_FLAG(bool, bdp_probe, false,

namespace {

class Reader final
: public grpc::ClientReadReactor<hellostreamingworld::HelloReply> {
class Reader final : public grpc::ClientReadReactor<helloworld::HelloReply> {
public:
void Start() {
StartRead(&res_);
Expand Down Expand Up @@ -74,7 +73,7 @@ class Reader final
private:
absl::Mutex mu_;
absl::optional<grpc::Status> result_;
hellostreamingworld::HelloReply res_;
helloworld::HelloReply res_;
};

} // namespace
Expand All @@ -91,12 +90,12 @@ int main(int argc, char* argv[]) {
auto channel = grpc::CreateCustomChannel(absl::GetFlag(FLAGS_target),
grpc::InsecureChannelCredentials(),
channel_arguments);
auto greeter = hellostreamingworld::MultiGreeter::NewStub(channel);
auto greeter = helloworld::Greeter::NewStub(channel);
grpc::ClientContext ctx;
hellostreamingworld::HelloRequest req;
helloworld::HelloRequest req;
req.set_name("World");
Reader reader;
greeter->async()->sayHello(&ctx, &req, &reader);
greeter->async()->SayHelloStreamReply(&ctx, &req, &reader);
reader.Start();
auto status = reader.WaitForDone();
if (status.ok()) {
Expand Down
15 changes: 7 additions & 8 deletions examples/cpp/flow_control/server_flow_control_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
#include <grpcpp/support/status.h>

#ifdef BAZEL_BUILD
#include "examples/protos/hellostreamingworld.grpc.pb.h"
#include "examples/protos/helloworld.grpc.pb.h"
#else
#include "hellostreamingworld.grpc.pb.h"
#include "helloworld.grpc.pb.h"
#endif

ABSL_FLAG(uint16_t, port, 50051, "Server port for the service");
Expand All @@ -53,7 +53,7 @@ namespace {
* previous one is done.
*/
class HelloReactor final
: public grpc::ServerWriteReactor<hellostreamingworld::HelloReply> {
: public grpc::ServerWriteReactor<helloworld::HelloReply> {
public:
HelloReactor(size_t message_size, size_t to_send)
: messages_to_send_(to_send) {
Expand Down Expand Up @@ -88,21 +88,20 @@ class HelloReactor final
void OnDone() override { delete this; }

private:
hellostreamingworld::HelloReply res_;
helloworld::HelloReply res_;
size_t messages_to_send_;
absl::optional<absl::Time> write_start_time_;
absl::Mutex mu_;
};

class GreeterService final
: public hellostreamingworld::MultiGreeter::CallbackService {
class GreeterService final : public helloworld::Greeter::CallbackService {
public:
GreeterService(size_t message_size, size_t to_send)
: message_size_(message_size), to_send_(to_send) {}

grpc::ServerWriteReactor<hellostreamingworld::HelloReply>* sayHello(
grpc::ServerWriteReactor<helloworld::HelloReply>* SayHelloStreamReply(
grpc::CallbackServerContext* /*context*/,
const hellostreamingworld::HelloRequest* request) override {
const helloworld::HelloRequest* request) override {
return new HelloReactor(message_size_, to_send_);
}

Expand Down

0 comments on commit 7214e38

Please sign in to comment.