コード例 #1
0
ファイル: NetMgr.cpp プロジェクト: aminsyed/rulib
BOOL CNetMgr::Cleanup()
{_STT();
	// Acquire lock
	CTlLocalLock ll( *this );
	if ( !ll.IsLocked() ) return FALSE;

	BOOL bChanged = FALSE;
	
	// Get the first object
	THList< GUID, CNetCom >::iterator it = NULL;
	while ( ( it = m_lstSession.next( it ) ) != NULL )
	{
		CNetCom* pNc = (*it);

		// Erase this session if invalid
		if ( !pNc || !pNc->IsValid() )
		{
			bChanged = TRUE;

			it = RemoveNode( it );

		} // end if

	} // end while

	return bChanged;
}
コード例 #2
0
ファイル: NetCmd.cpp プロジェクト: mvancompernolle/ai_project
BOOL CNetCmd::vMsg( const GUID *pNode, const GUID *pClass, DWORD dwFunction, CReg *pParams, DWORD dwBuffers, LPVOID *pArgs )
{_STT();
	// Verify we have authority to send this message
	if ( !OnTxAuthenticate( pNode, pClass, dwFunction ) )
		return FALSE;

	// Get destination
	CNetCom *pNc = GetNode( pNode );
	if ( pNc == NULL || !pNc->IsValid() ) 
		return FALSE;

	// Copy message data
	CNetMsg::SMsg msg;
	ZeroMemory( &msg, sizeof( msg ) );
	msg.dwFunction = dwFunction;
	
	// Encode params
	CPipe params;
	if ( pParams ) pParams->SaveRegFile( &params, NULL, "" );

	// Calculate the total size needed
	DWORD dwBlocks = 3; if ( params.GetBufferSize() ) dwBlocks++;
	DWORD dwTotalSize = ( sizeof( CNetMsg::SAddress ) * 2 ) +  
						sizeof( CNetMsg::SMsg ) +
						params.GetBufferSize();

	DWORD i;
	LPVOID *ptrExtra = pArgs;
	for ( i = 0; i < dwBuffers; i++ )
	{	RULIB_TRY 
		{	DWORD	dwType = *(LPDWORD)( ptrExtra );
			LPBYTE	pPtr = *(LPBYTE*)( ptrExtra + 1 );
			DWORD 	dwSize = *(LPDWORD)( ptrExtra + 2 );
			dwBlocks++;

			// Zero means NULL terminated
			if ( dwSize == 0 && pPtr != NULL ) dwSize = strlen( (LPCTSTR)pPtr );

			dwTotalSize += dwSize;

			ptrExtra += 3;
		} // end try
		RULIB_CATCH_ALL { return FALSE; }
	} // end for

	// Lock the tx buffer
	CTlLocalLock ll( *pNc->Tx() );
	if ( !ll.IsLocked() ) return FALSE;

	// Initialze the packet
	pNc->Tx()->InitPacket( NETMSG_PACKETTYPE, dwBlocks, dwTotalSize );

	CNetMsg::SAddress addr;

	// Destination information	
	memcpy( &addr.guidNode, pNc->Rx()->Address(), sizeof( GUID ) );
	if ( pClass ) memcpy( &addr.guidClass, pClass, sizeof( GUID ) );
	else ZeroMemory( &addr.guidClass, sizeof( addr.guidClass ) );
	pNc->Tx()->AddPacketData( NETMSGDT_DSTADDRESS, &addr, sizeof( addr ) );
	
	// Source information	
	memcpy( &addr.guidNode, pNc->Tx()->Address(), sizeof( GUID ) );
	ZeroMemory( &addr.guidClass, sizeof( addr.guidClass ) );
	pNc->Tx()->AddPacketData( NETMSGDT_SRCADDRESS, &addr, sizeof( addr ) );

	// Add message
	pNc->Tx()->AddPacketData( NETMSGDT_MSG, &msg, sizeof( msg ) );

	// Add params if any
	if ( params.GetBufferSize() )
		pNc->Tx()->AddPacketData( NETMSGDT_PARAMS, params.GetBuffer(), params.GetBufferSize() );

	// Add the data to the packet
	ptrExtra = pArgs;
	for ( i = 0; i < dwBuffers; i++ )
	{	RULIB_TRY 
		{	DWORD	dwType = *(LPDWORD)( ptrExtra );
			LPBYTE	pPtr = *(LPBYTE*)( ptrExtra + 1 );
			DWORD 	dwSize = *(LPDWORD)( ptrExtra + 2 );

			// Zero means NULL terminated
			if ( dwSize == 0 && pPtr != NULL ) dwSize = strlen( (LPCTSTR)pPtr );

			// Add packet data block
			pNc->Tx()->AddPacketData( dwType, pPtr, dwSize );

			ptrExtra += 3;
		} // end try
		RULIB_CATCH_ALL { return FALSE; }
	} // end for

	// Make it official
	return pNc->Tx()->EndPacket();
}