本文整理汇总了C++中NetworkManager::RemoveHTTPMarkers方法的典型用法代码示例。如果您正苦于以下问题:C++ NetworkManager::RemoveHTTPMarkers方法的具体用法?C++ NetworkManager::RemoveHTTPMarkers怎么用?C++ NetworkManager::RemoveHTTPMarkers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetworkManager
的用法示例。
在下文中一共展示了NetworkManager::RemoveHTTPMarkers方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NetworkThread
//! Network thread
void* NetworkManager::NetworkThread(void* pParam)
{
Log << "NetworkManager: NetworkThread started\n";
NetworkManager* pMgr = NetworkManager::Instance();
pMgr->m_bActive = true;
while(Engine::Instance()->IsRunning())
{
if(pMgr->m_lOperations.empty())
{
Thread::YieldThread();
continue;
}
pMgr->m_pMutex->Lock();
Operation operation = pMgr->m_lOperations.front();
pMgr->m_pMutex->Unlock();
struct hostent* server = gethostbyname(operation.m_HostName.c_str());
if(!server)
{
pMgr->OnError("couldn't resolve host");
continue;
}
struct sockaddr_in serv_addr;
memset(&serv_addr, 0, sizeof(struct sockaddr_in));
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(operation.m_Port);
memcpy((char *)&serv_addr.sin_addr.s_addr, (char*)server->h_addr, server->h_length);
Log.Print("NetworkThread connect: m_SocketID(%d)\n", operation.m_SocketID);
if(connect(operation.m_SocketID, (struct sockaddr*)&serv_addr, sizeof(serv_addr)) != 0)
{
pMgr->OnError("couldn't connect to host");
continue;
}
Log.Print("NetworkThread send: m_SocketID(%d)\n", operation.m_SocketID);
if(send(operation.m_SocketID, (const char*)operation.m_pData,operation.m_DataSize, 0) != operation.m_DataSize)
{
pMgr->OnError("data send error");
continue;
}
{
std::vector<uchar> readData;
while(Engine::Instance()->IsRunning())
{
Log.Print("NetworkThread recv: m_SocketID(%d)\n", operation.m_SocketID);
int received = recv(operation.m_SocketID, (char*)pMgr->m_ReadBuffer, ReadBufferSize, 0);
if(received < 0)
{
pMgr->OnError("data receive error");
break;
}
if(received > 0)
{
auto currentSize = readData.size();
readData.reserve(currentSize+received);
std::copy(pMgr->m_ReadBuffer, pMgr->m_ReadBuffer+received, std::back_inserter(readData));
}
// HTTP hack to check if we received the end of the response.
// TODO: make this check on the application side.
int end = received-1;
bool bHTPPEnd = false;
char* buf = (char*)pMgr->m_ReadBuffer;
if(end >= 3)
{
bHTPPEnd = (buf[end-3] == '\r' && buf[end-2] == '\n' && buf[end-1] == '\r' && buf[end] == '\n');
}
if(bHTPPEnd || received == 0)
{
NetResult result;
pMgr->RemoveHTTPMarkers(readData, result.m_Data);
result.m_Status = NetResult::S_DataReceived;
if(operation.m_pResultCallback)
{
operation.m_pResultCallback(result);
}
operation.Release();
pMgr->m_pMutex->Lock();
pMgr->m_lOperations.pop_front();
pMgr->m_pMutex->Unlock();
break;
}
}
}
}
pMgr->m_bActive = false;
Log << "NetworkManager: NetworkThread finished\n";
return NULL;
}