4#include "TimeOutException.h"
13 template <
typename T,
typename TRAITS>
14 inline WaitForIOReady<T, TRAITS>::WaitForIOReady (
const Traversal::Iterable<pair<T, TypeOfMonitorSet>>& fds,
15 optional<pair<SDKPollableType, TypeOfMonitorSet>> pollable2Wakeup)
17 : fPollData_{Containers::Collection<pair<T, TypeOfMonitorSet>>{fds}}
18 , fPollable2Wakeup_{pollable2Wakeup}
22 template <
typename T,
typename TRAITS>
23 WaitForIOReady<T, TRAITS>::WaitForIOReady (
const Traversal::Iterable<T>& fds,
const TypeOfMonitorSet& flags,
24 optional<pair<SDKPollableType, TypeOfMonitorSet>> pollable2Wakeup)
25 : WaitForIOReady{fds.template Map<Traversal::Iterable<pair<T, TypeOfMonitorSet>>> ([&] (const T& t) {
return make_pair (t, flags); }), pollable2Wakeup}
28 template <
typename T,
typename TRAITS>
29 WaitForIOReady<T, TRAITS>::WaitForIOReady (T fd,
const TypeOfMonitorSet& flags, optional<pair<SDKPollableType, TypeOfMonitorSet>> pollable2Wakeup)
30 : WaitForIOReady{Containers::Collection<pair<T, TypeOfMonitorSet>>{make_pair (fd, flags)}, pollable2Wakeup}
33 template <
typename T,
typename TRAITS>
34 inline auto WaitForIOReady<T, TRAITS>::GetDescriptors () const -> Traversal::Iterable<pair<T, TypeOfMonitorSet>>
36 Debug::AssertExternallySynchronizedMutex::ReadContext declareContext{fThisAssertExternallySynchronized_};
39 template <
typename T,
typename TRAITS>
40 inline auto WaitForIOReady<T, TRAITS>::Wait (Time::DurationSeconds waitFor) -> Containers::Set<T>
42 return WaitUntil (waitFor + Time::GetTickCount ());
44 template <
typename T,
typename TRAITS>
45 inline auto WaitForIOReady<T, TRAITS>::WaitQuietly (Time::DurationSeconds waitFor) -> Containers::Set<T>
47 return WaitQuietlyUntil (waitFor + Time::GetTickCount ());
49 template <
typename T,
typename TRAITS>
50 auto WaitForIOReady<T, TRAITS>::WaitUntil (Time::TimePointSeconds timeoutAt) -> Containers::Set<T>
52 Debug::AssertExternallySynchronizedMutex::WriteContext declareContext{fThisAssertExternallySynchronized_};
53 Containers::Set<T> result = WaitQuietlyUntil (timeoutAt);
54 if (result.empty ()) {
55 Execution::ThrowTimeoutExceptionAfter (timeoutAt);
59 template <
typename T,
typename TRAITS>
60 auto WaitForIOReady<T, TRAITS>::WaitQuietlyUntil (Time::TimePointSeconds timeoutAt) -> Containers::Set<T>
62 Debug::AssertExternallySynchronizedMutex::WriteContext declareContext{fThisAssertExternallySynchronized_};
65 auto fillBuffer = [
this] (vector<pair<SDKPollableType, TypeOfMonitorSet>>* pollBuffer, vector<T>* mappedObjectBuffer) ->
void {
68 Require (pollBuffer->size () == 0);
69 Require (mappedObjectBuffer->size () == 0);
70 pollBuffer->reserve (fPollData_.size ());
71 mappedObjectBuffer->reserve (fPollData_.size ());
72 for (
const auto& i : fPollData_) {
73 pollBuffer->push_back (pair<SDKPollableType, TypeOfMonitorSet>{TRAITS::GetSDKPollable (i.first), i.second});
74 mappedObjectBuffer->push_back (i.first);
76 if (fPollable2Wakeup_) {
77 pollBuffer->push_back (pair<SDKPollableType, TypeOfMonitorSet>{fPollable2Wakeup_.value ().first, fPollable2Wakeup_.value ().second});
81 Thread::CheckForInterruption ();
82 vector<pair<SDKPollableType, TypeOfMonitorSet>> pollBuffer;
83 vector<T> mappedObjectBuffer;
85 fillBuffer (&pollBuffer, &mappedObjectBuffer);
86 Assert (pollBuffer.size () == mappedObjectBuffer.size () or pollBuffer.size () == mappedObjectBuffer.size () + 1);
87 Containers::Set<T> result;
88 for (
size_t i : _WaitQuietlyUntil (Containers::
Start (pollBuffer), Containers::
End (pollBuffer), timeoutAt)) {
89 if (i == mappedObjectBuffer.size ()) {
90 Assert (fPollable2Wakeup_);
93 Assert (i < mappedObjectBuffer.size ());
94 result.Add (mappedObjectBuffer[i]);
104 constexpr EnumNames<Execution::WaitForIOReady_Support::WaitForIOReady_Base::TypeOfMonitor>
105 DefaultNames<Execution::WaitForIOReady_Support::WaitForIOReady_Base::TypeOfMonitor>::k{{{
106 {Execution::WaitForIOReady_Support::WaitForIOReady_Base::TypeOfMonitor::eRead, L
"Read"},
107 {Execution::WaitForIOReady_Support::WaitForIOReady_Base::TypeOfMonitor::eWrite, L
"Write"},
108 {Execution::WaitForIOReady_Support::WaitForIOReady_Base::TypeOfMonitor::eError, L
"Error"},
109 {Execution::WaitForIOReady_Support::WaitForIOReady_Base::TypeOfMonitor::eHUP, L
"HUP"},
#define RequireNotNull(p)
CONTAINER::value_type * End(CONTAINER &c)
For a contiguous container (such as a vector or basic_string) - find the pointer to the end of the co...
CONTAINER::value_type * Start(CONTAINER &c)
For a contiguous container (such as a vector or basic_string) - find the pointer to the start of the ...