diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2020-10-16 22:18:45 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2020-11-06 10:47:57 +0300 |
commit | ae43c5780651d594b1ec76e99330cd6ef082b0c5 (patch) | |
tree | 76a18276dbec9e63eb9dd8d09cbd5786a21610c6 /libbutl/fdstream.mxx | |
parent | 3ee9761b73aff34c7f30ee44b8aac276d413cc21 (diff) |
Add fdselect() overload that also takes timeout
Diffstat (limited to 'libbutl/fdstream.mxx')
-rw-r--r-- | libbutl/fdstream.mxx | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/libbutl/fdstream.mxx b/libbutl/fdstream.mxx index 86ada51..c863d2c 100644 --- a/libbutl/fdstream.mxx +++ b/libbutl/fdstream.mxx @@ -11,6 +11,7 @@ #include <ios> // streamsize #include <vector> #include <string> +#include <chrono> #include <istream> #include <ostream> #include <utility> // move(), pair @@ -911,10 +912,25 @@ LIBBUTL_MODEXPORT namespace butl // As above but wait up to the specified timeout returning a pair of zeroes // if none of the descriptors became ready. // - // @@ Maybe merge it with the above via a default/optional value? - // - // LIBBUTL_SYMEXPORT std::pair<std::size_t, std::size_t> - // fdselect (fdselect_set&, fdselect_set&, const duration& timeout); + template <typename R, typename P> + std::pair<std::size_t, std::size_t> + fdselect (fdselect_set&, fdselect_set&, const std::chrono::duration<R, P>&); + + template <typename R, typename P> + inline std::size_t + ifdselect (fdselect_set& ifds, const std::chrono::duration<R, P>& timeout) + { + fdselect_set ofds; + return fdselect (ifds, ofds, timeout).first; + } + + template <typename R, typename P> + inline std::size_t + ofdselect (fdselect_set& ofds, const std::chrono::duration<R, P>& timeout) + { + fdselect_set ifds; + return fdselect (ifds, ofds, timeout).second; + } // POSIX read() function wrapper. In particular, it supports the semantics // of non-blocking read for pipes on Windows. |