12 #include <boost/exception/errinfo_errno.hpp> 17 namespace duds {
namespace os {
namespace linux {
20 epfd = epoll_create(1);
23 boost::errinfo_errno(errno)
28 flist.reserve(reserveSize);
40 std::lock_guard<std::mutex> lock(
block);
45 std::lock_guard<std::mutex> lock(
block);
46 std::lock_guard<std::mutex> plock(p.block);
59 event.events = events;
60 std::lock_guard<std::mutex> lock(
block);
66 event.data.u32 =
flist.back();
68 if (epoll_ctl(
epfd, EPOLL_CTL_ADD, fd, &event)) {
85 std::lock_guard<std::mutex> lock(
block);
87 ResponderVec::iterator iter = std::find_if(
99 if (epoll_ctl(
epfd, EPOLL_CTL_DEL, fd,
nullptr) && ((err = errno) != ENOENT)) {
106 iter->responder.reset();
131 int count = epoll_wait(
epfd, events,
maxEvents, timeout.count());
135 }
else if (count < 0) {
136 if (errno == EINTR) {
140 boost::errinfo_errno(errno)
145 std::vector<ResponseRecord> resprec;
146 resprec.reserve(count);
148 std::lock_guard<std::mutex> lock(
block);
149 for (
int loop = 0; loop < count; ++loop) {
150 ResponderVec::iterator iter =
156 resprec.emplace_back(
std::move(prs), iter->fd);
172 rr.prs->respond(
this, rr.fd);
void remove(int fd)
Removes the entry for the given file descriptor.
ResponderVec responders
The responders and their file descriptors.
ResponseRecord(PollResponderSptr &&p, int f)
Poller(int reserveSize=0)
Constructs a new Poller and obtains a file descriptor for use with epoll.
Poller & operator=(Poller &&p) noexcept
Move assignment.
move_impl move(unsigned int c, unsigned int r)
Display stream manipulator that moves the display cursor to the given location.
A simple C++ interface to using Linux's epoll functions.
The call to epoll_create() failed.
int epfd
The file descriptor provided by epoll_create().
boost::error_info< struct Info_PollerFileDescriptor, int > PollerFileDescriptor
Poller error attribute that includes the value of the file descriptor.
Attempted to use a non-existent PollResponder object.
std::shared_ptr< PollResponder > PollResponderSptr
int wait()
Waits indefinitely for events, only returning after an event is received.
std::vector< int > flist
Free spot list.
An operation (remove) resulted in an error from an epoll function indicating that the file descriptor...
Holds a PollResponder object and its associated file descriptor.
void add(const PollResponderSptr &prs, int fd, int events=EPOLLIN)
Adds a PollResponder to check for events on a file descriptor.
~Poller()
Closes the internal file desciptor used with epoll.
std::mutex block
Used to allow for thread-safe operation.
static constexpr int maxEvents
The maximum number of events that will be read by a single call to wait(std::chrono::milliseconds).
#define DUDS_THROW_EXCEPTION(x)
Works like BOOST_THROW_EXCEPTION, but includes a stack trace if DUDS_ERRORS_VERBOSE is defined...
The base class for all Poller errors; used for general errors.