Ejemplo n.º 1
0
bool Notices::modify_notice_internal(NoticeId id, Notice const& notice)
{
  if (Notice* notice_ptr = find_notice(id)) {
    epoll_event ev;
    ev.events = translate_event_types(notice);
    if (::epoll_ctl(poller().raw_handle(), EPOLL_CTL_MOD, notice_ptr->raw_handle(), &ev) == 0) {
      notice_ptr->set_event_handler(notice.event_handler());
      notice_ptr->set_event_types(notice.event_types());
      return true;
    }
    on_error_ && on_error_(util::errc());
  }
  return false;
}
Ejemplo n.º 2
0
bool Notices::remove_notice_internal(NoticeId id)
{
  if (Notice* notice_ptr = find_notice(id)) {
    int raw_handle = notice_ptr->raw_handle();
    if (notices_.erase(id)) {
      int ret = ::epoll_ctl(poller().raw_handle(), EPOLL_CTL_DEL, raw_handle, nullptr);
      // If owner closes the file descriptor, epoll_ctl returns EBADF, which can be ignored
      if (ret == 0 || errno == EBADF)
        return true;
      on_error_ && on_error_(util::errc());
    }
  }
  return false;
}
Ejemplo n.º 3
0
bool Notices::add_notice_internal(Notice&& notice)
{
  assert(notice.any_event_type());
  auto res = notices_.insert(std::make_pair(notice.id(), std::move(notice)));
  if (res.second) {
    Notice *notice_ptr = &(res.first->second);
    epoll_event ev;
    ev.data.ptr = notice_ptr;
    ev.events = translate_event_types(*notice_ptr);
    if (::epoll_ctl(poller().raw_handle(), EPOLL_CTL_ADD, notice_ptr->raw_handle(), &ev) == 0)
      return true;
    notices_.erase(res.first);
    on_error_ && on_error_(util::errc());
  }
  return false;
}
Ejemplo n.º 4
0
    void on_error(error_code const& code)
    {
        if (code)
        {
            if  // usually, by on_receive
               ((code.category() == error::misc_category    && code.value   () == error::eof)               ||

                // and these - by on_send
                (code.category() == error::system_category  && code.value   () == error::connection_reset)  ||
                (code.category() == error::system_category  && code.value   () == error::broken_pipe     ))
            {
                on_discon_(code);
            }
            else
                on_error_(code);
        }
    }
Ejemplo n.º 5
0
 void on_error(std::string &&str) final {
   if (nullptr != on_error_) on_error_(user_data_, str.c_str());
 }
Ejemplo n.º 6
0
 void on_error(std::size_t num_thread, boost::exception_ptr const& e)
 {
     if (on_error_)
         on_error_(num_thread, e);
 }