Skip to content
Snippets Groups Projects
crawler.cpp 1.06 KiB
Newer Older
  • Learn to ignore specific revisions
  • benbergk's avatar
    benbergk committed
    //
    // Created by Ben Bergkamp on 1/31/18.
    //
    
    #include "crawler.h"
    
    
    /*
     *
     * @parms number of spiders
     * Creates a number of spiders and starts new threads for them
     *
     */
    
    
    
    jsclose's avatar
    jsclose committed
    void Crawler::SpawnSpiders ( size_t num_spiders )
    
    jsclose's avatar
    jsclose committed
    	{
    	for ( size_t i = 0; i < num_spiders; i++ )
    		{
    
    jsclose's avatar
    jsclose committed
    		Spider *temp = new Spider( this->mode, this->urlFrontier, this->IndexerQueue );
    
    jsclose's avatar
    jsclose committed
    		temp->StartThread( );
    		this->spiders.push_back( temp );
    		}
    
    jsclose's avatar
    jsclose committed
    	}
    
    /*
     *
     *Function to wait for all of the threads to finish running
     *
     */
    
    vcday's avatar
    vcday committed
    void Crawler::WaitOnAllSpiders ( )
    
    jsclose's avatar
    jsclose committed
    	{
    
    	cout << "Waiting for spiders to finish...\n";
    
    jsclose's avatar
    jsclose committed
    	for ( Spider *spider : spiders )
    		{
    
    vcday's avatar
    vcday committed
    		spider->WaitForFinish( );
    
    vcday's avatar
    vcday committed
    		delete spider; //FIXME do this in destructor?
    
    	 */
    
    		while( ! spiders.empty( ) )
    			{
    			Spider *spider = spiders.back();
    			spiders.pop_back();
    
    
    			spider->WaitForFinish();
    			spider = 0;
    			delete spider;
    			}
    
    		}
    
    vcday's avatar
    vcday committed
    void Crawler::KillAllSpiders ( )
    
    	//cout << "Waiting for spiders to finish...\n";
    
    		spider->kill( );
    		//delete spider; //FIXME do this in destructor?