Beispiel #1
0
int CUdpCast::SendInternal(const BYTE* pBuffer, int iLength)
{
	int result = NO_ERROR;

	if(HasStarted())
	{
		CCriSecLock locallock(m_csSend);

		if(HasStarted())
		{
			ASSERT(m_iPending >= 0);

			BOOL isPending = m_iPending > 0;

			TItem* pItem = m_itPool.PickFreeItem();
			pItem->Cat(pBuffer, iLength);
			m_lsSend.PushBack(pItem);

			m_iPending += iLength;

			if(!isPending) m_evBuffer.Set();
		}
		else
			result = ERROR_INVALID_STATE;
	}
	else
		result = ERROR_INVALID_STATE;

	return result;
}
Beispiel #2
0
int CUdpServer::CatAndPost(TUdpSocketObj* pSocketObj, const BYTE* pBuffer, int iLength, BOOL isPostSend)
{
	int result	 = NO_ERROR;
	TItem* pItem = m_itPool.PickFreeItem();

	pItem->Cat(pBuffer, iLength);
	pSocketObj->sndBuff.PushBack(pItem);
	pSocketObj->pending += iLength;

	if(isPostSend && !::PostIocpSend(m_hCompletePort, pSocketObj->connID))
		result = ::GetLastError();

	return result;
}
int TItemList::Cat(const BYTE* pData, int length)
{
	int remain = length;

	while(remain > 0)
	{
		TItem* pItem = Back();

		if(pItem == nullptr || pItem->IsFull())
			pItem = PushBack(itPool.PickFreeItem());

		int cat  = pItem->Cat(pData, remain);

		pData	+= cat;
		remain	-= cat;
	}

	return length;
}
Beispiel #4
0
BOOL CUdpServer::Send(CONNID dwConnID, const BYTE* pBuffer, int iLength, int iOffset)
{
	ASSERT(pBuffer && iLength > 0 && iLength <= (int)m_dwMaxDatagramSize);

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

	if(!pBuffer || iLength <= 0 || iLength > (int)m_dwMaxDatagramSize)
	{
		::SetLastError(ERROR_INVALID_PARAMETER);
		return FALSE;
	}

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

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

		if(!TUdpSocketObj::IsValid(pSocketObj))
			result = ERROR_OBJECT_NOT_FOUND;
		else
		{
			BOOL isPending	= TUdpSocketObj::IsPending(pSocketObj);
			TItem* pItem	= m_itPool.PickFreeItem();

			pItem->Cat(pBuffer, iLength);
			pSocketObj->sndBuff.PushBack(pItem);
			pSocketObj->pending += iLength;

			if(!isPending && !::PostIocpSend(m_hCompletePort, dwConnID))
				result = ::GetLastError();
		}
	}

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

	return (result == NO_ERROR);
}