+#include <msp/core/systemerror.h>
+#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 &&*/ ret<WAIT_OBJECT_0+priv->handles.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