diff options
Diffstat (limited to 'tests/NonBlocking_Conn_Test.cpp')
-rw-r--r-- | tests/NonBlocking_Conn_Test.cpp | 144 |
1 files changed, 94 insertions, 50 deletions
diff --git a/tests/NonBlocking_Conn_Test.cpp b/tests/NonBlocking_Conn_Test.cpp index 80e25c63cfb..95db73ebc90 100644 --- a/tests/NonBlocking_Conn_Test.cpp +++ b/tests/NonBlocking_Conn_Test.cpp @@ -30,14 +30,22 @@ #include "ace/WFMO_Reactor.h" #include "ace/Get_Opt.h" -static int test_select_reactor = 1; -static int test_tp_reactor = 1; -static int test_wfmo_reactor = 1; +static bool test_select_reactor = true; +static bool test_tp_reactor = true; +static bool test_wfmo_reactor = true; +static int result = 0; -Svc_Handler::Svc_Handler (void) +Svc_Handler::Svc_Handler (bool is_ref_counted) : status_ (0), - completion_counter_ (0) + completion_counter_ (0), + is_ref_counted_ (is_ref_counted) { + if (this->is_ref_counted_) + { + // Enable reference counting on the event handler. + this->reference_counting_policy ().value ( + ACE_Event_Handler::Reference_Counting_Policy::ENABLED); + } } void @@ -51,30 +59,44 @@ Svc_Handler::connection_status (Connection_Status &status, int Svc_Handler::open (void *) { - *this->status_ = SUCCEEDED; + *this->status_ = Svc_Handler::Conn_SUCCEEDED; (*this->completion_counter_)++; + ACE_TCHAR buf[BUFSIZ]; + ACE_INET_Addr raddr; + this->peer ().get_remote_addr (raddr); + raddr.addr_to_string (buf, sizeof buf); + + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("Connection to %s is opened\n"), + buf)); + return 0; } int -Svc_Handler::handle_close (ACE_HANDLE handle, - ACE_Reactor_Mask mask) +Svc_Handler::handle_close (ACE_HANDLE handle, ACE_Reactor_Mask mask) { - *this->status_ = FAILED; + *this->status_ = Svc_Handler::Conn_FAILED; (*this->completion_counter_)++; - return ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH>::handle_close (handle, - mask); + // Only if there is no reference counting can call parent's + // handle_close() as it does plain 'delete this'. + if (!this->is_ref_counted_) + { + typedef ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> super; + + return super::handle_close (handle, mask); + } + + return 0; } -typedef ACE_Connector<Svc_Handler, - ACE_SOCK_CONNECTOR> - CONNECTOR; +typedef ACE_Connector<Svc_Handler, ACE_SOCK_CONNECTOR> CONNECTOR; static const char* hosts[] = { "www.russiantvguide.com:80", - "www.pakarmy.gov.pk:80", + "news.bbc.co.uk:80", "www.cnn.com:80", "www.waca.com.au:80", "www.uganda.co.ug:80", @@ -82,15 +104,17 @@ static const char* hosts[] = { "www.dre.vanderbilt.edu:80", "www.dhm.gov.np:80", "www.msn.com:80", - "www.presidencymaldives.gov.mv:80" }; + "www.presidencymaldives.gov.mv:80" +}; static int number_of_connections = 0; +static bool with_ref_counting = false; void test_connect (ACE_Reactor &reactor, ACE_INET_Addr *addresses, ACE_Synch_Options &synch_options, - int complete_nonblocking_connections) + Svc_Handler::Completion_Status complete_nonblocking_connections) { CONNECTOR connector (&reactor); @@ -106,7 +130,7 @@ test_connect (ACE_Reactor &reactor, for (i = 0; i < number_of_connections; ++i) { svc_handlers[i] = - new Svc_Handler; + new Svc_Handler (with_ref_counting); svc_handlers[i]->connection_status (connection_status[i], completion_counter); @@ -121,7 +145,7 @@ test_connect (ACE_Reactor &reactor, if (!synch_options[ACE_Synch_Options::USE_REACTOR]) ACE_ASSERT (completion_counter == number_of_connections); - if (complete_nonblocking_connections) + if (complete_nonblocking_connections != Svc_Handler::Comp_NO) { while (completion_counter != number_of_connections) { @@ -139,12 +163,18 @@ test_connect (ACE_Reactor &reactor, 1); ACE_DEBUG ((LM_DEBUG, - "Connection to %s %s\n", + ACE_TEXT ("Connection to %s %s\n"), buffer, - connection_status[i] == Svc_Handler::SUCCEEDED ? - "succeeded" : "failed")); + connection_status[i] == Svc_Handler::Conn_SUCCEEDED ? + ACE_TEXT("succeeded") : ACE_TEXT("failed"))); - if (connection_status[i] == Svc_Handler::SUCCEEDED) + ACE_Event_Handler_var release_guard; + if (with_ref_counting) + { + release_guard.reset (svc_handlers[i]); + } + + if (connection_status[i] == Svc_Handler::Conn_SUCCEEDED) { svc_handlers[i]->close (); } @@ -157,11 +187,11 @@ test_connect (ACE_Reactor &reactor, void test (ACE_Reactor_Impl *impl) { - size_t nr_names = sizeof hosts / sizeof (char *); - ACE_INET_Addr *addresses = - new ACE_INET_Addr[nr_names]; + size_t const nr_names = sizeof hosts / sizeof (char *); + ACE_INET_Addr *addresses = new ACE_INET_Addr[nr_names]; + number_of_connections = 0; - for (size_t i = 0, number_of_connections = 0; i < nr_names; ++i) + for (size_t i = 0; i < nr_names; ++i) { if (addresses[number_of_connections].set (hosts[i]) == 0) ++number_of_connections; @@ -171,65 +201,60 @@ test (ACE_Reactor_Impl *impl) ACE_TEXT_CHAR_TO_TCHAR (hosts[i]))); } - ACE_Reactor reactor (impl, - 1); - - int complete_nonblocking_connections = 1; - int dont_wait_for_nonblocking_connections = 0; - int ignored = 99; + ACE_Reactor reactor (impl, 1); ACE_Synch_Options blocking_connect = ACE_Synch_Options::defaults; ACE_DEBUG ((LM_DEBUG, - "\nBlocking connections...\n\n")); + "Blocking connections...\n")); test_connect (reactor, addresses, blocking_connect, - ignored); + Svc_Handler::Comp_IGNORE); blocking_connect.set (ACE_Synch_Options::USE_TIMEOUT, ACE_Time_Value (0, 50 * 1000)); ACE_DEBUG ((LM_DEBUG, - "\nBlocking connections (with timeouts)...\n\n")); + "Blocking connections (with timeouts)...\n")); test_connect (reactor, addresses, blocking_connect, - ignored); + Svc_Handler::Comp_IGNORE); ACE_Synch_Options nonblocking_connect (ACE_Synch_Options::USE_REACTOR); ACE_DEBUG ((LM_DEBUG, - "\nNon-blocking connections...\n\n")); + "Non-blocking connections...\n")); test_connect (reactor, addresses, nonblocking_connect, - complete_nonblocking_connections); + Svc_Handler::Comp_YES); ACE_DEBUG ((LM_DEBUG, - "\nNon-blocking connections (without waiting for completions)...\n\n")); + "Non-blocking connections (without waiting for completions)...\n")); test_connect (reactor, addresses, nonblocking_connect, - dont_wait_for_nonblocking_connections); + Svc_Handler::Comp_NO); nonblocking_connect.set (ACE_Synch_Options::USE_REACTOR | ACE_Synch_Options::USE_TIMEOUT, ACE_Time_Value (0, 500 * 1000)); ACE_DEBUG ((LM_DEBUG, - "\nNon-blocking connections (with timeouts)...\n\n")); + "Non-blocking connections (with timeouts)...\n")); test_connect (reactor, addresses, nonblocking_connect, - complete_nonblocking_connections); + Svc_Handler::Comp_YES); delete[] addresses; } @@ -279,24 +304,37 @@ run_main (int argc, ACE_TCHAR *argv[]) ACE_START_TEST (ACE_TEXT ("NonBlocking_Conn_Test")); // Validate options. - int result = - parse_args (argc, argv); + result = parse_args (argc, argv); if (result != 0) return result; if (test_select_reactor) { ACE_DEBUG ((LM_DEBUG, - "\n\nTesting Select Reactor....\n\n")); + "Testing Select Reactor....\n")); + with_ref_counting = false; + test (new ACE_Select_Reactor); + + ACE_DEBUG ((LM_DEBUG, + "Testing Select Reactor (ref counted)....\n")); + + with_ref_counting = true; test (new ACE_Select_Reactor); } if (test_tp_reactor) { ACE_DEBUG ((LM_DEBUG, - "\n\nTesting TP Reactor....\n\n")); + "Testing TP Reactor....\n")); + + with_ref_counting = false; + test (new ACE_TP_Reactor); + + ACE_DEBUG ((LM_DEBUG, + "Testing TP Reactor (ref counted)....\n")); + with_ref_counting = true; test (new ACE_TP_Reactor); } @@ -305,8 +343,15 @@ run_main (int argc, ACE_TCHAR *argv[]) if (test_wfmo_reactor) { ACE_DEBUG ((LM_DEBUG, - "\n\nTesting WFMO Reactor....\n\n")); + "Testing WFMO Reactor....\n")); + with_ref_counting = false; + test (new ACE_WFMO_Reactor); + + ACE_DEBUG ((LM_DEBUG, + "Testing WFMO Reactor (ref counted)....\n")); + + with_ref_counting = true; test (new ACE_WFMO_Reactor); } @@ -314,6 +359,5 @@ run_main (int argc, ACE_TCHAR *argv[]) ACE_END_TEST; - return 0; + return result; } - |