aboutsummaryrefslogtreecommitdiff
path: root/pw_rpc/server.cc
diff options
context:
space:
mode:
Diffstat (limited to 'pw_rpc/server.cc')
-rw-r--r--pw_rpc/server.cc41
1 files changed, 33 insertions, 8 deletions
diff --git a/pw_rpc/server.cc b/pw_rpc/server.cc
index 4af9ff4e6..8822a0fd0 100644
--- a/pw_rpc/server.cc
+++ b/pw_rpc/server.cc
@@ -92,8 +92,8 @@ Status Server::ProcessPacket(ConstByteSpan packet_data) {
internal::rpc_lock().unlock();
}
break;
- case PacketType::CLIENT_STREAM_END:
- HandleClientStreamPacket(packet, *channel, call);
+ case PacketType::CLIENT_REQUEST_COMPLETION:
+ HandleCompletionRequest(packet, *channel, call);
break;
case PacketType::REQUEST: // Handled above
case PacketType::RESPONSE:
@@ -122,6 +122,35 @@ std::tuple<Service*, const internal::Method*> Server::FindMethod(
return {&(*service), service->FindMethod(packet.method_id())};
}
+void Server::HandleCompletionRequest(
+ const internal::Packet& packet,
+ internal::Channel& channel,
+ IntrusiveList<internal::Call>::iterator call) const {
+ if (call == calls_end()) {
+ channel.Send(Packet::ServerError(packet, Status::FailedPrecondition()))
+ .IgnoreError(); // Errors are logged in Channel::Send.
+ internal::rpc_lock().unlock();
+ PW_LOG_DEBUG(
+ "Received a request completion packet for %u:%08x/%08x, which is not a"
+ "pending call",
+ static_cast<unsigned>(packet.channel_id()),
+ static_cast<unsigned>(packet.service_id()),
+ static_cast<unsigned>(packet.method_id()));
+ return;
+ }
+
+ if (call->client_requested_completion()) {
+ internal::rpc_lock().unlock();
+ PW_LOG_DEBUG("Received multiple completion requests for %u:%08x/%08x",
+ static_cast<unsigned>(packet.channel_id()),
+ static_cast<unsigned>(packet.service_id()),
+ static_cast<unsigned>(packet.method_id()));
+ return;
+ }
+
+ static_cast<internal::ServerCall&>(*call).HandleClientRequestedCompletion();
+}
+
void Server::HandleClientStreamPacket(
const internal::Packet& packet,
internal::Channel& channel,
@@ -151,7 +180,7 @@ void Server::HandleClientStreamPacket(
return;
}
- if (!call->client_stream_open()) {
+ if (call->client_requested_completion()) {
channel.Send(Packet::ServerError(packet, Status::FailedPrecondition()))
.IgnoreError(); // Errors are logged in Channel::Send.
internal::rpc_lock().unlock();
@@ -164,11 +193,7 @@ void Server::HandleClientStreamPacket(
return;
}
- if (packet.type() == PacketType::CLIENT_STREAM) {
- call->HandlePayload(packet.payload());
- } else { // Handle PacketType::CLIENT_STREAM_END.
- static_cast<internal::ServerCall&>(*call).HandleClientStreamEnd();
- }
+ call->HandlePayload(packet.payload());
}
} // namespace pw::rpc