Fix route guide example

pull/18460/head
Juanli Shen 6 years ago
parent 668fc0cf32
commit 3f3f177222
  1. 9
      examples/cpp/route_guide/route_guide_server.cc

@ -147,24 +147,25 @@ class RouteGuideImpl final : public RouteGuide::Service {
Status RouteChat(ServerContext* context, Status RouteChat(ServerContext* context,
ServerReaderWriter<RouteNote, RouteNote>* stream) override { ServerReaderWriter<RouteNote, RouteNote>* stream) override {
std::vector<RouteNote> received_notes;
RouteNote note; RouteNote note;
while (stream->Read(&note)) { while (stream->Read(&note)) {
for (const RouteNote& n : received_notes) { std::unique_lock<std::mutex> lock(mu_);
for (const RouteNote& n : received_notes_) {
if (n.location().latitude() == note.location().latitude() && if (n.location().latitude() == note.location().latitude() &&
n.location().longitude() == note.location().longitude()) { n.location().longitude() == note.location().longitude()) {
stream->Write(n); stream->Write(n);
} }
} }
received_notes.push_back(note); received_notes_.push_back(note);
} }
return Status::OK; return Status::OK;
} }
private: private:
std::vector<Feature> feature_list_; std::vector<Feature> feature_list_;
std::mutex mu_;
std::vector<RouteNote> received_notes_;
}; };
void RunServer(const std::string& db_path) { void RunServer(const std::string& db_path) {

Loading…
Cancel
Save