本文整理汇总了C++中Dispatcher::get_fd方法的典型用法代码示例。如果您正苦于以下问题:C++ Dispatcher::get_fd方法的具体用法?C++ Dispatcher::get_fd怎么用?C++ Dispatcher::get_fd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dispatcher
的用法示例。
在下文中一共展示了Dispatcher::get_fd方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LS_OK_ERROR
// millisecs
std::error_code
PollPoller::poll(int timeout,
std::unordered_map<int, Dispatcher *> &active_dispatchers) {
if (fds_.size() == 0) {
::Sleep(timeout);
return LS_OK_ERROR();
}
int num_events = ::WSAPoll(&*fds_.begin(), fds_.size(), timeout);
if (num_events < 0) {
if (SOCK_ERRNO() == CERR(EINTR)) {
return LS_OK_ERROR();
}
} else if (num_events == 0) {
return LS_OK_ERROR();
} else {
for (auto it = fds_.begin(); it != fds_.end() && num_events > 0; ++it) {
if (it->revents > 0) {
--num_events;
Dispatcher *dispatcher = dispatchers_[it->fd];
dispatcher->set_poll_event_data(
it->revents & (POLLIN | POLLPRI), it->revents & POLLOUT,
it->revents & POLLERR,
(it->revents & POLLHUP) && !(it->revents & POLLIN));
active_dispatchers[dispatcher->get_fd()] = dispatcher;
}
}
}
return LS_OK_ERROR();
}
示例2: add_dispatcher
std::error_code PollPoller::add_dispatcher(Dispatcher &dispatcher) {
assert(dispatchers_.find(dispatcher.get_fd()) == dispatchers_.end());
int sock = dispatcher.get_fd();
struct pollfd pd;
pd.fd = sock;
pd.events = 0;
if (dispatcher.readable()) {
pd.events |= POLLIN;
}
if (dispatcher.writable()) {
pd.events |= POLLOUT;
}
dispatcher.set_index(fds_.size());
fds_.push_back(pd);
dispatchers_[dispatcher.get_fd()] = &dispatcher;
return LS_OK_ERROR();
}
示例3: has_dispathcer
bool Poller::has_dispathcer(const Dispatcher &dispatcher) const {
auto res = dispatchers_.find(dispatcher.get_fd());
return res != dispatchers_.end() && &dispatcher == res->second;
}