Esempio n. 1
0
std::error_code
PollPoller::update_dispatcher(Dispatcher &dispatcher) {
  assert(dispatchers_.find(dispatcher.get_fd()) != dispatchers_.end());
  int sock = dispatcher.get_fd();

  struct pollfd &pd = fds_[dispatcher.get_index()];

  pd.events = 0;

  if (dispatcher.readable()) {
    pd.events |= POLLIN;
  }
  if (dispatcher.writable()) {
    pd.events |= POLLOUT;
  }

  return LS_OK_ERROR();
}
Esempio n. 2
0
std::error_code
PollPoller::remove_dispatcher(Dispatcher &dispatcher) {
  assert(dispatchers_.find(dispatcher.get_fd()) != dispatchers_.end());

  int sock = dispatcher.get_fd();

  int vec_idx = dispatcher.get_index();
  if (dispatchers_.size() > 1) {
    fds_[vec_idx] = fds_[fds_.size() - 1];
    auto tgt_disp = dispatchers_[fds_[vec_idx].fd];
    tgt_disp->set_index(vec_idx);
    fds_.pop_back();
  } else {
    fds_.clear();
  }

  dispatchers_.erase(dispatcher.get_fd());
  return LS_OK_ERROR();
}