From ae43c5780651d594b1ec76e99330cd6ef082b0c5 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 16 Oct 2020 22:18:45 +0300 Subject: Add fdselect() overload that also takes timeout --- libbutl/fdstream.mxx | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'libbutl/fdstream.mxx') 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 // streamsize #include #include +#include #include #include #include // 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 - // fdselect (fdselect_set&, fdselect_set&, const duration& timeout); + template + std::pair + fdselect (fdselect_set&, fdselect_set&, const std::chrono::duration&); + + template + inline std::size_t + ifdselect (fdselect_set& ifds, const std::chrono::duration& timeout) + { + fdselect_set ofds; + return fdselect (ifds, ofds, timeout).first; + } + + template + inline std::size_t + ofdselect (fdselect_set& ofds, const std::chrono::duration& 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. -- cgit v1.1