aboutsummaryrefslogtreecommitdiff
path: root/pw_log_rpc/rpc_log_drain.cc
diff options
context:
space:
mode:
authorXin Li <delphij@google.com>2024-01-17 22:13:58 -0800
committerXin Li <delphij@google.com>2024-01-17 22:13:58 -0800
commit28d03a2a1cabbe01d7bcb6cf5166c10e50d3c2c6 (patch)
treec1643be8ab17fc607cea748a8bb1d621a5964873 /pw_log_rpc/rpc_log_drain.cc
parentec2628a6ba2d0ecbe3ac10c8c772f6fc6acc345d (diff)
parentf054515492af5132f685cb23fe11891ee77104c9 (diff)
downloadpigweed-28d03a2a1cabbe01d7bcb6cf5166c10e50d3c2c6.tar.gz
Merge Android 24Q1 Release (ab/11220357)temp_319669529
Bug: 319669529 Merged-In: Iba357b308a79d0c8b560acd4f72b5423c9c83294 Change-Id: Icdf552029fb97a34e83c6dd7799433fc473a2506
Diffstat (limited to 'pw_log_rpc/rpc_log_drain.cc')
-rw-r--r--pw_log_rpc/rpc_log_drain.cc11
1 files changed, 10 insertions, 1 deletions
diff --git a/pw_log_rpc/rpc_log_drain.cc b/pw_log_rpc/rpc_log_drain.cc
index 68294f9a5..143dbf5ed 100644
--- a/pw_log_rpc/rpc_log_drain.cc
+++ b/pw_log_rpc/rpc_log_drain.cc
@@ -69,6 +69,15 @@ Status RpcLogDrain::Open(rpc::RawServerWriter& writer) {
return Status::AlreadyExists();
}
server_writer_ = std::move(writer);
+
+ // Set a callback to close the drain when RequestCompletion() is requested by
+ // the reader. This callback is only set and invoked if
+ // PW_RPC_REQUEST_COMPLETION_CALLBACK is enabled.
+ // TODO: b/274936558 - : Add unit tests to check that when this callback is
+ // invoked, the stream is closed gracefully without dropping logs.
+ server_writer_.set_on_completion_requested_if_enabled(
+ [this]() { Close().IgnoreError(); });
+
if (on_open_callback_ != nullptr) {
on_open_callback_();
}
@@ -125,7 +134,7 @@ RpcLogDrain::LogDrainState RpcLogDrain::SendLogs(size_t max_num_bundles,
}
encoder.WriteFirstEntrySequenceId(sequence_id_)
- .IgnoreError(); // TODO(b/242598609): Handle Status properly
+ .IgnoreError(); // TODO: b/242598609 - Handle Status properly
sequence_id_ += packed_entry_count;
const Status status = server_writer_.Write(encoder);
sent_bundle_count++;