Ejemplo n.º 1
0
void Acceptor::handleEvent(int events)
{
  std::cout << "acceptor::events" << std::endl;
  assert(events && EPOLLIN);  //we should make sure the events is epollin
  while(true)
  {
    Socket* newsock = m_socket->accept();
    std::cout << "newsock:" << newsock << std::endl;
    if( newsock == NULL ){
      if( errno == EINTR ) continue;
      else if( errno == EWOULDBLOCK 
            || errno == EAGAIN ){
        return;
      }else{
        // should not execute here.
        // TODO: log error
        assert(false);
        return;
      }
    }else{
      m_connlist.push_back(newsock);
      newsock->setNonBlock();
      EventLoop* loop = getNextLoop();      
      Client* client = new Client(newsock, loop);
      loop->registerHandle(client, EPOLLIN|EPOLLERR);
      return;
    }
  }
}