當前位置: 首頁>>代碼示例>>C++>>正文


C++ AddFreeBufferObj函數代碼示例

本文整理匯總了C++中AddFreeBufferObj函數的典型用法代碼示例。如果您正苦於以下問題:C++ AddFreeBufferObj函數的具體用法?C++ AddFreeBufferObj怎麽用?C++ AddFreeBufferObj使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了AddFreeBufferObj函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。

示例1: TriggerFireReceive

void CTcpServer::HandleReceive(CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj)
{
	if(m_bMarkSilence) pSocketObj->activeTime = ::TimeGetTime();

	EnHandleResult hr = TriggerFireReceive(pSocketObj, pBufferObj);

	if(hr == HR_OK || hr == HR_IGNORE)
	{
		if(ContinueReceive(pSocketObj, pBufferObj, hr))
		{
			{
				CSpinLock locallock(pSocketObj->sgPause);

				pSocketObj->recving = FALSE;
			}

			DoReceive(pSocketObj, pBufferObj);
		}
	}

	if(hr == HR_CLOSED)
	{
		AddFreeBufferObj(pBufferObj);
	}
	else if(hr == HR_ERROR)
	{
		TRACE("<S-CNNID: %Iu> OnReceive() event return 'HR_ERROR', connection will be closed !\n", dwConnID);

		AddFreeSocketObj(pSocketObj, SCF_ERROR, SO_RECEIVE, ENSURE_ERROR_CANCELLED);
		AddFreeBufferObj(pBufferObj);
	}
}
開發者ID:huazhipeng,項目名稱:HP-Socket,代碼行數:32,代碼來源:TcpServer.cpp

示例2: VERIFY

void CTcpServer::HandleAccept(SOCKET soListen, TBufferObj* pBufferObj)
{
	VERIFY(::PostIocpAccept(m_hCompletePort));

	int iLocalSockaddrLen;
	int iRemoteSockaddrLen;
	HP_PSOCKADDR pLocalSockAddr;
	HP_PSOCKADDR pRemoteSockAddr;

	int iAddrLen = HP_SOCKADDR::AddrSize(m_usFamily) + 16;

	m_pfnGetAcceptExSockaddrs
							(
								pBufferObj->buff.buf,
								0,
								iAddrLen,
								iAddrLen,
								(SOCKADDR**)&pLocalSockAddr,
								&iLocalSockaddrLen,
								(SOCKADDR**)&pRemoteSockAddr,
								&iRemoteSockaddrLen
							);

	CONNID dwConnID = 0;
	SOCKET socket	= pBufferObj->client;

	if(!HasStarted() || !m_bfActiveSockets.AcquireLock(dwConnID))
	{
		::ManualCloseSocket(socket, SD_BOTH);
		AddFreeBufferObj(pBufferObj);

		return;
	}

	TSocketObj* pSocketObj = GetFreeSocketObj(dwConnID, socket);

	pRemoteSockAddr->Copy(pSocketObj->remoteAddr);
	AddClientSocketObj(dwConnID, pSocketObj);

	::SSO_UpdateAcceptContext(socket, soListen);
	::CreateIoCompletionPort((HANDLE)socket, m_hCompletePort, (ULONG_PTR)pSocketObj, 0);

	if(TriggerFireAccept(pSocketObj) != HR_ERROR)
		DoReceive(pSocketObj, pBufferObj);
	else
	{
		AddFreeSocketObj(pSocketObj, SCF_NONE);
		AddFreeBufferObj(pBufferObj);
	}
}
開發者ID:ExpLife0011,項目名稱:JsModule,代碼行數:50,代碼來源:TcpServer.cpp

示例3: while

int CTcpAgent::SendDirect(TSocketObj* pSocketObj, const BYTE* pBuffer, int iLength)
{
	int result	= NO_ERROR;
	int iRemain	= iLength;

	while(iRemain > 0)
	{
		int iBufferSize = min(iRemain, (int)m_dwSocketBufferSize);
		TBufferObj* pBufferObj = GetFreeBufferObj(iBufferSize);
		memcpy(pBufferObj->buff.buf, pBuffer, iBufferSize);

		result = ::PostSend(pSocketObj, pBufferObj);

		if(result != NO_ERROR)
		{
			AddFreeBufferObj(pBufferObj);
			break;
		}

		iRemain -= iBufferSize;
		pBuffer += iBufferSize;
	}

	if(result != NO_ERROR)
		CheckError(pSocketObj->connID, SO_SEND, result);

	return result;
}
開發者ID:MatzYang,項目名稱:HP-Socket,代碼行數:28,代碼來源:TcpAgent.cpp

示例4: while

int CTcpAgent::SendItem(TSocketObj* pSocketObj)
{
	int result = NO_ERROR;

	while(pSocketObj->sndBuff.Size() > 0)
	{
		::InterlockedIncrement(&pSocketObj->sndCount);

		TBufferObj* pBufferObj	= pSocketObj->sndBuff.PopFront();
		int iBufferSize			= pBufferObj->buff.len;

		ASSERT(iBufferSize > 0 && iBufferSize <= (int)m_dwSocketBufferSize);

		pSocketObj->pending	   -= iBufferSize;

		result = ::PostSendNotCheck(pSocketObj, pBufferObj);

		if(result != NO_ERROR)
		{
			if(result != WSA_IO_PENDING)
				AddFreeBufferObj(pBufferObj);

			break;
		}
	}

	return result;
}
開發者ID:kooyain,項目名稱:HP-Socket,代碼行數:28,代碼來源:TcpAgent.cpp

示例5: ASSERT

void CTcpAgent::HandleIo(CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj, DWORD dwBytes, DWORD dwErrorCode)
{
	ASSERT(pBufferObj != nullptr);
	ASSERT(pSocketObj != nullptr);

	if(dwErrorCode != NO_ERROR)
	{
		HandleError(dwConnID, pBufferObj, dwErrorCode);
		return;
	}

	if(dwBytes == 0 && pBufferObj->operation != SO_CONNECT)
	{
		AddFreeSocketObj(dwConnID, SCF_CLOSE);
		AddFreeBufferObj(pBufferObj);
		return;
	}

	pBufferObj->buff.len = dwBytes;

	switch(pBufferObj->operation)
	{
	case SO_CONNECT:
		HandleConnect(dwConnID, pSocketObj, pBufferObj);
		break;
	case SO_SEND:
		HandleSend(dwConnID, pSocketObj, pBufferObj);
		break;
	case SO_RECEIVE:
		HandleReceive(dwConnID, pSocketObj, pBufferObj);
		break;
	default:
		ASSERT(FALSE);
	}
}
開發者ID:MatzYang,項目名稱:HP-Socket,代碼行數:35,代碼來源:TcpAgent.cpp

示例6: locallock

int CTcpServer::DoSend(CONNID dwConnID, TSocketObj* pSocketObj, const BYTE* pBuffer, int iLen)
{
	int result	= NO_ERROR;
	int iRemain	= iLen;

	CCriSecLock locallock(pSocketObj->crisec);

	while(iRemain > 0)
	{
		int iBufferSize = min(iRemain, (int)m_dwSocketBufferSize);
		TBufferObj* pBufferObj = GetFreeBufferObj(iBufferSize);
		memcpy(pBufferObj->buff.buf, pBuffer, iBufferSize);

		result = ::PostSend(pSocketObj, pBufferObj);

		if(result != NO_ERROR)
		{
			AddFreeBufferObj(pBufferObj);
			break;
		}

		iRemain -= iBufferSize;
		pBuffer += iBufferSize;
	}

	return result;
}
開發者ID:JeffLi1993,項目名稱:HP-Socket,代碼行數:27,代碼來源:TcpServer.cpp

示例7: TRIGGER

EnHandleResult CTcpServer::TriggerFireSend(TSocketObj* pSocketObj, TBufferObj* pBufferObj)
{
	EnHandleResult rs = (EnHandleResult)HR_CLOSED;

	if(m_enOnSendSyncPolicy == OSSP_NONE)
		rs = TRIGGER(FireSend(pSocketObj, (BYTE*)pBufferObj->buff.buf, pBufferObj->buff.len));
	else
	{
		ASSERT(m_enOnSendSyncPolicy >= OSSP_CLOSE && m_enOnSendSyncPolicy <= OSSP_RECEIVE);

		if(TSocketObj::IsValid(pSocketObj))
		{
			CCriSecLock locallock(m_enOnSendSyncPolicy == OSSP_CLOSE ? pSocketObj->csSend : pSocketObj->csRecv);

			if(TSocketObj::IsValid(pSocketObj))
			{
				rs = TRIGGER(FireSend(pSocketObj, (BYTE*)pBufferObj->buff.buf, pBufferObj->buff.len));
			}
		}
	}

	if(rs == HR_ERROR)
	{
		TRACE("<S-CNNID: %Iu> OnSend() event should not return 'HR_ERROR' !!\n", pSocketObj->connID);
		ASSERT(FALSE);
	}

	if(pBufferObj->ReleaseSendCounter() == 0)
		AddFreeBufferObj(pBufferObj);

	return rs;
}
開發者ID:huazhipeng,項目名稱:HP-Socket,代碼行數:32,代碼來源:TcpServer.cpp

示例8: TriggerFireReceive

BOOL CTcpServer::ContinueReceive(TSocketObj* pSocketObj, TBufferObj* pBufferObj, EnHandleResult& hr)
{
	int rs = NO_ERROR;

	for(int i = 0; i < MAX_IOCP_CONTINUE_RECEIVE || MAX_IOCP_CONTINUE_RECEIVE < 0; i++)
	{
		if(hr != HR_OK && hr != HR_IGNORE)
			break;

		if(pBufferObj->buff.len != m_dwSocketBufferSize)
			break;

		pBufferObj->buff.len = m_dwSocketBufferSize;
		rs =::NoBlockReceiveNotCheck(pBufferObj);

		if(rs != NO_ERROR)
			break;

		hr = TriggerFireReceive(pSocketObj, pBufferObj);
	}

	if(rs != NO_ERROR && rs != WSAEWOULDBLOCK)
	{
		if(rs == WSAEDISCON)
			AddFreeSocketObj(pSocketObj, SCF_CLOSE);
		else
			CheckError(pSocketObj, SO_RECEIVE, rs);
		
		AddFreeBufferObj(pBufferObj);

		return FALSE;
	}

	return TRUE;
}
開發者ID:ExpLife0011,項目名稱:JsModule,代碼行數:35,代碼來源:TcpServer.cpp

示例9: while

int CTcpServer::SendItem(TSocketObj* pSocketObj)
{
	int result = NO_ERROR;

	while(pSocketObj->sndBuff.Size() > 0)
	{
		TBufferObj* pBufferObj	= pSocketObj->sndBuff.PopFront();
		int iBufferSize			= pBufferObj->buff.len;

		ASSERT(iBufferSize > 0 && iBufferSize <= (int)m_dwSocketBufferSize);

		pSocketObj->pending	   -= iBufferSize;
		::InterlockedExchangeAdd(&pSocketObj->sndCount, iBufferSize);

		result			= ::PostSendNotCheck(pSocketObj, pBufferObj);
		LONG sndCounter	= pBufferObj->ReleaseSendCounter();

		if(sndCounter == 0 || !IOCP_SUCCESS(result))
			AddFreeBufferObj(pBufferObj);

		if(result != NO_ERROR)
			break;
	}

	return result;
}
開發者ID:huazhipeng,項目名稱:HP-Socket,代碼行數:26,代碼來源:TcpServer.cpp

示例10: locallock

int CTcpServer::DoReceive(TSocketObj* pSocketObj, TBufferObj* pBufferObj)
{
	int result		= NO_ERROR;
	BOOL bNeedFree	= FALSE;

	{
		CSpinLock locallock(pSocketObj->sgPause);

		if(pSocketObj->paused || pSocketObj->recving)
			bNeedFree = TRUE;
		else
		{
			pSocketObj->recving	 = TRUE;
			pBufferObj->buff.len = m_dwSocketBufferSize;

			result = ::PostReceive(pSocketObj, pBufferObj);
		}
	}

	if(result != NO_ERROR)
	{
		CheckError(pSocketObj, SO_RECEIVE, result);
		bNeedFree = TRUE;
	}

	if(bNeedFree) AddFreeBufferObj(pBufferObj);

	return result;
}
開發者ID:huazhipeng,項目名稱:HP-Socket,代碼行數:29,代碼來源:TcpServer.cpp

示例11: socket

BOOL CTcpServer::DoAccept()
{
	BOOL isOK = FALSE;

	if(HasStarted())
	{
		SOCKET		soClient	= socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
		TBufferObj*	pBufferObj	= GetFreeBufferObj();

		ASSERT(soClient != INVALID_SOCKET);

		isOK = (::PostAccept(m_pfnAcceptEx, m_soListen, soClient, pBufferObj) == NO_ERROR);

		if(!isOK)
		{
			VERIFY(!HasStarted());

			::ManualCloseSocket(soClient);
			AddFreeBufferObj(pBufferObj);
		}
	}

	if(!isOK)
	{
		::InterlockedDecrement(&m_iRemainAcceptSockets);
		ASSERT(m_iRemainAcceptSockets >= 0);
	}

	return isOK;
}
開發者ID:Cutie-Pie,項目名稱:HP-Socket,代碼行數:30,代碼來源:TcpServer.cpp

示例12: while

int CUdpServer::SendItem(TUdpSocketObj* pSocketObj)
{
	int result = NO_ERROR;

	while(pSocketObj->sndBuff.Size() > 0)
	{
		::InterlockedIncrement(&pSocketObj->sndCount);

		TItemPtr itPtr(m_itPool, pSocketObj->sndBuff.PopFront());

		int iBufferSize = itPtr->Size();
		ASSERT(iBufferSize > 0 && iBufferSize <= (int)m_dwMaxDatagramSize);

		pSocketObj->pending		 -= iBufferSize;
		TUdpBufferObj* pBufferObj = GetFreeBufferObj(iBufferSize);

		memcpy(&pBufferObj->remoteAddr, &pSocketObj->remoteAddr, sizeof(SOCKADDR_IN));
		memcpy(pBufferObj->buff.buf, itPtr->Ptr(), iBufferSize);

		int result = ::PostSendToNotCheck(m_soListen, pBufferObj);

		if(result != NO_ERROR)
		{
			if(result != WSA_IO_PENDING)
				AddFreeBufferObj(pBufferObj);;

			break;
		}
	}

	return result;
}
開發者ID:grasswin,項目名稱:HP-Socket,代碼行數:32,代碼來源:UdpServer.cpp

示例13: ASSERT

void CIocpServer::HandleIo(TSocketObj* pSocketObj, TBufferObj* pBufferObj, DWORD dwBytes, DWORD dwErrorCode)
{
	ASSERT(pBufferObj != NULL);
	ASSERT(pSocketObj != NULL);

	//判斷是否已經標記失敗
	if(dwErrorCode != NO_ERROR)
	{
		if(pBufferObj->operation != SO_ACCEPT)
		{
			FireError(pSocketObj->connID, pBufferObj->operation, dwErrorCode);
			AddFreeSocketObj(pSocketObj->connID);
		}
		else
		{
			DeleteAcceptSocket(pBufferObj->client, TRUE);
		}

		AddFreeBufferObj(pBufferObj);
		return;
	}

	if(dwBytes == 0 && pBufferObj->operation != SO_ACCEPT)
	{
		FireClose(pSocketObj->connID);
		AddFreeSocketObj(pSocketObj->connID);
		AddFreeBufferObj(pBufferObj);
		return;
	}

	pBufferObj->buff.len = dwBytes;

	switch(pBufferObj->operation)
	{
	case SO_ACCEPT:
		HandleAccept((SOCKET)pSocketObj, pBufferObj);
		break;
	case SO_SEND:
		HandleSend(pSocketObj, pBufferObj);
		break;
	case SO_RECEIVE:
		HandleReceive(pSocketObj, pBufferObj);
		break;
	default:
		ASSERT(FALSE);
	}
}
開發者ID:KnowNo,項目名稱:test-code-backup,代碼行數:47,代碼來源:IocpServer.cpp

示例14: switch

void CUdpServer::HandleSend(CONNID dwConnID, TUdpBufferObj* pBufferObj)
{
	BOOL bNeedFree = FALSE;

	switch(m_enSendPolicy)
	{
	case SP_PACK:
		{
			TUdpSocketObj* pSocketObj = FindSocketObj(dwConnID);

			if(TUdpSocketObj::IsValid(pSocketObj))
			{
				long sndCount = ::InterlockedDecrement(&pSocketObj->sndCount);

				TriggerFireSend(dwConnID, pBufferObj);
				if(sndCount == 0) DoSendPack(pSocketObj);
			}
			else
				bNeedFree = TRUE;
		}

		break;
	case SP_SAFE:
		{
			long sndCount				= -1;
			TUdpSocketObj* pSocketObj	= FindSocketObj(dwConnID);

			if(TUdpSocketObj::IsValid(pSocketObj))
			{
				sndCount = ::InterlockedDecrement(&pSocketObj->sndCount);

				if(sndCount == 0 && !pSocketObj->smooth)
				{
					CCriSecLock locallock(pSocketObj->crisec);

					if((sndCount = pSocketObj->sndCount) == 0)
						pSocketObj->smooth = TRUE;
				}

				TriggerFireSend(dwConnID, pBufferObj);
				if(sndCount == 0) DoSendSafe(pSocketObj);
			}
			else
				bNeedFree = TRUE;
		}

		break;
	case SP_DIRECT:
		{
			TriggerFireSend(dwConnID, pBufferObj);
		}

		break;
	default:
		ASSERT(FALSE);
	}

	if(bNeedFree) AddFreeBufferObj(pBufferObj);
}
開發者ID:grasswin,項目名稱:HP-Socket,代碼行數:59,代碼來源:UdpServer.cpp

示例15: TriggerFireReceive

void CTcpServer::HandleReceive(CONNID dwConnID, TSocketObj* pSocketObj, TBufferObj* pBufferObj)
{
	if(m_bMarkSilence) pSocketObj->activeTime = ::TimeGetTime();
	EnHandleResult hr = TriggerFireReceive(pSocketObj, pBufferObj);

	if(hr == HR_OK || hr == HR_IGNORE)
		DoReceive(dwConnID, pSocketObj, pBufferObj);
	else if(hr == HR_CLOSED)
	{
		AddFreeBufferObj(pBufferObj);
	}
	else
	{
		AddFreeSocketObj(pSocketObj, SCF_ERROR, SO_RECEIVE, ERROR_CANCELLED);
		AddFreeBufferObj(pBufferObj);
	}
}
開發者ID:Cutie-Pie,項目名稱:HP-Socket,代碼行數:17,代碼來源:TcpServer.cpp


注:本文中的AddFreeBufferObj函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。