void ConnectionManager(ServerGame& aGame, Ogre::String aAddress, int32 aPort)
{
    LOG(INFO) << "Init SRP";

    boost::asio::ssl::context sslCtx(boost::asio::ssl::context::tlsv1_server);
    SSL_CTX* ctx = sslCtx.native_handle();

    SSL_CTX_set_info_callback(ctx, SSLInfoCallback);
    SSL_CTX_SRP_CTX_init(ctx);
    if (SSL_CTX_set_cipher_list(ctx, "SRP") != 1)
    {
        LOG(ERROR) << "Can not set SRP ciphers";
        return;
    }

    SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, NULL);
    SSL_CTX_set_srp_username_callback(ctx, SSLSRPServerParamCallback);

    AddUser("test", "test");

    LOG(INFO) << "Listening to " << aAddress << ":" << aPort;
    boost::asio::io_service IOService;
    boost::asio::ip::tcp::acceptor gate(IOService,
        boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), aPort));

    while (true)
    {
        SSLStreamPtr sslStream(new SSLStream(IOService, sslCtx));
        gate.accept(sslStream->lowest_layer());
        boost::thread thrd(boost::bind(ClientConnection, boost::ref(aGame), sslStream));
    }
}
int main(int argc, char* argv[])
{
  boost::thread thrd(&hello);
  
	count c1(1);
	count c2(2);
	count c3(3);
	count c4(4);
	c1.serial();
	c2.serial();
	c3.serial();
	c4.serial();
	/*
  boost::thread thrd1(count(1));
  boost::thread thrd2(count(2));
  boost::thread thrd3(count(3));
  boost::thread thrd4(count(4));
  
 
  thrd1.join();
  thrd2.join();
  thrd3.join();
  thrd4.join();

  */
  thrd.join();
  return 0;
}
Beispiel #3
0
void do_test_creation()
{
    test_value = 0;
    boost::thread thrd(&simple_thread);
    thrd.join();
    BOOST_CHECK_EQUAL(test_value, 999);
}
int main()
{
    factorial f(10);
    boost::thread thrd(boost::ref(f));
    thrd.join();
    std::cout << "10! = " << f.result() << std::endl;
}
Beispiel #5
0
int _tmain(int argc, _TCHAR* argv[])
{
	int param[3] = {1, 2, 0};
	
	thrd((void*)&param[2]);

	unsigned int thrdid = 0;

	SECURITY_ATTRIBUTES sa;
	sa.nLength = sizeof(sa);
	sa.bInheritHandle = FALSE;
	sa.lpSecurityDescriptor = 0;

	HANDLE hThread[2];
	printf("start thread %d\n", param[0]);
	hThread[0] = (HANDLE)_beginthreadex(&sa, 0, &thrd, (void*)&param[0], 0, &thrdid);
	if (hThread == 0){
		DWORD dwRet = GetLastError();
		printf("%d\n", dwRet);
	}
	Sleep(500);
	printf("start thread %d\n", param[1]);
	hThread[1] = (HANDLE)_beginthreadex(&sa, 0, &thrd, (void*)&param[1], 0, &thrdid);
	if (hThread == 0){
		DWORD dwRet = GetLastError();
		printf("%d\n", dwRet);
	}
	WaitForMultipleObjects(2, hThread, TRUE, INFINITE);
	CloseHandle(hThread[0]);
	CloseHandle(hThread[1]);
	
	return 0;
}
Beispiel #6
0
void PoolManagerFactory (int argc, char **argv) {

	boost::xtime xt, xt2;
	boost::xtime_get(&xt, boost::TIME_UTC);

	Caller   caller(s_callee);
	s_callee.start();
	caller.shout("Welcome to the management thread!");

//	try {
	PoolManager manager(nProducers, sizeN > nConsumers ? nConsumers : sizeN);

	boost::thread thrd(manager);
	thrd.join();
//  }
//	catch (boost::exception &ex){
//		caller.shout( diagnostic_information(ex) );
//	}
	s_callee.stop();

	boost::xtime_get(&xt2, boost::TIME_UTC);
	long time = boost::lexical_cast<long>((xt2.sec*1000000000 + xt2.nsec - xt.sec*1000000000 - xt.nsec) / 1000000);
	printf("%d producer, max %d consumers: %ld msec\n", nProducers, nConsumers, time);

}
void boost_thread(const bool leakage)
{
	boost::scoped_ptr<boost::thread> thrd(new boost::thread(local::thread_proc(leakage)));  // create thread

	{
		int *pi = new int [50];
		long *pl = new long [10];
		float *pf = new float [30];
		double *pd = new double [50];

		delete [] pi;
		pi = NULL;
		if (!leakage)
		{
			delete [] pl;
			pl = NULL;
			delete [] pf;
			pf = NULL;
			delete [] pd;
			pd = NULL;
		}
	}

	thrd->join();
}
Beispiel #8
0
int main(int argc, char* argv[])
{
    int secs = 5;
    std::cout << "setting alarm for 5 seconds..." << std::endl;
    thread_alarm alarm(secs);
    boost::thread thrd(alarm);
    thrd.join();
}
int main()
{
    int result;
    factorial f(10, result);
    boost::thread thrd(f);
    thrd.join();
    std::cout << "10! = " << result << std::endl;
}
void do_test_creation_through_reference_wrapper()
{
    non_copyable_functor f;
    
    boost::thread thrd(boost::ref(f));
    thrd.join();
    BOOST_CHECK_EQUAL(f.value, 999u);
}
Beispiel #11
0
thread* thread_group::create_thread(const function0<void>& threadfunc)
{
    // No scoped_lock required here since the only "shared data" that's
    // modified here occurs inside add_thread which does scoped_lock.
    std::auto_ptr<thread> thrd(new thread(threadfunc));
    add_thread(thrd.get());
    return thrd.release();
}
Beispiel #12
0
void MainWindow::createRayTraceThread()
{
	count++;
	int vres = 800;
	int hres = 800;
	world = new World();
	world->init(QtWindow,vres,hres);	
	boost::thread thrd(fastdelegate::MakeDelegate(world->camera,&Camera::renderScene),world);
}
Beispiel #13
0
void do_test_creation_with_attrs()
{
  test_value = 0;
  boost::thread_attributes attrs;
  attrs.set_stack_size(0x4000);
  boost::thread thrd(attrs, &simple_thread);
  thrd.join();
  BOOST_CHECK_EQUAL(test_value, 999);
}
Beispiel #14
0
void timed_test(F func, int secs,
    execution_monitor::wait_type type = execution_monitor::use_sleep_only)
{
    execution_monitor monitor(type, secs);
    indirect_adapter<F> ifunc(func, monitor);
    monitor.start();
    boost::thread thrd(ifunc);
    BOOST_REQUIRE(monitor.wait()); // Timed test didn't complete in time, possible deadlock
}
void do_test_thread_interrupts_at_interruption_point()
{
    boost::mutex m;
    bool failed=false;
    boost::mutex::scoped_lock lk(m);
    boost::thread thrd(boost::bind(&interruption_point_thread,&m,&failed));
    thrd.interrupt();
    lk.unlock();
    thrd.join();
    BOOST_CHECK(!failed);
}
void do_test_thread_no_interrupt_if_interrupts_disabled_at_interruption_point()
{
    boost::mutex m;
    bool failed=true;
    boost::unique_lock<boost::mutex> lk(m);
    boost::thread thrd(boost::bind(&disabled_interruption_point_thread,&m,&failed));
    thrd.interrupt();
    lk.unlock();
    thrd.join();
    BOOST_CHECK(!failed);
}
Beispiel #17
0
   // -----------------------------------------------------------------------
   SOAP_FMAC5 int SOAP_FMAC6 __shawnts__flashPrograms( soap*,
            shawnts__flashPrograms *shawnts__flashPrograms_,
            shawnts__flashProgramsResponse *shawnts__flashProgramsResponse_ )
   {
      if ( !experiment_control_available() )
         return SOAP_OK;

      int node_cnt = shawnts__flashPrograms_->__sizenodeIds;
      std::vector<std::string> nodes;
      for ( int i = 0; i < node_cnt; i++ )
      {
         nodes.push_back( std::string(shawnts__flashPrograms_->nodeIds[i]) );
      }

      int idx_cnt = shawnts__flashPrograms_->__sizeprogramIndices;
      std::vector<int> indices;
      for ( int i = 0; i < idx_cnt; i++ )
      {
         indices.push_back( shawnts__flashPrograms_->programIndices[i] );
      }

      int program_cnt = shawnts__flashPrograms_->__sizeprograms;
      std::vector<testbedservice::ExperimentControl::FlashProgram> programs;
      for ( int i = 0; i < program_cnt; i++ )
      {
         testbedservice::ExperimentControl::FlashProgram program;

         xsd__base64Binary *bin = &shawnts__flashPrograms_->programs[i]->program;
         program.data = new uint8_t[bin->__size];
         memcpy( program.data, bin->__ptr, bin->__size );
         program.data_len = bin->__size;

         shawnts__programMetaData *meta = shawnts__flashPrograms_->programs[i]->metaData;
         program.version = std::string( meta->version );
         program.name = std::string( meta->name );
         program.platform = std::string( meta->platform );
         program.other = std::string( meta->other );

         programs.push_back(program);
      }

      std::string id = testbedservice::create_response_id();
      char *response_id = testbedservice::allocate_string( shawnts__flashProgramsResponse_->soap, id );
      shawnts__flashProgramsResponse_->return_ = response_id;

      boost::thread thrd( boost::bind(
         &testbedservice::ExperimentControl::flash_programs,
         testbedservice::experiment_control_,
         id, nodes, indices, programs ) );

      return SOAP_OK;
   }
Beispiel #18
0
void  CMessagePushMgr::Start()
{
	m_bEnableRun = true;

	m_AsyncHttpClient_ptr.reset(new CAsyncHttpClient());
	m_AsyncHttpClient_ptr->init(30);

	m_JWTEncode_ptr.reset(new JWTEncode(m_config.AuthKey));
	
	thrdPush tl(this);
	boost::thread thrd(tl);

}
Beispiel #19
0
    void    start() {

        if (!stop_flag_)
            stop();

        stop_flag_  = false;
        start_sem_  = new boost::interprocess::interprocess_semaphore(0);
        stop_sem_   = new boost::interprocess::interprocess_semaphore(0);

        boost::function0<void> func = boost::bind(&RunnableImpl::run_core, this);
        boost::thread thrd(func);
        start_sem_->wait();
    }
Beispiel #20
0
 void operator()() const
 {
     try
     {
         boost::thread thrd(m_func);
         thrd.join();
     }
     catch (...)
     {
         m_monitor.finish();
         throw;
     }
     m_monitor.finish();
 }
Beispiel #21
0
	task< typename result_of< Fn() >::result_type >
    operator()( Fn fn)
	{
        typedef typename result_of< Fn() >::result_type  R;

		BOOST_ASSERT( ! this_task::runs_in_pool() );

        promise< R > prom;
        unique_future< R > f( prom.get_future() );
        context ctx1, ctx2;
        task< R > t( f, ctx1);
        callable ca( fn, boost::move( prom), ctx2);
        shared_ptr< thread > thrd( new thread( ca), detail::joiner() );
        ctx1.reset( thrd);
        return t;
	}
   // -----------------------------------------------------------------------
   // ------------- Web Service Calls Network Control -----------------------
   // -----------------------------------------------------------------------
   SOAP_FMAC5 int SOAP_FMAC6 __ns1__setVirtualLink( soap*,
            ns1__setVirtualLink *ns1__setVirtualLink_,
            ns1__setVirtualLinkResponse *ns1__setVirtualLinkResponse_ )
   {
      if ( !virtual_link_control_available() )
         return SOAP_OK;

      std::string source = std::string( ns1__setVirtualLink_->sourceNode );
      std::string destination = std::string( ns1__setVirtualLink_->targetNode );
      std::string remote_uri = std::string( ns1__setVirtualLink_->remoteServiceInstance );

      std::string id = testbedservice::create_response_id();
      char *response_id = testbedservice::allocate_string( ns1__setVirtualLinkResponse_->soap, id );
      ns1__setVirtualLinkResponse_->return_ = response_id;

      boost::thread thrd( boost::bind(
         &testbedservice::VirtualLinkControl::set_virtual_link,
         testbedservice::virtual_link_control_,
         id, source, destination, remote_uri ) );

      return SOAP_OK;
   }
   // -----------------------------------------------------------------------
   SOAP_FMAC5 int SOAP_FMAC6 __ns1__disablePhysicalLink( soap*,
            ns1__disablePhysicalLink *ns1__disablePhysicalLink_,
            ns1__disablePhysicalLinkResponse *ns1__disablePhysicalLinkResponse_)
   {
      if ( !virtual_link_control_available() )
         return SOAP_OK;

      std::string source = std::string( ns1__disablePhysicalLink_->nodeA );
      std::string destination = std::string( ns1__disablePhysicalLink_->nodeB );

      std::string id = testbedservice::create_response_id();
      char *response_id = testbedservice::allocate_string(
         ns1__disablePhysicalLinkResponse_->soap, id );
      ns1__disablePhysicalLinkResponse_->return_ = response_id;

      boost::thread thrd( boost::bind(
         &testbedservice::VirtualLinkControl::disable_physical_link,
         testbedservice::virtual_link_control_,
         id, source, destination ) );

      return SOAP_OK;
   }
void do_test_timed_join()
{
    long_running_thread f;
    boost::thread thrd(boost::ref(f));
    BOOST_CHECK(thrd.joinable());
    boost::system_time xt=delay(3);
    bool const joined=thrd.timed_join(xt);
    BOOST_CHECK(in_range(boost::get_xtime(xt), 2));
    BOOST_CHECK(!joined);
    BOOST_CHECK(thrd.joinable());
    {
        boost::mutex::scoped_lock lk(f.mut);
        f.done=true;
        f.cond.notify_one();
    }
    
    xt=delay(3);
    bool const joined2=thrd.timed_join(xt);
    boost::system_time const now=boost::get_system_time();
    BOOST_CHECK(xt>now);
    BOOST_CHECK(joined2);
    BOOST_CHECK(!thrd.joinable());
}
Beispiel #25
0
int HttpProxy::start()
{
    Owned<ISocket> socket1 = ISocket::create(m_localport);
    if(http_tracelevel > 0)
        printf("Proxy started\n");

    for (;;)
    {
        try
        {
            Owned<ISocket> client = socket1->accept();
            char peername[256];
            int port = client->peer_name(peername, 256);

            if(m_host.length() > 0)
            {
                COneServerHttpProxyThread thrd(client.get(), m_host.str(), m_port, m_ofile, m_use_ssl, m_ssctx, m_url_prefix);
                thrd.start();
            }
            else
            {
                Owned<CHttpProxyThread> thrd = new CHttpProxyThread(client.get(), m_ofile);
                thrd->start();
            }
        }
        catch(IException *excpt)
        {
            StringBuffer errMsg;
            DBGLOG("%s", excpt->errorMessage(errMsg).str());
        }
        catch(...)
        {
            DBGLOG("unknown exception");
        }
    }
    return 0;
}
Beispiel #26
0
void AsCInterFace::test_calledFunction( std::string input_string )
{
	boost::thread thrd(boost::bind(&AsCInterFace::ProcessThreadFunction, this, input_string));
	thrd.detach();
}
 void start()
 {
     boost::function0< void> f =  boost::bind(&HelloWorld::hello,this);
     boost::thread thrd( f );
     thrd.join();
 }
int main()
{
    boost::thread thrd(boost::bind(&helloworld, "Bob"));
    thrd.join();
}
Beispiel #29
0
int main()
{
    boost::thread thrd(&helloworld);
    thrd.join();
}
Beispiel #30
0
void do_test_comparison()
{
    boost::thread self;
    boost::thread thrd(bind(&comparison_thread, &self));
    thrd.join();
}