X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fio%2Fwindows%2Fpoll.cpp;fp=source%2Fio%2Fwindows%2Fpoll.cpp;h=e67225805f3964a970f6e6d8fb93f82cb616d376;hp=0000000000000000000000000000000000000000;hb=609c9a508cfdc7b42c46c4f21d17639204165a00;hpb=b4806214e905752617691f851717033fd3f266c2 diff --git a/source/io/windows/poll.cpp b/source/io/windows/poll.cpp new file mode 100644 index 0000000..e672258 --- /dev/null +++ b/source/io/windows/poll.cpp @@ -0,0 +1,53 @@ +#include +#include "eventobject.h" +#include "handle.h" +#include "handle_private.h" +#include "poll.h" +#include "poll_platform.h" + +namespace Msp { +namespace IO { + +void Poller::rebuild_array() +{ + priv->handles.clear(); + + for(EventMap::iterator i=objects.begin(); i!=objects.end(); ++i) + priv->handles.push_back(*i->first->get_event_handle()); + + objs_changed = false; +} + +void Poller::platform_poll(int timeout) +{ + if(timeout<0) + timeout = INFINITE; + + DWORD ret = WaitForMultipleObjects(priv->handles.size(), &priv->handles.front(), false, timeout); + if(/*ret>=WAIT_OBJECT_0 &&*/ rethandles.size()) + { + EventMap::iterator i = objects.begin(); + advance(i, ret-WAIT_OBJECT_0); + poll_result.push_back(Slot(i->first, i->second)); + } + else if(ret==WAIT_FAILED) + throw system_error("WaitForMultipleObjects"); +} + + +PollEvent platform_poll(EventObject &obj, PollEvent pe, int timeout) +{ + if(timeout<0) + timeout = INFINITE; + + DWORD ret = WaitForSingleObject(*obj.get_event_handle(), timeout); + if(ret==WAIT_OBJECT_0) + return pe; + else if(ret==WAIT_FAILED) + throw system_error("WaitForSingleObject"); + + return P_NONE; +} + +} // namespace IO +} // namespace Msp