Commit d34ede5
authored
[all-devices-app] Make the Pigweed RPC server port configurable (project-chip#74139)
* [all-devices-app] Make the Pigweed RPC server port configurable
The POSIX all-devices-app hardcoded the Pigweed RPC listen port to 33000
(with a "TODO: Add an arg for Pw port"), so two instances of the app could
not run concurrently and the in-tree PwRPC test was pinned to that port.
Add a --rpc-server-port option, named to match the equivalent option in
examples/platform/linux so that existing tooling and docs carry over. It
defaults to 33000, so behavior is unchanged when the flag is not passed.
Note this is distinct from --port, which sets the Matter operational port.
The option and the AppConfig field are parsed unconditionally rather than
being guarded by PW_RPC_ENABLED, for two reasons:
- the app_options unit test target does not define PW_RPC_ENABLED, so a
guarded option would compile away and could not be tested;
- all-devices-app defines PW_RPC_ENABLED as 0/1 while
examples/platform/linux/Options.h tests it with #if defined(), so
spreading the define to more targets risks changing the visible layout
of LinuxDeviceOptions between translation units.
Only the consumption of the value in main.cpp is guarded; builds without
Pigweed RPC log a warning if the flag is passed rather than silently
ignoring it.
While here, the duplicated inline port parsing is factored into a shared
AppOptions::ParsePortNumber() used by both --port and --rpc-server-port.
This adds an `endptr == value` check the previous --port code lacked, so
an empty value is now rejected instead of silently parsing as 0.
The boolean-state-sensor PwRPC test no longer hardcodes 127.0.0.1:33000
and accepts "--int-arg rpc_server_port:<port>".
* [all-devices-app] Address review feedback on --rpc-server-port
Two fixes from review:
Reject port 0 for --rpc-server-port. Binding port 0 makes the OS pick an
ephemeral port, and because the pw_rpc port is not advertised anywhere and
the app does not report the port it actually bound, no client could reach
the server. The check is applied at the option site rather than in the
shared ParsePortNumber(), so --port 0 keeps working: the Matter operational
port is advertised over DNS-SD, so an ephemeral port is still resolvable
there.
Track whether --rpc-server-port was actually supplied, by making the
AppConfig field a std::optional<uint16_t> (matching the neighbouring `port`
field). Previously the non-PW_RPC build compared the value against the
default, so "--rpc-server-port 33000" was silently ignored instead of
warning. main.cpp now uses value_or(kDefaultRpcServerPort) when RPC is
enabled and has_value() for the warning when it is not.
* [all-devices-app] Document --rpc-server-port in the boolean-state-sensor test
Wire the new option through both halves of the example invocation in the
test's docstring: --rpc-server-port on the app side and the matching
--int-arg rpc_server_port on the script side, so the two stay in sync.
Addresses review feedback from @sxb427.1 parent bc64de7 commit d34ede5
5 files changed
Lines changed: 156 additions & 11 deletions
File tree
- examples/all-devices-app
- all-devices-common/device/types/boolean-state-sensor
- posix
- app_options
- tests
Lines changed: 9 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
39 | | - | |
| 40 | + | |
| 41 | + | |
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
| |||
103 | 105 | | |
104 | 106 | | |
105 | 107 | | |
106 | | - | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
107 | 112 | | |
108 | 113 | | |
109 | 114 | | |
110 | 115 | | |
111 | | - | |
| 116 | + | |
112 | 117 | | |
113 | 118 | | |
114 | 119 | | |
| |||
Lines changed: 51 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
66 | 67 | | |
67 | 68 | | |
68 | 69 | | |
| |||
112 | 113 | | |
113 | 114 | | |
114 | 115 | | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
115 | 137 | | |
116 | 138 | | |
117 | 139 | | |
| |||
196 | 218 | | |
197 | 219 | | |
198 | 220 | | |
199 | | - | |
200 | | - | |
201 | | - | |
| 221 | + | |
| 222 | + | |
202 | 223 | | |
203 | 224 | | |
204 | 225 | | |
205 | 226 | | |
206 | | - | |
207 | | - | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
208 | 248 | | |
209 | 249 | | |
210 | 250 | | |
| |||
273 | 313 | | |
274 | 314 | | |
275 | 315 | | |
| 316 | + | |
276 | 317 | | |
277 | 318 | | |
278 | 319 | | |
| |||
344 | 385 | | |
345 | 386 | | |
346 | 387 | | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
347 | 393 | | |
348 | 394 | | |
349 | 395 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
33 | 38 | | |
34 | 39 | | |
35 | 40 | | |
| |||
47 | 52 | | |
48 | 53 | | |
49 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
50 | 61 | | |
51 | 62 | | |
52 | 63 | | |
| |||
58 | 69 | | |
59 | 70 | | |
60 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
61 | 77 | | |
62 | 78 | | |
63 | 79 | | |
| |||
Lines changed: 71 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
27 | 98 | | |
28 | 99 | | |
29 | 100 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
398 | 398 | | |
399 | 399 | | |
400 | 400 | | |
401 | | - | |
402 | | - | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
403 | 410 | | |
404 | 411 | | |
405 | 412 | | |
| |||
0 commit comments