Пример #1
0
	CErrno NetThread::StartupClient(const Json::Value & clients)
	{
		INT32 nCount = clients.size(); 
		for (INT32 i = 0 ;i < nCount; ++ i)
		{     
			Json::Value client = clients[i];

			INT32 bReconnect = client.get("reconnect", 1).asInt();
			std::string strType = client.get("type" , "tcp").asCString();
			std::string strAddress = client.get("address", "127.0.0.1").asCString();
			INT32 nPort = client.get("port", 0000).asInt();
			INT32 nSendBuf = client.get("send_buf", DEFAULT_SOCKET_BUFFER_SIZE).asInt();
			INT32 nRecvBuf = client.get("recv_buf", DEFAULT_SOCKET_BUFFER_SIZE).asInt();
			
			INetHandlerPtr pNetHandler = CreateClientHandler(m_strNetNodeName, "" , strAddress.c_str(), nPort);
			if (!pNetHandler)
			{
				return CErrno::Failure();
			}
			ClientSession * pSession = dynamic_cast<ClientSession*>(pNetHandler->GetSession());
			if (pSession)
			{
				pSession->SetReconnect(bReconnect);
				NetSocket objSocket = pSession->GetSocket();
				if (objSocket != -1)
				{
					NetHelper::SetDefaultSocket(objSocket, nSendBuf, nRecvBuf);
					pSession->SetSendBufSize(nSendBuf);
					pSession->SetSendBufSize(nRecvBuf);
				}
			}
		}
		return CErrno::Success();
	} 
Пример #2
0
	CErrno NetThread::FetchClientsQueue()
	{
		SCreateInfo objInfo;
		while (m_queCreateClients.try_pop(objInfo))
		{
			INetHandlerPtr pNetHandler = CreateClientHandler(objInfo.strNodeName, objInfo.strUUID, objInfo.strAddress.c_str(), objInfo.usPort);
			if (!pNetHandler)
			{
				continue;
			}

			ClientSession * pSession = dynamic_cast<ClientSession*>(pNetHandler->GetSession());			
			if (pSession)
			{
				pSession->SetReconnect(objInfo.bReconnect);
			}
		}

		return CErrno::Success();
	}