int DevPollFDMultiplexer::run(struct timeval* now, int timeout)
{
- if (d_inrun) {
- throw FDMultiplexerException("FDMultiplexer::run() is not reentrant!\n");
- }
+ InRun guard(d_inrun);
+
std::vector<struct pollfd> fds(d_readCallbacks.size() + d_writeCallbacks.size());
struct dvpoll dvp;
dvp.dp_nfds = d_readCallbacks.size() + d_writeCallbacks.size();
return 0;
}
- d_inrun = true;
int count = 0;
for (int n = 0; n < ret; ++n) {
if ((fds.at(n).revents & POLLIN) || (fds.at(n).revents & POLLERR) || (fds.at(n).revents & POLLHUP)) {
}
}
- d_inrun = false;
return count;
}
int EpollFDMultiplexer::run(struct timeval* now, int timeout)
{
- if (d_inrun) {
- throw FDMultiplexerException("FDMultiplexer::run() is not reentrant!\n");
- }
+ InRun guard(d_inrun);
int ret = epoll_wait(d_epollfd, d_eevents.data(), d_eevents.size(), timeout);
gettimeofday(now, nullptr); // MANDATORY
return 0;
}
- d_inrun = true;
int count = 0;
+
for (int n = 0; n < ret; ++n) {
if ((d_eevents[n].events & EPOLLIN) || (d_eevents[n].events & EPOLLERR) || (d_eevents[n].events & EPOLLHUP)) {
const auto& iter = d_readCallbacks.find(d_eevents[n].data.fd);
}
}
- d_inrun = false;
return count;
}
int KqueueFDMultiplexer::run(struct timeval* now, int timeout)
{
- if (d_inrun) {
- throw FDMultiplexerException("FDMultiplexer::run() is not reentrant!\n");
- }
+ InRun guard(d_inrun);
struct timespec ts;
ts.tv_sec = timeout / 1000;
return 0;
}
- d_inrun = true;
-
for (int n = 0; n < ret; ++n) {
if (d_kevents[n].filter == EVFILT_READ) {
const auto& iter = d_readCallbacks.find(d_kevents[n].ident);
}
}
- d_inrun = false;
return ret;
}
minimum value of maxEventsHint and s_maxevents, to reduce memory usage. */
static FDMultiplexer* getMultiplexerSilent(unsigned int maxEventsHint = s_maxevents);
+ struct InRun {
+ InRun(const InRun&) = delete;
+ InRun(InRun&&) = delete;
+ InRun& operator=(const InRun&) = delete;
+ InRun& operator=(InRun&&) = delete;
+ InRun(bool& ref) :
+ d_inrun(ref)
+ {
+ if (d_inrun) {
+ throw FDMultiplexerException("FDMultiplexer::run() is not reentrant!");
+ }
+ d_inrun = true;
+ }
+ ~InRun() {
+ d_inrun = false;
+ }
+ bool& d_inrun;
+ };
+
/* tv will be updated to 'now' before run returns */
/* timeout is in ms, 0 will return immediately, -1 will block until at
least one descriptor is ready */
int PollFDMultiplexer::run(struct timeval* now, int timeout)
{
- if (d_inrun) {
- throw FDMultiplexerException("FDMultiplexer::run() is not reentrant!\n");
- }
+ InRun guard(d_inrun);
auto pollfds = preparePollFD();
if (pollfds.empty()) {
throw FDMultiplexerException("poll returned error: " + stringerror());
}
- d_inrun = true;
int count = 0;
for (const auto& pollfd : pollfds) {
if (pollfd.revents & POLLIN || pollfd.revents & POLLERR || pollfd.revents & POLLHUP) {
}
}
- d_inrun = false;
return count;
}
int PortsFDMultiplexer::run(struct timeval* now, int timeout)
{
- if (d_inrun) {
- throw FDMultiplexerException("FDMultiplexer::run() is not reentrant!\n");
- }
+ InRun guard(d_inrun);
struct timespec timeoutspec;
timeoutspec.tv_sec = timeout / 1000;
return 0;
}
- d_inrun = true;
int count = 0;
for (unsigned int n = 0; n < numevents; ++n) {
if (d_pevents[n].portev_events & POLLIN || d_pevents[n].portev_events & POLLERR || d_pevents[n].portev_events & POLLHUP) {
}
}
- d_inrun = false;
return count;
}