From c65f5dd18e5f937e25cc16da9dac61e403ef5982 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Sat, 23 Mar 2024 19:37:09 +0100 Subject: libutil: convert drainFD to a Bytes generator the `*Source` name is a slight misnomer since we do also have a Source type, but we can probably live with this for time being. Change-Id: I54eb2e59a4009014e324797f16b80b962759c7d3 --- src/libutil/file-descriptor.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/libutil/file-descriptor.cc') diff --git a/src/libutil/file-descriptor.cc b/src/libutil/file-descriptor.cc index a19ceaf2a..ab69b5754 100644 --- a/src/libutil/file-descriptor.cc +++ b/src/libutil/file-descriptor.cc @@ -81,12 +81,12 @@ std::string drainFD(int fd, bool block, const size_t reserveSize) // the parser needs two extra bytes to append terminating characters, other users will // not care very much about the extra memory. StringSink sink(reserveSize + 2); - drainFD(fd, sink, block); + sink << drainFDSource(fd, block); return std::move(sink.s); } -void drainFD(int fd, Sink & sink, bool block) +Generator drainFDSource(int fd, bool block) { // silence GCC maybe-uninitialized warning in finally int saved = 0; @@ -115,7 +115,7 @@ void drainFD(int fd, Sink & sink, bool block) throw SysError("reading from file"); } else if (rd == 0) break; - else sink({(char *) buf.data(), (size_t) rd}); + else co_yield std::span{(char *) buf.data(), (size_t) rd}; } } -- cgit v1.2.3