Ejemplo n.º 1
0
// CheckWaitingJobs
//------------------------------------------------------------------------------
void Server::CheckWaitingJobs( const ToolManifest * manifest )
{
    // queue for start any jobs that may now be ready
#ifdef ASSERTS_ENABLED
    bool atLeastOneJobStarted = false;
#endif

    MutexHolder mhC( m_ClientListMutex );
    const ClientState * const * end = m_ClientList.End();
    for ( ClientState ** it = m_ClientList.Begin(); it!=end; ++it )
    {
        // For each connected client...
        ClientState * cs = *it;
        MutexHolder mh2( cs->m_Mutex );

        // .. check all jobs waiting for ToolManifests
        int32_t numJobs = (int32_t)cs->m_WaitingJobs.GetSize();
        for ( int32_t i=( numJobs -1 ); i >= 0; --i )
        {
            Job * job = cs->m_WaitingJobs[ i ];
            ToolManifest * manifestForThisJob = job->GetToolManifest();
            ASSERT( manifestForThisJob );
            if ( manifestForThisJob == manifest )
            {
                cs->m_WaitingJobs.EraseIndex( i );
                JobQueueRemote::Get().QueueJob( job );
                PROTOCOL_DEBUG( "Server: Job %x can now be started\n", job );
#ifdef ASSERTS_ENABLED
                atLeastOneJobStarted = true;
#endif
            }
        }
    }

    // We should only have called this function when a ToolChain sync was complete
    // so at least 1 job should have been waiting for it
    ASSERT( atLeastOneJobStarted );
}
Ejemplo n.º 2
0
// OnReceive
//------------------------------------------------------------------------------
/*virtual*/ void Server::OnReceive( const ConnectionInfo * connection, void * data, uint32_t size, bool & keepMemory )
{
    keepMemory = true; // we'll take care of freeing the memory

    ClientState * cs = (ClientState *)connection->GetUserData();
    ASSERT( cs );

    // are we expecting a msg, or the payload for a msg?
    void * payload = nullptr;
    size_t payloadSize = 0;
    if ( cs->m_CurrentMessage == nullptr )
    {
        // message
        cs->m_CurrentMessage = reinterpret_cast< const Protocol::IMessage * >( data );
        if ( cs->m_CurrentMessage->HasPayload() )
        {
            return;
        }
    }
    else
    {
        // payload
        ASSERT( cs->m_CurrentMessage->HasPayload() );
        payload = data;
        payloadSize = size;
    }


    // determine message type
    const Protocol::IMessage * imsg = cs->m_CurrentMessage;
    Protocol::MessageType messageType = imsg->GetType();

    PROTOCOL_DEBUG( "Client -> Server : %u (%s)\n", messageType, GetProtocolMessageDebugName( messageType ) );

    switch ( messageType )
    {
    case Protocol::MSG_CONNECTION:
    {
        const Protocol::MsgConnection * msg = static_cast< const Protocol::MsgConnection * >( imsg );
        Process( connection, msg );
        break;
    }
    case Protocol::MSG_STATUS:
    {
        const Protocol::MsgStatus * msg = static_cast< const Protocol::MsgStatus * >( imsg );
        Process( connection, msg );
        break;
    }
    case Protocol::MSG_NO_JOB_AVAILABLE:
    {
        const Protocol::MsgNoJobAvailable * msg = static_cast< const Protocol::MsgNoJobAvailable * >( imsg );
        Process( connection, msg );
        break;
    }
    case Protocol::MSG_JOB:
    {
        const Protocol::MsgJob * msg = static_cast< const Protocol::MsgJob * >( imsg );
        Process( connection, msg, payload, payloadSize );
        break;
    }
    case Protocol::MSG_MANIFEST:
    {
        const Protocol::MsgManifest * msg = static_cast< const Protocol::MsgManifest * >( imsg );
        Process( connection, msg, payload, payloadSize );
        break;
    }
    case Protocol::MSG_FILE:
    {
        const Protocol::MsgFile * msg = static_cast< const Protocol::MsgFile * >( imsg );
        Process( connection, msg, payload, payloadSize );
        break;
    }
    default:
    {
        // unknown message type
        ASSERT( false ); // this indicates a protocol bug
        Disconnect( connection );
        break;
    }
    }

    // free everything
    FREE( (void *)( cs->m_CurrentMessage ) );
    FREE( payload );
    cs->m_CurrentMessage = nullptr;
}
Ejemplo n.º 3
0
// OnReceive
//------------------------------------------------------------------------------
/*virtual*/ void Client::OnReceive( const ConnectionInfo * connection, void * data, uint32_t size, bool & keepMemory )
{
	keepMemory = true; // we'll take care of freeing the memory

	MutexHolder mh( m_ServerListMutex );

	ServerState * ss = (ServerState *)connection->GetUserData();
	ASSERT( ss );

	// are we expecting a msg, or the payload for a msg?
	void * payload = nullptr;
	size_t payloadSize = 0;
	if ( ss->m_CurrentMessage == nullptr )
	{
		// message
		ss->m_CurrentMessage = reinterpret_cast< const Protocol::IMessage * >( data );
		if ( ss->m_CurrentMessage->HasPayload() )
		{
			return;
		}
	}
	else
	{
		// payload
		ASSERT( ss->m_CurrentMessage->HasPayload() );
		payload = data;
		payloadSize = size;
	}

	// determine message type
	const Protocol::IMessage * imsg = ss->m_CurrentMessage;
	Protocol::MessageType messageType = imsg->GetType();

	PROTOCOL_DEBUG( "Server -> Client : %u (%s)\n", messageType, GetProtocolMessageDebugName( messageType ) );

	switch ( messageType )
	{
		case Protocol::MSG_REQUEST_JOB:
		{
			const Protocol::MsgRequestJob * msg = static_cast< const Protocol::MsgRequestJob * >( imsg );
			Process( connection, msg ); 
			break;
		}
		case Protocol::MSG_JOB_RESULT:
		{
			const Protocol::MsgJobResult * msg = static_cast< const Protocol::MsgJobResult * >( imsg );
			Process( connection, msg, payload, payloadSize ); 
			break;
		}
		case Protocol::MSG_REQUEST_MANIFEST:
		{
			const Protocol::MsgRequestManifest * msg = static_cast< const Protocol::MsgRequestManifest * >( imsg );
			Process( connection, msg ); 
			break;
		}
		case Protocol::MSG_REQUEST_FILE:
		{
			const Protocol::MsgRequestFile * msg = static_cast< const Protocol::MsgRequestFile * >( imsg );
			Process( connection, msg ); 
			break;
		}
		case Protocol::MSG_SERVER_STATUS:
		{
			const Protocol::MsgServerStatus * msg = static_cast< const Protocol::MsgServerStatus * >( imsg );
			Process( connection, msg ); 
			break;
		}
		default:
		{
			// unknown message type
			ASSERT( false ); // this indicates a protocol bug
			Disconnect( connection );
			break;
		}
	}

	// free everything
	FREE( (void *)( ss->m_CurrentMessage ) );
	FREE( payload );
	ss->m_CurrentMessage = nullptr;
}