#ifndef MSP_IO_POLL_H_
#define MSP_IO_POLL_H_
-#include <list>
#include <map>
#include <vector>
+#include <msp/core/attributes.h>
+#include <msp/core/noncopyable.h>
#include <msp/time/timedelta.h>
namespace Msp {
P_INPUT = 1,
P_PRIO = 2,
P_OUTPUT = 4,
- P_ERROR = 8
+ P_ERROR = 8,
+ P_HANGUP = 16
};
inline PollEvent operator|(PollEvent e, PollEvent f)
{ return PollEvent(~static_cast<int>(e)); }
-class Poller
+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::list<Slot> SlotList;
-private:
- typedef std::map<EventObject *, PollEvent> EventMap;
+ typedef PolledObject Slot DEPRECATED;
+ typedef std::vector<PolledObject> SlotList DEPRECATED;
+private:
struct Private;
- EventMap objects;
+ std::vector<PolledObject> objects;
Private *priv;
+ bool events_changed;
bool objs_changed;
- SlotList 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 SlotList &get_result() const { return poll_result; }
+ const std::vector<PolledObject> &get_result() const { return poll_result; }
};
PollEvent poll(EventObject &, PollEvent);