/usr/include/Eris-1.3/Eris/PollGlib.h is in liberis-1.3-dev 1.3.14-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | #ifndef ERIS_POLL_GLIB_H
#define ERIS_POLL_GLIB_H
#include <map>
#include <Eris/DeleteLater.h>
#include <Eris/Exceptions.h>
#include <Eris/Poll.h>
#include <Eris/PollGlibFD.h>
#include <Eris/PollGlibSource.h>
#include <Eris/Types.h>
#include <Eris/Timeout.h>
namespace Eris
{
class PollGlib : public Eris::Poll, public Eris::PollData, public PollGlibSource
{
public:
PollGlib(GMainContext * pMainContext = 0) :
PollGlibSource(pMainContext),
_wait_time(-1)
{
g_timeout_add(250, (GSourceFunc)(bTimeoutCallback), this);
}
static gboolean bTimeoutCallback(PollGlib * pPoller)
{
pPoller->_wait_time = Eris::TimedEventService::instance()->tick();
execDeleteLaters();
return TRUE;
}
virtual ~PollGlib()
{
for(StreamMap::iterator I = _streams.begin(); I != _streams.end(); ++I)
delete I->second;
}
virtual void addStream(const basic_socket_stream* str, Check check)
{
if(!(check & MASK))
throw Eris::InvalidOperation("Null check in PollGlib");
gushort events = getEvents(check);
PollGlibFD* fd = new PollGlibFD(source(), str, events);
if(!_streams.insert(StreamMap::value_type(str, fd)).second) {
delete fd;
throw Eris::InvalidOperation("Duplicate streams in PollGlib");
}
}
virtual void changeStream(const basic_socket_stream* str, Check check)
{
if(!(check & MASK))
throw Eris::InvalidOperation("Null check in PollGlib");
StreamMap::iterator I = _streams.find(str);
if(I == _streams.end())
throw Eris::InvalidOperation("Can't find stream in PollGlib");
I->second->setEvents(getEvents(check));
}
virtual void removeStream(const basic_socket_stream* str)
{
StreamMap::iterator I = _streams.find(str);
if(I == _streams.end())
throw Eris::InvalidOperation("Can't find stream in PollGlib");
PollGlibFD *data = I->second;
_streams.erase(I);
delete data;
}
virtual bool isReady(const basic_socket_stream* str)
{
StreamMap::iterator I = _streams.find(str);
return I != _streams.end() && I->second->check();
}
protected:
virtual bool prepare(int& timeout)
{
timeout = _wait_time;
return timeout != -1;
}
virtual bool check()
{
for(StreamMap::iterator I = _streams.begin(); I != _streams.end(); ++I)
if(I->second->check())
return TRUE;
return FALSE;
}
virtual bool dispatch()
{
if(check())
Ready.emit(*this);
unsigned long wait = Eris::TimedEventService::instance()->tick();
if(new_timeout_) {
_wait_time = 0;
new_timeout_ = false;
}
else if(wait <= G_MAXINT)
_wait_time = wait;
else
_wait_time = -1;
return TRUE;
}
private:
static gushort getEvents(Eris::Poll::Check check)
{
assert(check & Eris::Poll::MASK);
gushort events = 0;
if(check & Eris::Poll::READ)
events |= G_IO_IN;
if(check & Eris::Poll::WRITE)
events |= G_IO_OUT;
assert(events);
return events;
}
typedef std::map<const basic_socket_stream*,PollGlibFD*> StreamMap;
StreamMap _streams;
gint _wait_time;
};
} // namespace Eris
#endif // ERIS_POLL_GLIB_H
|