コード例 #1
0
ファイル: poll_poller.cpp プロジェクト: usbuild/light
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();
}
コード例 #2
0
ファイル: poll_poller.cpp プロジェクト: usbuild/light
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();
}