diff --git a/io.hpp b/io.hpp index f1e402d5..8582748b 100644 --- a/io.hpp +++ b/io.hpp @@ -43,9 +43,11 @@ namespace util { std::vector slurp (FILE *); - //------------------------------------------------------------------------- + /////////////////////////////////////////////////////////////////////////// void write (const posix::fd&, const void *restrict data, size_t bytes); + + //------------------------------------------------------------------------- inline void write (const posix::fd &dst, util::view data) { @@ -53,6 +55,7 @@ namespace util { } + //------------------------------------------------------------------------- template void write (const posix::fd &_fd, const T &data) { @@ -60,7 +63,27 @@ namespace util { } - //------------------------------------------------------------------------- + ///------------------------------------------------------------------------ + /// writes all data from the provided view into the file-like-object + /// + /// writing will continually iterate until the entire buffer has been + /// dispatched so as to avoid issues with partial writes. will block until + /// such time as the entire buffer has written. + /// + /// an exception may be thrown in the event forward progress is impossible. + /// in this event the progress may not be reported to the caller. in the + /// future an exception member variable may expose the information. + template + void + write (DstT &dst, util::view src) + { + for (auto cursor = src.begin (); cursor != src.end (); ) { + cursor = dst.write (view{cursor, src.end ()}); + } + } + + + /////////////////////////////////////////////////////////////////////////// class indenter : public std::streambuf { protected: std::streambuf* m_dest;