summaryrefslogtreecommitdiff
path: root/ACE/tests/NonBlocking_Conn_Test.cpp
diff options
context:
space:
mode:
authorvzykov <vzykov@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2010-03-17 12:21:14 +0000
committervzykov <vzykov@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2010-03-17 12:21:14 +0000
commit3a7b3e4e0a4739c1326e04498fcc0c91faa885bf (patch)
tree008ce4e7b7ac719e57dce5f90c151c784b974155 /ACE/tests/NonBlocking_Conn_Test.cpp
parent3f8b10924ec2dd86b94a260a6031723263471d13 (diff)
downloadATCD-3a7b3e4e0a4739c1326e04498fcc0c91faa885bf.tar.gz
Wed Mar 17 11:58:10 UTC 2010 Vladimir Zykov <vladimir.zykov@prismtech.com>
Committed the changes that I had to revert before x.7.7. * ace/Strategies_T.cpp: Changed the code so that close() is called in case of failure instead of destroy(). * ace/Connector.cpp: * ace/Connector.h: Changed the fix for bug#3731. Now NBCH adds a reference in constructor and removes it in destructor if the SVC_HANDLER that it owns is reference counted. This is a cleaner solution than the one used before. * tests/NonBlocking_Conn_Test.h: * tests/Process_Strategy_Test.cpp: * tests/NonBlocking_Conn_Test.cpp: Extended NonBlocking_Conn_Test and changed Process_Strategy_Test because of the change in Strategies_T.cpp. * tests/MT_NonBlocking_Connect_Test.cpp: * tests/tests.mpc: * tests/run_test.lst: Added a new test. This can be a reproducer for the bug#3731 which currently doesn't have its own test.
Diffstat (limited to 'ACE/tests/NonBlocking_Conn_Test.cpp')
-rw-r--r--ACE/tests/NonBlocking_Conn_Test.cpp85
1 files changed, 62 insertions, 23 deletions
diff --git a/ACE/tests/NonBlocking_Conn_Test.cpp b/ACE/tests/NonBlocking_Conn_Test.cpp
index 7ca7df557a2..3161dea906a 100644
--- a/ACE/tests/NonBlocking_Conn_Test.cpp
+++ b/ACE/tests/NonBlocking_Conn_Test.cpp
@@ -35,10 +35,17 @@ 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
@@ -52,7 +59,7 @@ Svc_Handler::connection_status (Connection_Status &status,
int
Svc_Handler::open (void *)
{
- *this->status_ = SUCCEEDED;
+ *this->status_ = Svc_Handler::Conn_SUCCEEDED;
(*this->completion_counter_)++;
return 0;
@@ -61,18 +68,26 @@ Svc_Handler::open (void *)
int
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;
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",
@@ -80,15 +95,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);
@@ -104,7 +121,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);
@@ -119,7 +136,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,10 +156,16 @@ test_connect (ACE_Reactor &reactor,
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("Connection to %s %s\n"),
buffer,
- connection_status[i] == Svc_Handler::SUCCEEDED ?
+ 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 ();
}
@@ -171,10 +194,6 @@ test (ACE_Reactor_Impl *impl)
ACE_Reactor reactor (impl, 1);
- int complete_nonblocking_connections = 1;
- int dont_wait_for_nonblocking_connections = 0;
- int ignored = 99;
-
ACE_Synch_Options blocking_connect =
ACE_Synch_Options::defaults;
@@ -184,7 +203,7 @@ test (ACE_Reactor_Impl *impl)
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));
@@ -195,7 +214,7 @@ test (ACE_Reactor_Impl *impl)
test_connect (reactor,
addresses,
blocking_connect,
- ignored);
+ Svc_Handler::Comp_IGNORE);
ACE_Synch_Options nonblocking_connect
(ACE_Synch_Options::USE_REACTOR);
@@ -206,7 +225,7 @@ test (ACE_Reactor_Impl *impl)
test_connect (reactor,
addresses,
nonblocking_connect,
- complete_nonblocking_connections);
+ Svc_Handler::Comp_YES);
ACE_DEBUG ((LM_DEBUG,
"Non-blocking connections (without waiting for completions)...\n"));
@@ -214,7 +233,7 @@ test (ACE_Reactor_Impl *impl)
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,
@@ -226,7 +245,7 @@ test (ACE_Reactor_Impl *impl)
test_connect (reactor,
addresses,
nonblocking_connect,
- complete_nonblocking_connections);
+ Svc_Handler::Comp_YES);
delete[] addresses;
}
@@ -285,6 +304,13 @@ run_main (int argc, ACE_TCHAR *argv[])
ACE_DEBUG ((LM_DEBUG,
"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);
}
@@ -293,6 +319,13 @@ run_main (int argc, ACE_TCHAR *argv[])
ACE_DEBUG ((LM_DEBUG,
"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);
}
@@ -303,6 +336,13 @@ run_main (int argc, ACE_TCHAR *argv[])
ACE_DEBUG ((LM_DEBUG,
"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);
}
@@ -312,4 +352,3 @@ run_main (int argc, ACE_TCHAR *argv[])
return result;
}
-