eventxx  1.0.1
prio-test.cpp

This is a priority usage example.

#include <eventxx>
#include <iostream>
#include <map>
#include <csignal>
#include <cstdlib>
#define OSASSERT(func, ...) \
if (func(__VA_ARGS__) == -1) { perror(#func "()"); std::exit(1); }
struct handler
{
dispatcher& d;
int fds[4];
std::map< int, eventxx::basic_event* > events;
handler(dispatcher& d): d(d)
{
OSASSERT(pipe, fds);
OSASSERT(pipe, fds+2);
}
void add(eventxx::basic_event& e)
{
events[e.fd()] = &e;
}
void operator() (int fd, eventxx::type event)
{
char buf[7];
OSASSERT(read, fd, buf, 7);
std::cout << "Read from fd " << fd << ": " << buf << "\n";
d.del(*events[fd]);
}
};
int main()
{
dispatcher d(2);
handler h(d);
OSASSERT(write, h.fds[1], "hola 1", 7);
OSASSERT(write, h.fds[3], "hola 2", 7);
h.add(e1);
h.add(e2);
d.add(e1, 1);
d.add(e2, 0);
d.dispatch();
return 0;
}
type
Type of events.
Definition: eventxx:192
@ READ
Read event.
Definition: eventxx:194
Basic event from which all events derive.
Definition: eventxx:218
int fd() const
Event's file descriptor.
Definition: eventxx:271
Event dispatcher.
Definition: eventxx:549
Generic event object.
Definition: eventxx:301