From 39f96c4d9f5799aad1c064ef80c6fb1aed45f4e3 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Fri, 27 Nov 2020 14:49:57 -0500 Subject: fix(txix): Override overflow in BuildLogStreambuf Subclasses of std::streambuf are expected to override overflow in addition to xsputn, as it's called in certain cases by the non-virtual methods. In our case, this was preventing endlines from getting sent over the log stream. Change-Id: I70d00f0c7cb8f8cf2f744f58974c21e7a70a715b Reviewed-on: https://cl.tvl.fyi/c/depot/+/2172 Tested-by: BuildkiteCI Reviewed-by: kanepyork --- third_party/nix/src/nix-daemon/nix-daemon-proto.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'third_party/nix/src') diff --git a/third_party/nix/src/nix-daemon/nix-daemon-proto.cc b/third_party/nix/src/nix-daemon/nix-daemon-proto.cc index b6a5fe358a96..eab10e9572aa 100644 --- a/third_party/nix/src/nix-daemon/nix-daemon-proto.cc +++ b/third_party/nix/src/nix-daemon/nix-daemon-proto.cc @@ -99,6 +99,7 @@ class BuildLogStreambuf final : public std::streambuf { using Writer = grpc::ServerWriter; explicit BuildLogStreambuf(Writer* writer) : writer_(writer) {} + // TODO(grfn): buffer with a timeout so we don't have too many messages std::streamsize xsputn(const char_type* s, std::streamsize n) override { nix::proto::BuildEvent event; event.mutable_build_log()->set_line(s, n); @@ -106,6 +107,15 @@ class BuildLogStreambuf final : public std::streambuf { return n; } + int_type overflow(int_type ch) override { + if (ch != traits_type::eof()) { + nix::proto::BuildEvent event; + event.mutable_build_log()->set_line(std::string(1, ch)); + writer_->Write(event); + } + return ch; + } + private: Writer* writer_{}; }; -- cgit 1.4.1