当前位置: 首页>>代码示例>>C++>>正文


C++ Operation::Release方法代码示例

本文整理汇总了C++中Operation::Release方法的典型用法代码示例。如果您正苦于以下问题:C++ Operation::Release方法的具体用法?C++ Operation::Release怎么用?C++ Operation::Release使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Operation的用法示例。


在下文中一共展示了Operation::Release方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: OnError

	//! called on a network error
	void NetworkManager::OnError(const char* strError)
	{
		Log.Print("NetworkManager: error - %s\n", strError);
		m_pMutex->Lock();
		Operation operation = m_lOperations.front();
		m_pMutex->Unlock();

		NetResult result;
		result.m_Status = NetResult::S_ConnectionError;
		if(operation.m_pResultCallback)
		{
			operation.m_pResultCallback(result);
		}

		operation.Release();
		m_pMutex->Lock();
		m_lOperations.pop_front();
		m_pMutex->Unlock();
	}
开发者ID:aminere,项目名称:StarportsPublic,代码行数:20,代码来源:NetworkManager.cpp

示例2: 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;
	}
开发者ID:aminere,项目名称:StarportsPublic,代码行数:96,代码来源:NetworkManager.cpp


注:本文中的Operation::Release方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。