int CR_thread_stop( int blocking ) { PRINT_DEBUG( DEBUG_FT_verbose>1, "CR_thread_stop(blocking=%d) called\n", blocking); CR_state_transition( CR_STOPPED ); nspawns = 0; if (cr_tid) { if (blocking) { pthread_join(cr_tid, NULL); } cr_tid = 0; } #ifdef CR_FTB /* Nothing to be done */ #else clean_connections(); #endif return 0; }
int main( int argc, char* argv[] ) { try { indri::api::Parameters& parameters = indri::api::Parameters::instance(); parameters.loadCommandLine( argc, argv ); indri::net::NetworkListener listener; int port = parameters.get( "port", INDRID_PORT ); verbose = parameters.get( "verbose", false ); std::string repositoryPath = parameters["index"]; // wrap the index in a local server that the stub can talk to indri::collection::Repository* repository = new indri::collection::Repository(); // pass in parameters, in case anyone wants to do query side stopping. repository->openRead( repositoryPath, ¶meters ); indri::server::LocalQueryServer server( *repository ); // open for business listener.listen( port ); indri::net::NetworkStream* connection; std::list<connection_info*> connections; // this handles the threading issue by only allowing one // connection at a time; for our current uses this is fine while( connection = listener.accept() ) { connection_info* info = build_connection( connection, &server ); connections.push_back( info ); clean_connections( connections ); } wait_connections( connections ); repository->close(); delete repository; return 0; } catch( lemur::api::Exception& e ) { LEMUR_ABORT(e); } }
void wait_connections( std::list<connection_info*>& connections ) { while( connections.size() ) { clean_connections( connections ); indri::thread::Thread::yield(); } }