]> git.tdb.fi Git - libs/core.git/commitdiff
Additional adjustments for Poller
authorMikko Rasa <tdb@tdb.fi>
Fri, 27 Sep 2019 19:35:14 +0000 (22:35 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 27 Sep 2019 23:33:45 +0000 (02:33 +0300)
source/io/eventdispatcher.cpp
source/io/poll.cpp
source/io/poll.h
source/io/unix/poll.cpp
source/io/windows/poll.cpp

index 550043f4cffdd99f47144a0af5a7e32686cabad1..f98474c227d4cc7e1fd8d1a2e03274a6f21c89d5 100644 (file)
@@ -63,8 +63,8 @@ void EventDispatcher::tick(const Time::Timer &timer)
 
 void EventDispatcher::dispatch()
 {
-       const vector<Poller::Slot> &result = poller.get_result();
-       for(vector<Poller::Slot>::const_iterator i=result.begin(); i!=result.end(); ++i)
+       const vector<Poller::PolledObject> &result = poller.get_result();
+       for(vector<Poller::PolledObject>::const_iterator i=result.begin(); i!=result.end(); ++i)
                i->object->event(i->events);
 }
 
index 2e33502e8433969059dccdd1ecbde834a3e6aff7..a5d2d023c81d3f1ae730fc69d8d903b5546926db 100644 (file)
@@ -25,7 +25,7 @@ void Poller::set_object(EventObject &obj, PollEvent ev)
        if(ev)
                obj.get_event_handle();
 
-       for(vector<Slot>::iterator i=objects.begin(); i!=objects.end(); ++i)
+       for(vector<PolledObject>::iterator i=objects.begin(); i!=objects.end(); ++i)
                if(i->object==&obj)
                {
                        if(ev)
@@ -48,16 +48,16 @@ void Poller::set_object(EventObject &obj, PollEvent ev)
                throw logic_error("Maximum number of wait objects reached");
 #endif
 
-       objects.push_back(Slot(&obj, ev));
+       objects.push_back(PolledObject(&obj, ev));
        objs_changed = true;
 }
 
-int Poller::poll()
+unsigned Poller::poll()
 {
        return do_poll(-1);
 }
 
-int Poller::poll(const Time::TimeDelta &timeout)
+unsigned Poller::poll(const Time::TimeDelta &timeout)
 {
        if(timeout<Time::zero)
                throw invalid_argument("Poller::poll");
@@ -65,7 +65,7 @@ int Poller::poll(const Time::TimeDelta &timeout)
        return do_poll(static_cast<int>(timeout/Time::msec));
 }
 
-int Poller::do_poll(int timeout)
+unsigned Poller::do_poll(int timeout)
 {
        if(objs_changed || events_changed)
        {
@@ -82,7 +82,6 @@ int Poller::do_poll(int timeout)
 }
 
 
-
 PollEvent platform_poll(EventObject &, PollEvent, int);
 
 PollEvent poll(EventObject &obj, PollEvent pe)
index fdb68c515bbe35e0e05cafdde93e59c625a7bced..40c15a70cb84389caa0d9df7a0273383dbc87ac2 100644 (file)
@@ -35,37 +35,39 @@ inline PollEvent operator~(PollEvent e)
 class Poller: private NonCopyable
 {
 public:
-       struct Slot
+       struct PolledObject
        {
                EventObject *object;
                PollEvent events;
 
-               Slot(EventObject *o, PollEvent e): object(o), events(e) { }
+               PolledObject(EventObject *o, PollEvent e): object(o), events(e) { }
        };
 
-       typedef std::vector<Slot> SlotList DEPRECATED;
+       typedef PolledObject Slot DEPRECATED;
+
+       typedef std::vector<PolledObject> SlotList DEPRECATED;
 private:
        struct Private;
 
-       std::vector<Slot> objects;
+       std::vector<PolledObject> objects;
        Private *priv;
        bool events_changed;
        bool objs_changed;
-       std::vector<Slot> poll_result;
+       std::vector<PolledObject> poll_result;
 
 public:
        Poller();
        ~Poller();
 
        void set_object(EventObject &, PollEvent);
-       int poll();
-       int poll(const Time::TimeDelta &);
+       unsigned poll();
+       unsigned poll(const Time::TimeDelta &);
 private:
        void rebuild_array();
-       int do_poll(int);
+       unsigned do_poll(int);
        void platform_poll(int);
 public:
-       const std::vector<Slot> &get_result() const { return poll_result; }
+       const std::vector<PolledObject> &get_result() const { return poll_result; }
 };
 
 PollEvent poll(EventObject &, PollEvent);
index 0fb9d22e03919476e95d52e09ca5faf10088241f..7df113e539609238e56d64bfd90662c0449c9af4 100644 (file)
@@ -62,7 +62,7 @@ void Poller::rebuild_array()
                priv->pfd.clear();
                priv->pfd.reserve(objects.size());
 
-               for(vector<Slot>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
+               for(vector<PolledObject>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
                {
                        pollfd p;
                        p.fd = *i->object->get_event_handle();
@@ -91,7 +91,7 @@ void Poller::platform_poll(int timeout)
        for(unsigned i=0; (i<objects.size() && ret>0); ++i)
                if(priv->pfd[i].revents)
                {
-                       poll_result.push_back(Slot(objects[i].object, poll_event_from_sys(priv->pfd[i].revents)));
+                       poll_result.push_back(PolledObject(objects[i].object, poll_event_from_sys(priv->pfd[i].revents)));
                        --ret;
                }
 }
index b3ee8ec9dda104712075891d33127b052b892885..7aafc6e1c2fcf74d6da3a1ca34777652da795489 100644 (file)
@@ -18,7 +18,7 @@ void Poller::rebuild_array()
        priv->handles.clear();
        priv->handles.reserve(objects.size());
 
-       for(vector<Slot>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
+       for(vector<PolledObject>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
                priv->handles.push_back(*i->object->get_event_handle());
 }
 
@@ -30,8 +30,8 @@ void Poller::platform_poll(int timeout)
        DWORD ret = WaitForMultipleObjects(priv->handles.size(), &priv->handles.front(), false, timeout);
        if(/*ret>=WAIT_OBJECT_0 &&*/ ret<WAIT_OBJECT_0+priv->handles.size())
        {
-               const Slot &slot = objects[ret-WAIT_OBJECT_0];
-               poll_result.push_back(slot);
+               const PolledObject &obj = objects[ret-WAIT_OBJECT_0];
+               poll_result.push_back(obj);
        }
        else if(ret==WAIT_FAILED)
                throw system_error("WaitForMultipleObjects");