Пример #1
0
void Channel::HandleEventWithGuard(Timestamp receive_time) {
  event_handling_ = true;
#if defined(__MACH__) || defined(__ANDROID_API__)
  LogTrace("%s", REventsToString().c_str());
#else
  VLOG(1) << REventsToString();
#endif

  if ((revents_ & POLLHUP) && !(revents_ & POLLIN)) {
    if (log_hup_) {
#if defined(__MACH__) || defined(__ANDROID_API__)
      LogWarn("Channel::handle_event() POLLHUP");
#else
      LOG(WARNING) << "Channel::handle_event() POLLHUP";
#endif
    }

    if (close_callback_) {
      close_callback_();
    }
  }

  if (revents_ & POLLNVAL) {
#if defined(__MACH__) || defined(__ANDROID_API__)
    LogWarn("Channel::handle_event() POLLNVAL");
#else
    LOG(WARNING) << "Channel::handle_event() POLLNVAL";
#endif
  }

  if (revents_ & (POLLERR | POLLNVAL)) {
    if (error_callback_) error_callback_();
  }

#ifndef POLLRDHUP
  const int POLLRDHUP = 0;
#endif

  if (revents_ & (POLLIN | POLLPRI | POLLRDHUP)) {
    if (read_callback_) read_callback_(receive_time);
  }

  if (revents_ & POLLOUT) {
    if (write_callback_) write_callback_();
  }

  event_handling_ = false;
}
Пример #2
0
void TcpConnection::handle_read(const boost::system::error_code &ec, std::size_t bytes_transfered) {
    if (!ec) {
        if(read_callback_) {
            read_callback_(shared_from_this(), bytes_transfered);
        }
        socket_.async_read_some(boost::asio::buffer(readbuf_), std::bind(
                                    &TcpConnection::handle_read, this, std::placeholders::_1,  std::placeholders::_2));
    } else {

        if (ec.value() == boost::asio::error::eof) {// EOF
            handle_close();
        } else {
             LOG_DEBUG<<ec.message();
        }
    }
}