CommandProcessor: add fd argument to ProcessInput()
Various commands (such as commands which request a log
dump, or which write a blob to the log) will need to
provide a file descriptor argument. Accordingly, we
revise ProcessInput(), to support such an argument.
Add tests that verify that a provided FD argument
is closed when ProcessInput() returns. As noted in
the test implementation, these tests aren't truly
unit tests. But they're the best we can reasonably
do, given how unique_fd works.
Along the way: rename ProcessInput() to
ProcessCommand(). The new name is more consistent
with various bits of documentation (comments and
type names).
Bug: 32093334
Test: ./runtests.sh
Change-Id: Ib5845dc4ec13d10564894c4dbe7b486e3351ed22
diff --git a/command_processor.h b/command_processor.h
index 9e4e7e5..0c2ae66 100644
--- a/command_processor.h
+++ b/command_processor.h
@@ -38,9 +38,18 @@
// This method allows tests to provide a MockOs.
CommandProcessor(size_t buffer_size_bytes, std::unique_ptr<Os> os);
- // Processes the given command. The effect of this call depends on the
- // contents of |input_buf|.
- bool ProcessInput(NONNULL const void* input_buf, size_t n_bytes_read);
+ // Processes the given command, with the given file descriptor. The effect of
+ // this call depends on the contents of |input_buf|. In particular, depending
+ // on the command, |fd| may be used for reading or writing, or |fd| may be
+ // ignored. However, |fd| is guaranteed to be closed before ProcessCommand()
+ // returns, in all cases.
+ //
+ // (Ideally, we might want to take |fd| as a unique_fd. Unfortunately,
+ // GoogleMock doesn't deal well with move-only parameters. And we'll
+ // want to mock this method, eventually.
+ // https://github.com/google/googletest/issues/395)
+ bool ProcessCommand(NONNULL const void* input_buf, size_t n_bytes_read,
+ int fd);
private:
struct TimestampHeader {