Exemple #1
0
void AbstractHost::processPackage()
{
	Package *constructedPackage = new Package(parseBuffer);
	if(!constructedPackage->isValid())
	{
		sendPackage(constructAcknowledgementPackage(constructedPackage, "invalid"));
		delete constructedPackage;
	}
	else if(!server->packageRouterInstance()->isAllowed(type, constructedPackage))
	{
		sendPackageAndDelete(constructAcknowledgementPackage(constructedPackage, "forbidden"));
		delete constructedPackage;
	}
	else if(constructedPackage->getType() == ConnectionManagement)
	{
		updateNextPackageID(constructedPackage->getID());
		handlePackage(constructedPackage);
	}
	else if(state == Established)
	{
		updateNextPackageID(constructedPackage->getID());
		server->packageRouterInstance()->processPackage(this, constructedPackage);
	}
	else
	{
		sendPackage(constructAcknowledgementPackage(constructedPackage, "invalid"));
		delete constructedPackage;
	}


	parseBuffer.clear();
}
Exemple #2
0
int EventConnection::RecBuf()
{
	int errCode = YQER_OK;
	BOOL parseBuffer = FALSE;
	BOOL bufferedData = FALSE;
	BYTE msg[BUF_SIZE];
	BYTE* pMsg = msg;
	DWORD msgLen = (DWORD)bufferevent_read(bev, msg, BUF_SIZE-1 );
	LOG(LOG_INFORMATION,"rec pkg len[%d] data:%s",msgLen, TYQUtils::Byte2Hex(msg,msgLen).c_str());
	if (m_buffer){
		appendData2Buffer(msg,msgLen);
		pMsg = m_buffer;		
		msgLen = m_buffer_size;
		parseBuffer = TRUE;
	}
	while(msgLen > 0) 
	{
		IPackage* pkg = createPackage();
		if (!pkg)
			break;
		DWORD eatLen = 0;
		errCode = pkg->ParseProto(pMsg,msgLen,eatLen);
		pMsg += eatLen;
		msgLen -= eatLen;
		if (errCode == YQER_OK){
			//由handlePackage进行删除pkg
			errCode = handlePackage(pkg);
		}
		else if (errCode == YQER_PKG_Err(1)){
			//半截包,缓存起来继续接收
			YQLogMin("RecBuf,half pkg, bufferred and wait left data...");
			if (parseBuffer){
				memmove(m_buffer,pMsg,msgLen);
				m_buffer_size = msgLen;
			}
			else{
				m_buffer_size = msgLen;
				m_buffer = new BYTE[m_buffer_size];
				memcpy(m_buffer,pMsg,msgLen);
			}
			delete pkg;
			bufferedData = TRUE;
			break;
		}
		else{
			YQLogMin("RecBuf, pkg invalid!");
			delete pkg;
		}
	}

	if (!bufferedData && m_buffer){
		delete[] m_buffer;
		m_buffer = NULL;
		m_buffer_size = 0;
	}

	return errCode;
}
void CPosSession::CreateSubSessionL(TPositionModuleId aId, TBool aIsProxy, const RMessage2& aMessage)
	{
    CPosSubSession* subSession = CPosSubSession::NewLC(
        iModuleSettings, 
        iLocMonitorReqHandlerHub,
        aId,
        aIsProxy,
        &iModulesStatus,
        &iModulesStatus);

    TInt subSessionHandle = iSubSessionRegistry->AddInstanceL(subSession);
    CleanupStack::Pop(subSession); // Now owned by registry
    
    // Set the client subsession identifier.
    TPckg<TInt> handlePackage(subSessionHandle);
    TInt err = Global::Write(aMessage, KParamSubsession, handlePackage);
    if (err)
        {
        iSubSessionRegistry->CloseSubSession(subSessionHandle);
        User::Leave(err);
        }
    DEBUG_TRACE("Subsession created successfully", __LINE__)
	}