Exemplo n.º 1
0
void Robot::onConnected(Link *link, const NetAddress& localAddr, const NetAddress& peerAddr)
{
	static int g_connectedRobotCnt = 0;
	++g_connectedRobotCnt;

	m_link = link;

	if (g_connectedRobotCnt % 100 == 0) {
		LOG_INFO << name() << " <" << localAddr.toIpPort() << "> connect to <" << peerAddr.toIpPort() << "> success, current robot cnt = " << m_robotMgr->m_robotMap.size();
	}

	// m_link->send("1\r\n");
}
Exemplo n.º 2
0
	bool bindAddress(socket_t sockfd, const NetAddress& localaddr)
	{
		int ret = bind(sockfd, (struct sockaddr *)&localaddr.m_addr, sizeof(localaddr.m_addr));
		if(ret == SOCKET_ERROR) {
			LOG_SYSTEM_ERR << "bindAddress failed address=<" << localaddr.toIpPort() << ">";
			return false;
		}

		return true;
	}
Exemplo n.º 3
0
void Robot::onDisconnect(Link *link, const NetAddress& localAddr, const NetAddress& peerAddr)
{
	/*
	if (link->m_isCreateByConnector) {
		Robot *robot = m_robotMgr->createRobot();
		m_robotMgr->m_wan.connect(peerAddr.toIp(), peerAddr.toPort(), *robot);
	}
	*/

	if (m_robotMgr->m_robotMap.size() - 1 % 100 >= 0) {
		LOG_INFO << "robot<" << m_robotId << "> <" << localAddr.toIpPort() << "> to gateserver <" << peerAddr.toIpPort() << "> closed! current robot cnt = " << m_robotMgr->m_robotMap.size() - 1;
	}

	m_robotMgr->onRobotDisconnect(this);
}