From 7d7f8a4b8966985da25a5ce72fdddb9e394dca5f Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 27 Oct 2022 09:51:03 +0200 Subject: Add buffer_size constant, blocking() accessor to fdstreambuf --- libbutl/fdstream.hxx | 13 ++++++++++++- libbutl/fdstream.ixx | 2 ++ 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'libbutl') diff --git a/libbutl/fdstream.hxx b/libbutl/fdstream.hxx index 4dc89a3..730d4dd 100644 --- a/libbutl/fdstream.hxx +++ b/libbutl/fdstream.hxx @@ -137,6 +137,11 @@ namespace butl class LIBBUTL_SYMEXPORT fdstreambuf: public bufstreambuf { public: + // Reasonable (for stack allocation) buffer size that provides decent + // performance. + // + static const std::size_t buffer_size = 8192; + fdstreambuf () = default; // Unless specified, the current read/write position is assumed to @@ -174,6 +179,9 @@ namespace butl bool blocking (bool); + bool + blocking () const {return !non_blocking_;} + public: using base = bufstreambuf; @@ -238,7 +246,7 @@ namespace butl private: auto_fd fd_; - char buf_[8192]; + char buf_[buffer_size]; bool non_blocking_ = false; }; @@ -311,6 +319,9 @@ namespace butl int fd () const {return buf_.fd ();} + bool + blocking () const {return buf_.blocking ();} + protected: fdstreambuf buf_; }; diff --git a/libbutl/fdstream.ixx b/libbutl/fdstream.ixx index 08e317c..e024af9 100644 --- a/libbutl/fdstream.ixx +++ b/libbutl/fdstream.ixx @@ -167,6 +167,8 @@ namespace butl inline std::vector ifdstream:: read_binary () { + // @@ TODO: surely there is a more efficient way! See sha256! + std::vector v (std::istreambuf_iterator (*this), std::istreambuf_iterator ()); return v; -- cgit v1.1