aboutsummaryrefslogtreecommitdiff
path: root/libbutl/fdstream.ixx
diff options
context:
space:
mode:
Diffstat (limited to 'libbutl/fdstream.ixx')
-rw-r--r--libbutl/fdstream.ixx31
1 files changed, 27 insertions, 4 deletions
diff --git a/libbutl/fdstream.ixx b/libbutl/fdstream.ixx
index fb57b99..e024af9 100644
--- a/libbutl/fdstream.ixx
+++ b/libbutl/fdstream.ixx
@@ -1,6 +1,8 @@
// file : libbutl/fdstream.ixx -*- C++ -*-
// license : MIT; see accompanying LICENSE file
+#include <cassert>
+
namespace butl
{
// auto_fd
@@ -27,16 +29,16 @@ namespace butl
reset ();
}
- // fdbuf
+ // fdstreambuf
//
- inline fdbuf::
- fdbuf (auto_fd&& fd, std::uint64_t pos)
+ inline fdstreambuf::
+ fdstreambuf (auto_fd&& fd, std::uint64_t pos)
{
if (fd.get () >= 0)
open (std::move (fd), pos);
}
- inline auto_fd fdbuf::
+ inline auto_fd fdstreambuf::
release ()
{
return std::move (fd_);
@@ -165,6 +167,8 @@ namespace butl
inline std::vector<char> ifdstream::
read_binary ()
{
+ // @@ TODO: surely there is a more efficient way! See sha256!
+
std::vector<char> v (std::istreambuf_iterator<char> (*this),
std::istreambuf_iterator<char> ());
return v;
@@ -353,4 +357,23 @@ namespace butl
{
return fdmode (stderr_fd (), m);
}
+
+ // fdselect
+ //
+ // Implement fdselect() function templates in terms of their milliseconds
+ // specialization.
+ //
+ template <>
+ LIBBUTL_SYMEXPORT std::pair<std::size_t, std::size_t>
+ fdselect (fdselect_set&, fdselect_set&, const std::chrono::milliseconds&);
+
+ template <typename R, typename P>
+ inline std::pair<std::size_t, std::size_t>
+ fdselect (fdselect_set& ifds,
+ fdselect_set& ofds,
+ const std::chrono::duration<R, P>& timeout)
+ {
+ using namespace std::chrono;
+ return fdselect (ifds, ofds, duration_cast<milliseconds> (timeout));
+ }
}