Esempio n. 1
0
Scheduler::ID Scheduler::RegisterTimeout(Handler&& handler, std::time_t millisecond, bool isCycle) {
  auto id = GenId();
  if (id == 0) {
    BB_ERROR_LOG("schedule id == 0 ???");
    return 0;
  }
  auto info = std::make_shared<ScheduleInfo>(io_);
  info->callback = std::move(handler);
  info->isCycle = isCycle;
  info->timeout = std::chrono::milliseconds(millisecond);
  info->wait.expires_after(info->timeout);

  info->waitHandler = [this, id](const boost::system::error_code& ec) {
    if (ec) {
      maps_.erase(id);
      BB_ERROR_LOG("schedule[%llu] error:%s", id, ec.message().c_str());
      return;
    }

    HandleTimeout(id, false);
  };

  maps_[id] = info;
  HandleTimeout(id, true);

  return id;
}
Esempio n. 2
0
void CNet::OnAccept(evutil_socket_t fd)
{
	unsigned int nId = GenId();
	CAcceptor* pAcceptor = CAcceptor::CreateAcceptor(nId, m_pReactor, fd);
	if (pAcceptor)
	{
		m_mId2BufferEvent[nId] = pAcceptor;
	}
}
Esempio n. 3
0
unsigned int CNet::Connect(int family, const char *hostname, int port)
{
	unsigned int nId = GenId();
	CConnector* pConnector = CConnector::CreateConnector(nId, m_pReactor);
	if (pConnector && pConnector->Connect(family, hostname, port))
	{
		m_mId2BufferEvent[nId] = pConnector;
		return nId;
	}

	return 0;
}