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


C++ CIOBuffer::GetUsed方法代码示例

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


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

示例1: OnDataRecieved

HRESULT CServer::OnDataRecieved()
{
   if (!m_pSocketServer)
   {
      return Error(L"Server hasn't been initialised - programming error!");
   }

   if (!m_pIDataInit || !m_pIData)
   {
      return Error(L"Internal error: failed to create Data object");
   }
   
   CCOMSocketServer::Socket *pSocket = m_pSocketServer->GetSocket();

   CIOBuffer *pBuffer = m_pSocketServer->GetBuffer();

   if (!pSocket || !pBuffer)
   {
      return Error(L"Internal error: pSocket or pBuffer is 0");
   }

   ISocket *pISocket = reinterpret_cast<ISocket*>(pSocket->GetUserPtr());

   HRESULT hr = m_pIDataInit->Init(pBuffer->GetBuffer(), pBuffer->GetUsed());

   if (SUCCEEDED(hr))
   {  
      Fire_OnDataReceived(pISocket, m_pIData);   // this can stall if the handler doesnt return - 
                                                 // the ATL implementation is difficult to multi thread...
   }

   return hr;
}
开发者ID:legacygamedev,项目名称:limited-source,代码行数:33,代码来源:Server.cpp

示例2: Write

void CSocketClient::Write( const char *pData, size_t dataLength )
{
	if ( INVALID_SOCKET != m_connectSocket &&
		dataLength > 0 &&
		pData )
	{
		CIOBuffer *pBuffer = Allocate();
		
		/*
		 * Call to unqualified virtual function
		 */
		PreWrite( pBuffer, pData, dataLength );

		pBuffer->AddData( pData, dataLength );

		/*
		 * Begin to send data
		 */
		pBuffer->SetupWrite();
		
		DWORD dwFlags = 0;
		DWORD dwSendNumBytes = 0;
		
		if ( SOCKET_ERROR == ::WSASend(
					m_connectSocket,
					pBuffer->GetWSABUF(), 
					1, 
					&dwSendNumBytes,
					dwFlags,
					pBuffer, 
					NULL) )
		{
			DWORD lastError = ::WSAGetLastError();
			
			if ( ERROR_IO_PENDING != lastError )
			{
				Output( _T("CSocketClient::Write() - WSASend: ") + GetLastErrorMessage( lastError ) );
				
				if ( lastError == WSAECONNABORTED || 
					lastError == WSAECONNRESET ||
					lastError == WSAEDISCON)
				{
					StopConnections();
				}
			}
		}
		
		if ( pBuffer->GetUsed() != pBuffer->GetWSABUF()->len )
		{
			/*
			 * Call to unqualified virtual function
			 */
			//OnError(_T("CSocketClient::WriteCompleted - Socket write where not all data was written"));
		}

		pBuffer->Release();
	}
}
开发者ID:XeanoRRR,项目名称:mmo-resourse,代码行数:58,代码来源:SocketClient.cpp


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