2 #include <msp/core/systemerror.h>
4 #include "eventobject.h"
6 #include "handle_private.h"
8 #include "poll_platform.h"
15 using namespace Msp::IO;
17 inline short int sys_poll_event(PollEvent event)
21 if(event&~(P_INPUT|P_PRIO|P_OUTPUT))
22 throw invalid_argument("sys_poll_event");
34 inline PollEvent poll_event_from_sys(int event)
36 PollEvent result = P_NONE;
39 result = result|P_INPUT;
41 result = result|P_PRIO;
43 result = result|P_OUTPUT;
45 result = result|P_ERROR;
47 result = result|P_HANGUP;
58 void Poller::rebuild_array()
63 priv->pfd.reserve(objects.size());
65 for(const PolledObject &po: objects)
68 p.fd = *po.object->get_event_handle();
69 p.events = sys_poll_event(po.events);
70 priv->pfd.push_back(p);
75 for(unsigned i=0; i<objects.size(); ++i)
76 priv->pfd[i].events = sys_poll_event(objects[i].events);
80 void Poller::platform_poll(int timeout)
82 int ret = ::poll(&priv->pfd.front(), priv->pfd.size(), timeout);
88 throw system_error("poll");
91 for(unsigned i=0; (i<objects.size() && ret>0); ++i)
92 if(priv->pfd[i].revents)
94 poll_result.push_back(PolledObject(objects[i].object, poll_event_from_sys(priv->pfd[i].revents)));
100 PollEvent platform_poll(EventObject &obj, PollEvent pe, int timeout)
102 pollfd pfd = { *obj.get_event_handle(), sys_poll_event(pe), 0 };
104 int ret = ::poll(&pfd, 1, timeout);
110 throw system_error("poll");
113 return poll_event_from_sys(pfd.revents);