int run_main (int argc, ACE_TCHAR *argv[]) { ACE_START_TEST (ACE_TEXT ("TP_Reactor_Test")); #if defined(ACE_HAS_THREADS) if (::parse_args (argc, argv) == -1) return -1; ::disable_signal (SIGPIPE, SIGPIPE); MyTask task1; Acceptor acceptor; Connector connector; if (task1.start (threads) == 0) { int rc = 0; ACE_INET_Addr addr (port); if (both != 0 || host == 0) // Acceptor rc += acceptor.start (addr); if (both != 0 || host != 0) { if (host == 0) host = ACE_LOCALHOST; if (addr.set (port, host, 1, addr.get_type ()) == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), host)); rc += connector.start (addr, senders); } if (rc > 0) ACE_OS::sleep (seconds); } task1.stop (); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\nNumber of Receivers objects = %d\n") ACE_TEXT ("\nNumber of Sender objects = %d\n"), acceptor.get_number_sessions (), connector.get_number_sessions ())); // As Reactor event loop now is inactive it is safe to destroy all // senders connector.stop (); acceptor.stop (); //Print statistic ACE_TCHAR bufs [256]; ACE_TCHAR bufr [256]; ACE_OS::sprintf ( bufs , ACE_TEXT ("%ld(%ld)"), connector.get_total_snd(), connector.get_total_w() ); ACE_OS::sprintf ( bufr , ACE_TEXT ("%ld(%ld)"), connector.get_total_rcv(), connector.get_total_r() ); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Connector/Senders total bytes: snd=%s rcv=%s\n"), bufs, bufr )); ACE_OS::sprintf ( bufs , ACE_TEXT ("%ld(%ld)"), acceptor.get_total_snd(), acceptor.get_total_w() ); ACE_OS::sprintf ( bufr , ACE_TEXT ("%ld(%ld)"), acceptor.get_total_rcv(), acceptor.get_total_r() ); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Acceptor/Receivers total bytes: snd=%s rcv=%s\n"), bufs, bufr )); #else /* ACE_HAS_THREADS */ ACE_UNUSED_ARG( argc ); ACE_UNUSED_ARG( argv ); #endif /* ACE_HAS_THREADS */ ACE_END_TEST; return 0; }
// ************************************************************* // Configuration helpers // ************************************************************* int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { ACE_START_TEST (ACE_TEXT ("PSSL_Test")); if (cfg.parse_args (argc, argv) < 0) return -1; disable_signal (ACE_SIGRTMIN, ACE_SIGRTMAX); disable_signal (SIGPIPE, SIGPIPE); disable_signal (SIGIO, SIGIO); //ACE_DEBUG ((LM_DEBUG, // ACE_TEXT ("FD_SETSIZE=%d ACE_FDSETSIZE=%d\n"), // FD_SETSIZE, // ACE_FD_SETSIZE)); ACE_DEBUG ((LM_DEBUG, "s_blksize=%u r_blksize=%u win_size=%u\n", cfg.s_blksize(), cfg.r_blksize(), cfg.w_size())); ACE_SSL_Context *context = ACE_SSL_Context::instance (); // Note - the next two strings are naked on purpose... the arguments to // the ACE_SSL_Context methods are const char *, not ACE_TCHAR *. context->certificate ("dummy.pem", SSL_FILETYPE_PEM); context->private_key ("key.pem", SSL_FILETYPE_PEM); { int rc = 0; ProactorTask task1(cfg); RecvFactory r_factory; SendFactory s_factory; PSessionManager r_manager (task1, r_factory,"R_Manager"); PSessionManager s_manager (task1, s_factory,"S_Manager"); Acceptor acceptor (r_manager); Connector connector (s_manager); ACE_Time_Value time_begin = ACE_OS::gettimeofday (); ACE_Time_Value time_end = ACE_OS::gettimeofday (); ACE_Time_Value time_run; if (task1.start () == 0) { ACE_Time_Value timeout (cfg.timeout(), 0); r_manager.set_timeout (timeout); s_manager.set_timeout (timeout); if (cfg.both() != 0 || cfg.connections () == 0) // Acceptor { // Simplify, initial read with zero size if (acceptor.start (ACE_INET_Addr (cfg.listen_port())) == 0) rc = 1; } if (cfg.both() != 0 || cfg.connections () > 0) // Connector { ACE_INET_Addr addr; addr.set (cfg.connect_port(), cfg.connect_host()); rc += connector.start (addr, cfg.connections ()); } time_begin = ACE_OS::gettimeofday (); if (rc > 0) { task1.enable_event_loop(); ACE_Time_Value sleep_time (cfg.seconds()); while ( sleep_time != ACE_Time_Value::zero) { ACE_Countdown_Time countdown ( & sleep_time ); ACE_OS::sleep (sleep_time ); } if (cfg.seconds () == 0) { // comment this later char c; cout << "Press any key to stop=>" << flush; cin.clear (); cin >> c; } }
// ************************************************************* // Configuration helpers // ************************************************************* int run (int argc, ACE_TCHAR *argv[]) { int rc = 0; ProactorTask task1(cfg); RecvFactory r_factory; SendFactory s_factory; PSessionManager r_manager (task1, r_factory,"R_Manager"); PSessionManager s_manager (task1, s_factory,"S_Manager"); Acceptor acceptor (r_manager); Connector connector (s_manager); ACE_Time_Value time_begin = ACE_OS::gettimeofday (); ACE_Time_Value time_end = ACE_OS::gettimeofday (); ACE_Time_Value time_run; if (task1.start () == 0) { task1.enable_event_loop(); ACE_Time_Value timeout (cfg.timeout(), 0); r_manager.set_timeout (timeout); s_manager.set_timeout (timeout); if (cfg.both() != 0 || cfg.connections () == 0) // Acceptor { if (acceptor.start (ACE_INET_Addr (cfg.listen_port())) == 0) rc = 1; } if (cfg.both() != 0 || cfg.connections () > 0) // Connector { ACE_INET_Addr addr; addr.set (cfg.connect_port(), cfg.connect_host()); rc += connector.start (addr, cfg.connections ()); } } time_begin = ACE_OS::gettimeofday (); if (rc > 0) { //task1.enable_event_loop(); ACE_Time_Value sleep_time (cfg.seconds()); while ( sleep_time != ACE_Time_Value::zero) { ACE_Countdown_Time countdown ( & sleep_time ); ACE_OS::sleep (sleep_time ); } if (cfg.seconds () == 0) { bool flgExit = false; for (;!flgExit;) { char c; cout << "\nPress Q to stop=>" << flush; cin.clear (); cin >> c; switch (toupper (c)) { case 'Q': flgExit = true; break; case 'P': cout << "\n*** Connector: PendingConnects=" << connector.get_ref_cnt() << " Senders=" << s_manager.get_number_connections () << "\n*** Acceptor: PendingAccepts=" << acceptor.get_ref_cnt() << " Receivers=" << r_manager.get_number_connections (); break; }//switch }//for }//if cfg.seconds
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { ACE_START_TEST (ACE_TEXT ("W_Test")); if (cfg.parse_args (argc, argv) < 0) return -1; disable_signal (ACE_SIGRTMIN, ACE_SIGRTMAX); disable_signal (SIGPIPE, SIGPIPE); disable_signal (SIGIO, SIGIO); //ACE_DEBUG ((LM_DEBUG, // ACE_TEXT ("FD_SETSIZE=%d ACE_FDSETSIZE=%d\n"), // FD_SETSIZE, // ACE_FD_SETSIZE)); ACE_DEBUG ((LM_DEBUG, "s_blksize=%u r_blksize=%u win_size=%u\n", cfg.s_blksize(), cfg.r_blksize(), cfg.w_size())); ACE_SSL_Context *context = ACE_SSL_Context::instance (); // Note - the next two strings are naked on purpose... the arguments to // the ACE_SSL_Context methods are const char *, not ACE_TCHAR *. context->certificate ("dummy.pem", SSL_FILETYPE_PEM); context->private_key ("key.pem", SSL_FILETYPE_PEM); { int rc = 0; ProactorTask task1(cfg); RecvFactory r_factory; RecvFactorySSL r_ssl_factory; PConnectionManager r_manager (task1, r_factory,"R_Manager"); PConnectionManager r_ssl_manager (task1, r_ssl_factory,"R_SSL_Manager"); Acceptor acceptor (r_manager); Acceptor acceptor_ssl (r_ssl_manager); ACE_Time_Value time_begin = ACE_OS::gettimeofday (); ACE_Time_Value time_end = ACE_OS::gettimeofday (); ACE_Time_Value time_run; if (task1.start () == 0) { ACE_Time_Value timeout (cfg.timeout(), 0); r_manager.set_timeout (timeout); // Simplify, initial read with zero size if (acceptor.start (ACE_INET_Addr (cfg.listen_port())) == 0) rc = 1; if (acceptor_ssl.start (ACE_INET_Addr (cfg.listen_port()+1)) == 0) rc = 1; time_begin = ACE_OS::gettimeofday (); if (rc > 0) { task1.enable_event_loop(); char c; cout << "Press any key to stop=>" << flush; cin.clear (); cin >> c; } }
// ************************************************************* // Configuration helpers // ************************************************************* int run (int argc, ACE_TCHAR *argv[]) { int rc = 0; ProactorTask task1(cfg); if (task1.start () != 0) { task1.stop (); return -1; } task1.enable_event_loop(); RecvFactory r_factory; SendFactory s_factory; PConnectionManager r_manager (task1, r_factory,"R_Manager"); PConnectionManager s_manager (task1, s_factory,"S_Manager"); Acceptor acceptor (r_manager); Connector connector (s_manager); ACE_Time_Value time_begin = ACE_OS::gettimeofday (); ACE_Time_Value time_end = ACE_OS::gettimeofday (); ACE_Time_Value time_run; ACE_Time_Value timeout (cfg.timeout(), 0); r_manager.set_timeout (timeout); s_manager.set_timeout (timeout); time_begin = ACE_OS::gettimeofday (); if (cfg.both() != 0 || cfg.connections () == 0) // Acceptor { // Simplify, initial read with zero size if (acceptor.start (ACE_INET_Addr (cfg.listen_port())) == 0) rc = 1; } if (cfg.both() != 0 || cfg.connections () > 0) // Connector { ACE_INET_Addr addr; addr.set (cfg.connect_port(), cfg.connect_host()); rc += connector.start (addr, cfg.connections ()); } if (rc > 0) { //task1.enable_event_loop(); ACE_Time_Value sleep_time (cfg.seconds()); while ( sleep_time != ACE_Time_Value::zero) { ACE_Countdown_Time countdown ( & sleep_time ); ACE_OS::sleep (sleep_time ); } if (cfg.seconds () == 0) { bool flgExit = false; for (;!flgExit;) { char c; cout << "\nEnter:" << "\n1 - stop connector" << "\n2 - stop acceptor" << "\n3 -stop senders" << "\n4 -stop receivers" << "\nP - statistic" << "\nQ quit=>" << flush; cin.clear (); cin >> c; switch (toupper (c)) { case '1': connector.cancel(); connector.wait (); break; case '2': acceptor.cancel (); acceptor.wait(); break; case '3': s_manager.cancel (); while (!s_manager.is_safe_to_delete ()) { task1.wait_signal (); } break; case '4': r_manager.cancel (); while (!r_manager.is_safe_to_delete ()) { task1.wait_signal (); } break; case 'Q': flgExit = true; break; case 'P': break; }//switch cout << "\n*** Connector: PendingConnects=" << connector.get_pending_count () << " Senders=" << s_manager.get_number_connections () << "\n*** Acceptor: PendingAccepts=" << acceptor.get_pending_count () << " Receivers=" << r_manager.get_number_connections (); }//for }//if cfg.seconds