Ejemplo n.º 1
0
	vector<CHttpClientResponse*> GZipUnZipTcpStream(unsigned char* pszData, unsigned int nLen)
	{
		vector<CHttpClientResponse*> ret;
		int nPackSize = 0;		
		int nDelta = 0;//目前读取的长度
		while (nDelta + 4 < nLen)
		{
			//读取头长度
			unsigned char chPackSizes[4] = {0};
			memcpy(chPackSizes, pszData, 4);
			pszData += 4;
			nDelta += 4;
			//获取头长度
			nPackSize = *((int*)&chPackSizes[0]);
			if (nLen - nDelta < nPackSize)
			{
				break;;
			}
			unsigned char* pszBuffer = new unsigned char[nPackSize];
			memset(pszBuffer, 0, nPackSize);
			memcpy(pszBuffer, pszData, nPackSize);
			pszData += nPackSize;
			nDelta += nPackSize;
			int nLen = 0;
			unsigned char* pszOut = NULL;
			if (pszBuffer[0] == 0x1f && pszBuffer[1] == 0x8b && pszBuffer[2] == 0x08 && pszBuffer[3] == 0x00)
			{				
				unsigned char* pszOut;
				int nLen = ZipUtils::ccInflateMemory((unsigned char*)pszBuffer, nPackSize, (unsigned char**)&pszOut);
				if (nLen > 0)
				{
					CHttpClientResponse* pResp = new CHttpClientResponse();
					CMemoryStream* pMem = new CMemoryStream();
					pResp->SetTarget(pMem);
					pMem->WriteBuffer((char*)pszOut, nLen);
					ret.push_back(pResp);
					delete []pszOut;
				}					
			}
			else
			{
				CHttpClientResponse* pResp = new CHttpClientResponse();
				CMemoryStream* pMem = new CMemoryStream();
				pResp->SetTarget(pMem);
				pMem->WriteBuffer((char*)pszBuffer, nPackSize);
				ret.push_back(pResp);
			}	
			delete []pszBuffer;
		}
		return ret;
	}
Ejemplo n.º 2
0
bool ScutDataLogic::CDataRequest::ExecTcpRequest(CDataHandler* pHandler, const char* lpszUrl, const char* lpSendData, unsigned int nDataLen)
{
	if (pHandler)
	{
		if (m_pTcpClient == NULL)
		{
			m_pTcpClient = new CTcpClient();
		}

		if (nDataLen == 0)
		{
			nDataLen = strlen(lpSendData);
		}

		CHttpClientResponse resp;
		resp.SetTarget(new CMemoryStream());
		resp.SetSendData(lpSendData, nDataLen);
		if (!m_pTcpClient->IsBusy())
		{
			//直接执行同步请求
			if (m_pTcpClient->TcpGet(lpszUrl, resp) == 0) //成功
			{		
				//在此判断是否存在
				if (pHandler && pHandler->IsAlive())
				{
					return pHandler->HandleData(0, *resp.GetTarget(), NULL);
				}			
			}
		}
		else
		{
			CTcpClient* pTcpClient = new CTcpClient();

			if (pTcpClient)
			{
				//直接执行同步请求
				if (pTcpClient->TcpGet(lpszUrl, resp) == 0) //成功
				{		
					//在此判断是否存在
					if (pHandler && pHandler->IsAlive())
					{
						return pHandler->HandleData(0, *resp.GetTarget(), NULL);
					}			
				}
			}
		}

	}
	return false;
}
Ejemplo n.º 3
0
bool ScutDataLogic::CDataRequest::ExecRequest( CDataHandler* pHandler, const char* lpszUrl )
{
	if (pHandler)
	{
		CHttpSession hs;
		CHttpClient hc(&hs);
		CHttpClientResponse resp;
		resp.SetTarget(new CMemoryStream());
		//直接执行同步请求
		if (hc.HttpGet(lpszUrl, resp) == 0) //成功
		{		
			//在此判断是否存在
			if (pHandler && pHandler->IsAlive())
			{
				return pHandler->HandleData(0, *resp.GetTarget(), NULL);
			}			
		}
	}
	return false;
}
Ejemplo n.º 4
0
bool ScutDataLogic::CDataRequest::ExecRequest(void* pScene)
{
	const std::string strPostData = CNetWriter::getInstance()->generatePostData();
	if (strPostData.size())
	{
		CHttpSession hs;
		CHttpClient hc(&hs);
		CHttpClientResponse resp;
		resp.SetTarget(new CMemoryStream());
		//直接执行同步请求
		int nRet = hc.HttpGet(strPostData.c_str(), resp);
		//处理LUA数据
		CNetWriter::getInstance()->resetData();
		if (nRet == 0)
		{
			LuaHandleData(pScene, 0, aisSucceed, resp.GetTarget(), NULL);
		}
		else
		{
			LuaHandleData(pScene, 0, 0, resp.GetTarget(), NULL);
		}
	}
	return false;
}