10 #include <sys/select.h> 12 #include <fmt/format.h> 14 template<
typename... Args>
15 std::runtime_error
error(
const char* fmt,
const Args& ... args)
17 return std::runtime_error(fmt::format(fmt, args...));
40 timeout.tv_sec = duration.
toNSec() / 1000LL / 1000LL / 1000LL;
41 timeout.tv_usec = (duration.
toNSec() / 1000LL) % (1000LL * 1000LL * 1000LL);
47 for(
auto pair :
m_fds)
49 FD_SET(pair.first, &fds);
50 maxfd = std::max(pair.first, maxfd);
53 int ret = select(maxfd+1, &fds,
nullptr,
nullptr, &timeout);
56 if(errno == EINTR || errno == EAGAIN)
59 throw error(
"Could not select(): {}", strerror(errno));
66 std::vector<std::pair<int, boost::function<void(int)>>> toBeNotified;
68 for(
auto pair : m_fds)
70 if(FD_ISSET(pair.first, &fds))
71 toBeNotified.emplace_back(pair);
75 for(
auto pair : toBeNotified)
76 pair.second(pair.first);
void wait(const ros::WallDuration &duration)
std::map< int, boost::function< void(int)> > m_fds
void registerFD(int fd, const boost::function< void(int)> &cb)
std::runtime_error error(const char *fmt, const Args &...args)