aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pw_rpc/call.cc4
-rw-r--r--pw_rpc/docs.rst7
-rw-r--r--pw_rpc/raw/client_reader_writer_test.cc14
3 files changed, 22 insertions, 3 deletions
diff --git a/pw_rpc/call.cc b/pw_rpc/call.cc
index ed16c1f4c..e96fd793f 100644
--- a/pw_rpc/call.cc
+++ b/pw_rpc/call.cc
@@ -62,6 +62,10 @@ Call::Call(LockedEndpoint& endpoint_ref,
? kClientStreamActive
: kClientStreamInactive),
properties_(properties) {
+ PW_CHECK_UINT_NE(channel_id,
+ Channel::kUnassignedChannelId,
+ "Calls cannot be created with channel ID 0 "
+ "(Channel::kUnassignedChannelId)");
endpoint().RegisterCall(*this);
}
diff --git a/pw_rpc/docs.rst b/pw_rpc/docs.rst
index 3e8bf6b1f..133f41310 100644
--- a/pw_rpc/docs.rst
+++ b/pw_rpc/docs.rst
@@ -927,7 +927,8 @@ Example
// Generated clients are namespaced with their proto library.
using EchoClient = pw_rpc::nanopb::EchoService::Client;
- // RPC channel ID on which to make client calls.
+ // RPC channel ID on which to make client calls. RPC calls cannot be made on
+ // channel 0 (Channel::kUnassignedChannelId).
constexpr uint32_t kDefaultChannelId = 1;
pw::rpc::NanopbUnaryReceiver<pw_rpc_EchoMessage> echo_call;
@@ -1191,8 +1192,8 @@ instantiate as:
``MethodRequestType<RpcMethod>``/``MethodResponseType<RpcMethod>``. Raw has
them both set as ``void``. In reality, they are ``pw::ConstByteSpan``. Any
helper/trait that wants to use this types for raw methods should do a custom
- implemenation that copies the bytes under the span instead of copying just the
- span.
+ implementation that copies the bytes under the span instead of copying just
+ the span.
Client Synchronous Call wrappers
================================
diff --git a/pw_rpc/raw/client_reader_writer_test.cc b/pw_rpc/raw/client_reader_writer_test.cc
index 7b4184f0b..98b394679 100644
--- a/pw_rpc/raw/client_reader_writer_test.cc
+++ b/pw_rpc/raw/client_reader_writer_test.cc
@@ -14,6 +14,8 @@
#include "pw_rpc/raw/client_reader_writer.h"
+#include <optional>
+
#include "gtest/gtest.h"
#include "pw_rpc/raw/client_testing.h"
#include "pw_rpc/writer.h"
@@ -310,6 +312,18 @@ TEST(RawUnaryReceiver, Move_ActiveToActive) {
EXPECT_TRUE(active_call_2.active());
}
+TEST(RawUnaryReceiver, InvalidChannelId) {
+ RawClientTestContext ctx;
+ std::optional<Status> error;
+
+ RawUnaryReceiver call = TestService::TestUnaryRpc(
+ ctx.client(), 1290341, {}, {}, [&error](Status status) {
+ error = status;
+ });
+ EXPECT_FALSE(call.active());
+ EXPECT_EQ(error, Status::Unavailable());
+}
+
TEST(RawClientReader, NoClientStream_OutOfScope_SilentlyCloses) {
RawClientTestContext ctx;