Exemplo n.º 1
0
void Server::HandleEvent(int fd, FileEventType event) {
  std::cout << "[" << fd << "," << (int)event << "]" << std::endl;

  if (fd == listen_fd_) {
    AcceptClient();
  } else {
    Client *client = clients_[fd];

    if (client == NULL) {
      return;
    }

    char buf[256] = "";
    int received = recv(fd, buf, sizeof(buf)-1, 0);

    if (received <= 0) {
      Disconnect(client);
    } else {
      if (client_manager_) {
        client->AddBuffer(buf, received);
        if (client_manager_->HandleBuffer(client) ==
            ClientManagerInterface::kInvalid) {
          Disconnect(client);
        }
      }
    } 
  }
}