mirror of https://github.com/grpc/grpc.io.git
fix: resolve inconsistency between doc and code (#1021)
* fix: resolve inconsistent between doc and code * chore: fix typo * chore: refine doc
This commit is contained in:
parent
c19bd55eeb
commit
f99dc0fe34
|
@ -284,16 +284,16 @@ Finally, let's look at our bidirectional streaming RPC `RouteChat()`.
|
||||||
```cpp
|
```cpp
|
||||||
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(¬e)) {
|
while (stream->Read(¬e)) {
|
||||||
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;
|
||||||
|
@ -307,6 +307,9 @@ get the other's messages in the order they were written, both the client and
|
||||||
server can read and write in any order — the streams operate completely
|
server can read and write in any order — the streams operate completely
|
||||||
independently.
|
independently.
|
||||||
|
|
||||||
|
Note that since `received_notes_` is an instance variable and can be accessed by
|
||||||
|
multiple threads, we use a mutex lock here to guarantee exclusive access.
|
||||||
|
|
||||||
#### Starting the server
|
#### Starting the server
|
||||||
|
|
||||||
Once we've implemented all our methods, we also need to start up a gRPC server
|
Once we've implemented all our methods, we also need to start up a gRPC server
|
||||||
|
|
Loading…
Reference in New Issue