Esempio n. 1
0
int main() {
    ctx::execution_context< void > ctx1( f1);
    ctx1 = ctx1();
    std::cout << "f1: returned first time" << std::endl;
    ctx1 = ctx1();
    std::cout << "f1: returned second time" << std::endl;

    std::cout << "main: done" << std::endl;

    return EXIT_SUCCESS;
}
Esempio n. 2
0
int main() {
    int data = 1;
    ctx::execution_context< int > ctx1( f1);
    std::tie( ctx1, data) = ctx1( data + 2);
    std::cout << "f1: returned first time: " << data << std::endl;
    std::tie( ctx1, data) = ctx1( data + 2);
    std::cout << "f1: returned second time: " << data << std::endl;

    std::cout << "main: done" << std::endl;

    return EXIT_SUCCESS;
}
Esempio n. 3
0
void test_move() {
    value1 = 0;
    ctx::captured_context ctx;
    BOOST_CHECK( ! ctx);
    ctx::captured_context ctx1( fn1, 1);
    ctx::captured_context ctx2( fn1, 3);
    BOOST_CHECK( ctx1);
    BOOST_CHECK( ctx2);
    ctx1 = std::move( ctx2);
    BOOST_CHECK( ctx1);
    BOOST_CHECK( ! ctx2);
    BOOST_CHECK_EQUAL( 0, value1);
    ctx1();
    BOOST_CHECK_EQUAL( 3, value1);
}
Esempio n. 4
0
int main( int argc, char * argv[])
{
    {
        ctx2 = boost::contexts::context(
            fn2, 
            boost::contexts::default_stacksize(),
			boost::contexts::no_stack_unwind, boost::contexts::return_to_caller);
        boost::contexts::context ctx1(
            fn1, 
            boost::contexts::default_stacksize(),
			boost::contexts::no_stack_unwind,
            ctx2);

        ctx1.start();
    }

    std::cout << "main(): ctx1 is destructed\n";

    std::cout << "main(): resume ctx2\n";
    ctx2.resume();

    std::cout << "Done" << std::endl;

    return EXIT_SUCCESS;
}
Esempio n. 5
0
void test_case_6()
{
    value1 = 0;
    value2 = "";
    value3 = "";
    BOOST_CHECK_EQUAL( 0, value1);
    BOOST_CHECK_EQUAL( std::string(""), value2);
    BOOST_CHECK_EQUAL( std::string(""), value3);

    boost::contexts::context ctx1(
        fn4, "abc", "xyz",
        boost::contexts::default_stacksize(),
        boost::contexts::stack_unwind,
		boost::contexts::return_to_caller);
    boost::contexts::context ctx2(
        fn1, 7,
        boost::contexts::default_stacksize(),
        boost::contexts::stack_unwind,
		ctx1);

    BOOST_CHECK( ! ctx1.is_complete() );
    BOOST_CHECK( ! ctx2.is_complete() );
    ctx2.start();
    BOOST_CHECK( ctx1.is_complete() );
    BOOST_CHECK( ctx2.is_complete() );
  
    BOOST_CHECK_EQUAL( 7, value1);
    BOOST_CHECK_EQUAL( "abc", value2);
    BOOST_CHECK_EQUAL( "xyz", value3);
}
Esempio n. 6
0
  static void test_base()
  {
    try
    {
      std::size_t echo_num = 10;

      gce::log::asio_logger lg;
      attributes attrs;
      attrs.lg_ = boost::bind(&gce::log::asio_logger::output, &lg, _arg1, "");
      
      attrs.id_ = atom("router");
      context ctx(attrs);
      attrs.id_ = atom("one");
      context ctx1(attrs);
      attrs.id_ = atom("two");
      context ctx2(attrs);
      
      threaded_actor base = spawn(ctx);
      threaded_actor base1 = spawn(ctx1);
      threaded_actor base2 = spawn(ctx2);
      
      netopt_t opt = make_netopt();
      opt.is_router = 1;
      gce::bind(base, "tcp://127.0.0.1:14923", remote_func_list_t(), opt);

      spawn(base1, "test_lua_actor/services.lua", monitored);
      spawn(base2, "test_lua_actor/services.lua", monitored);

      opt.reconn_period = seconds(1);
      connect(base1, "router", "tcp://127.0.0.1:14923", opt);
      connect(base2, "router", "tcp://127.0.0.1:14923", opt);
      base2.sleep_for(millisecs(200));

      for (std::size_t i=0; i<echo_num; ++i)
      {
        base1->send("echo_svc", "echo");
        base1->recv("echo");
      }

      base1->send(make_svcid("one", "echo_svc"), "end");
      base1->send(make_svcid("two", "echo_svc"), "end");

      base1->recv(exit);
      base2->recv(exit);
    }
    catch (std::exception& ex)
    {
      std::cerr << ex.what() << std::endl;
    }
  }
Esempio n. 7
0
  static void test_base()
  {
    try
    {
      std::size_t echo_num = 100;

      attributes attrs;
      attrs.id_ = atom("one");
      context ctx1(attrs);
      attrs.id_ = atom("two");
      context ctx2(attrs);

      mixin_t base1 = spawn(ctx1);
      mixin_t base2 = spawn(ctx2);

      gce::bind(base2, "tcp://127.0.0.1:14923");

      aid_t echo_aid =
        spawn(
          base2,
          boost::bind(
            &socket_ut::echo, _1
            ),
          monitored
          );

      wait(base1, boost::chrono::milliseconds(100));
      net_option opt;
      opt.reconn_period_ = seconds_t(1);
      connect(base1, atom("two"), "tcp://127.0.0.1:14923", false, opt);

      for (std::size_t i=0; i<echo_num; ++i)
      {
        send(base1, echo_aid, atom("echo"));
        recv(base1, atom("echo"));
      }
      send(base1, echo_aid, atom("end"));

      recv(base2);
    }
    catch (std::exception& ex)
    {
      std::cerr << "test_base except: " << ex.what() << std::endl;
    }
  }
Esempio n. 8
0
int
main(int argc, char *argv[])
{  
    std::cout << "SSLDemo  Copyright (C) 2015,  W. B. Yates" << std::endl;
    std::cout << "This program comes with ABSOLUTELY NO WARRANTY; for details see http://www.gnu.org/licenses/." << std::endl;
    std::cout << "This is free software, and you are welcome to redistribute it" << std::endl;
    std::cout << "under certain conditions; see http://www.gnu.org/licenses/" << std::endl;
    
    SSLContext ctx1("client", "client.pem", "password");
    SSLContext ctx2("server", "server.pem", "password", true);
    
    SSLSocket::registerContext( &ctx1 );
    SSLSocket::registerContext( &ctx2 );
    
    SSLSocket client;
    client.setContext("client");
    
    SSLSocket server("server");
    
    //Socket client;
    //Socket server;
    

    for (int i = 0; i < 5; ++i)
    {
        std::cout << "\nBegin socket test " << i + 1 <<  std::endl;
        std::thread thread1 = std::thread(rec,&server);
        std::thread thread2;
        
        if (i == 0)
            thread2 = std::thread(sender1,&client);
        else thread2 = std::thread(sender2,&client);
        thread1.join();
        thread2.join();
    }

    SSLSocket::clearRegister();
    std::cout << "End socket test" <<  std::endl;
    return 0;
}
Esempio n. 9
0
int main() {
    ctx::execution_context< void > ctx1( f1);
    ctx1 = ctx1();
    std::cout << "main: done" << std::endl;
    return EXIT_SUCCESS;
}
Esempio n. 10
0
ctx::captured_context fn4( ctx::captured_context ctx, void * ignored) {
    ctx::captured_context ctx1( fn5);
    ctx1();
    value3 = 3.14;
    return ctx;
}