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


C++ FindSocketObj函數代碼示例

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


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

示例1: 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

示例2: HandleAccept

void CUdpServer::HandleZeroBytes(CONNID dwConnID, TUdpBufferObj* pBufferObj)
{
	if(pBufferObj->operation == SO_RECEIVE)
	{
		if(dwConnID == 0)
			dwConnID = HandleAccept(pBufferObj);
		
		if(dwConnID != 0)
		{
			TUdpSocketObj* pSocketObj = FindSocketObj(dwConnID);

			if(TUdpSocketObj::IsValid(pSocketObj))
			{
				pSocketObj->detectFails = 0;
				DoSend(pSocketObj, nullptr, 0);
			}
			
			TRACE("<S-CNNID: %Iu> recv 0 bytes (detect package)\n", dwConnID);
		}

		DoReceive(pBufferObj);
	}
	else
	{
		ASSERT(dwConnID != 0);
		TRACE("<S-CNNID: %Iu> send 0 bytes (detect package)\n", dwConnID);
	}
}
開發者ID:JeffLi1993,項目名稱:HP-Socket,代碼行數:28,代碼來源:UdpServer.cpp

示例3: FindSocketObj

void CTcpAgent::AddFreeSocketObj(CONNID dwConnID, EnSocketCloseFlag enFlag, EnSocketOperation enOperation, int iErrorCode)
{
	BOOL bDone				= FALSE;
	TSocketObj* pSocketObj	= FindSocketObj(dwConnID);;

	if(TUdpSocketObj::IsValid(pSocketObj))
	{
		CReentrantWriteLock locallock(m_csClientSocket);

		if(TSocketObj::IsValid(pSocketObj))
		{
			TSocketObj::Invalid(pSocketObj);
			bDone = TRUE;
		}
	}

	if(bDone)
	{
		CloseClientSocketObj(pSocketObj, enFlag, enOperation, iErrorCode);
		TSocketObj::Release(pSocketObj);

		{
			CReentrantWriteLock locallock(m_csClientSocket);
			m_mpClientSocket.erase(dwConnID);
		}

		{
			CCriSecLock locallock(m_csFreeSocket);
			m_lsFreeSocket.push_back(pSocketObj);
		}

		if(m_lsFreeSocket.size() > m_dwFreeSocketObjHold)
			CompressFreeSocket(m_dwFreeSocketObjPool);
	}
}
開發者ID:MatzYang,項目名稱:HP-Socket,代碼行數:35,代碼來源:TcpAgent.cpp

示例4: HandleAccept

void CUdpServer::HandleZeroBytes(CONNID dwConnID, TUdpBufferObj* pBufferObj)
{
	if(pBufferObj->operation == SO_RECEIVE)
	{
		if(dwConnID == 0)
			dwConnID = HandleAccept(pBufferObj);
		
		if(dwConnID != 0)
		{
			TRACE("<S-CNNID: %Iu> recv 0 bytes (detect package)\n", dwConnID);

			TUdpSocketObj* pSocketObj = FindSocketObj(dwConnID);

			if(TUdpSocketObj::IsValid(pSocketObj))
			{
				pSocketObj->detectFails = 0;
				SendDetectPackage(dwConnID, pSocketObj);
			}			
		}

		DoReceive(pBufferObj);
	}
	else
		VERIFY(FALSE);
}
開發者ID:grasswin,項目名稱:HP-Socket,代碼行數:25,代碼來源:UdpServer.cpp

示例5: locallock

void CUdpServer::AddFreeSocketObj(CONNID dwConnID)
{
	BOOL bDone = FALSE;
	TUdpSocketObj* pSocketObj = nullptr;

	{
		CReentrantWriteLock locallock(m_csClientSocket);

		pSocketObj = FindSocketObj(dwConnID);
		if(pSocketObj != nullptr)
		{
			m_mpClientAddr.erase(&pSocketObj->clientAddr);
			m_mpClientSocket.erase(dwConnID);
			bDone = TRUE;
		}
	}

	if(bDone)
	{
		{
			CCriSecLock locallock(m_csFreeSocket);

			pSocketObj->freeTime = ::TimeGetTime();
			m_lsFreeSocket.push_back(pSocketObj);
		}

		if(m_lsFreeSocket.size() > m_dwFreeSocketObjHold)
			CompressFreeSocket(m_dwFreeSocketObjPool);
	}
}
開發者ID:KnowNo,項目名稱:test-code-backup,代碼行數:30,代碼來源:UdpServer.cpp

示例6: FindSocketObj

void CUdpServer::ForceDisconnect(CONNID dwConnID)
{
	TUdpSocketObj* pSocketObj = FindSocketObj(dwConnID);

	if(TUdpSocketObj::IsValid(pSocketObj))
		AddFreeSocketObj(dwConnID, SCF_CLOSE);
}
開發者ID:JeffLi1993,項目名稱:HP-Socket,代碼行數:7,代碼來源:UdpServer.cpp

示例7: ASSERT

BOOL CTcpAgent::Send(CONNID dwConnID, const BYTE* pBuffer, int iLength, int iOffset)
{
	ASSERT(pBuffer && iLength > 0);

	if(iOffset != 0) pBuffer += iOffset;

	int result				= NO_ERROR;
	TSocketObj* pSocketObj	= FindSocketObj(dwConnID);

	if(!TSocketObj::IsValid(pSocketObj))
		result = ERROR_OBJECT_NOT_FOUND;
	else
	{
		CCriSecLock locallock(pSocketObj->crisec);

		if(!TSocketObj::IsValid(pSocketObj))
			result = ERROR_OBJECT_NOT_FOUND;
		else
		{
			switch(m_enSendPolicy)
			{
			case SP_PACK:	result = SendPack(pSocketObj, pBuffer, iLength);	break;
			case SP_SAFE:	result = SendSafe(pSocketObj, pBuffer, iLength);	break;
			case SP_DIRECT:	result = SendDirect(pSocketObj, pBuffer, iLength);	break;
			default: ASSERT(FALSE);	result = ERROR_INVALID_INDEX;				break;
			}
		}
	}

	if(result != NO_ERROR)
		::SetLastError(result);

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

示例8: FindSocketObj

int CUdpServer::DoSend(CONNID dwConnID)
{
	TUdpSocketObj* pSocketObj = FindSocketObj(dwConnID);

	if(TUdpSocketObj::IsValid(pSocketObj))
		return DoSend(pSocketObj);

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

示例9: ASSERT

void CTcpServer::AddClientSocketObj(CONNID dwConnID, TSocketObj* pSocketObj)
{
	ASSERT(FindSocketObj(dwConnID) == nullptr);

	pSocketObj->connTime	= ::TimeGetTime();
	pSocketObj->activeTime	= pSocketObj->connTime;

	VERIFY(m_bfActiveSockets.ReleaseLock(dwConnID, pSocketObj));
}
開發者ID:ExpLife0011,項目名稱:JsModule,代碼行數:9,代碼來源:TcpServer.cpp

示例10: FindSocketObj

BOOL CTcpServer::IsConnected(CONNID dwConnID)
{
	TSocketObj* pSocketObj = FindSocketObj(dwConnID);

	if(TSocketObj::IsValid(pSocketObj))
		return pSocketObj->HasConnected();

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

示例11: locallock

void CUdpServer::AddClientSocketObj(CONNID dwConnID, TUdpSocketObj* pSocketObj)
{
	CReentrantWriteLock locallock(m_csClientSocket);

	ASSERT(FindSocketObj(dwConnID) == nullptr);

	pSocketObj->connTime						= ::TimeGetTime();
	m_mpClientSocket[dwConnID]					= pSocketObj;
	m_mpClientAddr	[&pSocketObj->clientAddr]	= dwConnID;
}
開發者ID:JeffLi1993,項目名稱:HP-Socket,代碼行數:10,代碼來源:UdpServer.cpp

示例12: FindSocketObj

void CUdpServer::ForceDisconnect(CONNID dwConnID)
{
	TUdpSocketObj* pSocketObj = FindSocketObj(dwConnID);

	if(pSocketObj != nullptr)
	{
		FireClose(dwConnID);
		AddFreeSocketObj(dwConnID);
	}
}
開發者ID:KnowNo,項目名稱:test-code-backup,代碼行數:10,代碼來源:UdpServer.cpp

示例13: FindSocketObj

BOOL CIocpServer::GetConnectionAddress(DWORD dwConnID, CString& strAddress, USHORT& usPort)
{
	TSocketObj* pSocketObj = FindSocketObj(dwConnID);
	if(pSocketObj)
	{
		strAddress	= CA2T(inet_ntoa(pSocketObj->clientAddr.sin_addr));
		usPort		= ntohs(pSocketObj->clientAddr.sin_port);
	}

	return pSocketObj != NULL;
}
開發者ID:KnowNo,項目名稱:test-code-backup,代碼行數:11,代碼來源:IocpServer.cpp

示例14: RemoveSocketObjByHandle

//
// Function: RemoveSocketObjByHandle
//
// Description:
//    Remove the socket object structure from the list of objects that
//    matches the socket handle.
//
void RemoveSocketObjByHandle(SOCKET s)
{
    SOCKET_OBJ *obj;

    obj = FindSocketObj(s);
    if (obj)
    {
        RemoveSocketObj(obj);
    }
    return;
}
開發者ID:c3827286,項目名稱:NetworkProgrammingForMicrosoftWindows2e,代碼行數:18,代碼來源:asyncserver.cpp

示例15: ASSERT

void CTcpServer::AddClientSocketObj(CONNID dwConnID, TSocketObj* pSocketObj, const HP_SOCKADDR& remoteAddr)
{
	ASSERT(FindSocketObj(dwConnID) == nullptr);

	pSocketObj->connTime	= ::TimeGetTime();
	pSocketObj->activeTime	= pSocketObj->connTime;

	remoteAddr.Copy(pSocketObj->remoteAddr);
	pSocketObj->SetConnected();

	ENSURE(m_bfActiveSockets.ReleaseLock(dwConnID, pSocketObj));
}
開發者ID:huazhipeng,項目名稱:HP-Socket,代碼行數:12,代碼來源:TcpServer.cpp


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