summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TAO/tests/Bug_2417_Regression/Bug_2417_Regression.mpc19
-rw-r--r--TAO/tests/Bug_2417_Regression/client.cpp78
-rw-r--r--TAO/tests/Bug_2417_Regression/publisher.idl10
-rw-r--r--TAO/tests/Bug_2417_Regression/publisher_impl.cpp166
-rw-r--r--TAO/tests/Bug_2417_Regression/publisher_impl.h37
-rwxr-xr-xTAO/tests/Bug_2417_Regression/run_test.pl49
-rw-r--r--TAO/tests/Bug_2417_Regression/server.cpp93
-rw-r--r--TAO/tests/Bug_2417_Regression/subscriber.idl7
-rw-r--r--TAO/tests/Bug_2417_Regression/subscriber_impl.cpp45
-rw-r--r--TAO/tests/Bug_2417_Regression/subscriber_impl.h34
10 files changed, 538 insertions, 0 deletions
diff --git a/TAO/tests/Bug_2417_Regression/Bug_2417_Regression.mpc b/TAO/tests/Bug_2417_Regression/Bug_2417_Regression.mpc
new file mode 100644
index 00000000000..eae10dc662e
--- /dev/null
+++ b/TAO/tests/Bug_2417_Regression/Bug_2417_Regression.mpc
@@ -0,0 +1,19 @@
+// -*- MPC -*-
+// $Id$
+
+project(*Server): taoserver, messaging {
+ Source_Files {
+ publisher_impl.cpp
+ server.cpp
+ }
+}
+
+project(*Client): taoserver {
+ exename = client
+ after += *Server
+ Source_Files {
+ subscriber_impl.cpp
+ client.cpp
+ }
+}
+
diff --git a/TAO/tests/Bug_2417_Regression/client.cpp b/TAO/tests/Bug_2417_Regression/client.cpp
new file mode 100644
index 00000000000..d24f2ed88be
--- /dev/null
+++ b/TAO/tests/Bug_2417_Regression/client.cpp
@@ -0,0 +1,78 @@
+// $Id$
+
+#include "subscriber_impl.h"
+#include "publisherC.h"
+#include "ace/Get_Opt.h"
+#include "ace/Task.h"
+#include <conio.h>
+
+class ThreadPool : public ACE_Task_Base
+{
+public:
+ ThreadPool (CORBA::ORB_ptr orb);
+ virtual int svc (void);
+private:
+ CORBA::ORB_var orb_;
+};
+
+int
+main (int argc, char *argv[])
+{
+ ACE_TRY_NEW_ENV
+ {
+ CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, "");
+ CORBA::Object_var poa_object = orb->resolve_initial_references("RootPOA");
+
+ if (CORBA::is_nil (poa_object.in ()))
+ ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Unable to initialize the POA.\n"), 1);
+
+ PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ());
+ PortableServer::POAManager_var poa_manager =
+ root_poa->the_POAManager();
+
+ Subscriber_impl subscriber(orb.in ());
+ Subscriber_var subscriber_var = subscriber._this();
+
+ CORBA::Object_var object = orb->string_to_object("file://ior.out");
+ Publisher_var publisher = Publisher::_narrow(object.in());
+
+ publisher->subscribe(subscriber_var.in());
+
+ poa_manager->activate();
+
+ ThreadPool pool (orb.in ());
+ if (pool.activate(THR_NEW_LWP | THR_JOINABLE, 5) != 0)
+ ACE_ERROR_RETURN ((LM_ERROR, "Cannot activate client threads\n"), 1);
+
+ pool.thr_mgr ()->wait ();
+
+ ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
+ }
+ ACE_CATCHANY
+ {
+ ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Exception caught:");
+ return 1;
+ }
+ ACE_ENDTRY;
+
+ return 0;
+}
+
+// ****************************************************************
+
+ThreadPool::ThreadPool(CORBA::ORB_ptr orb)
+: orb_(CORBA::ORB::_duplicate (orb))
+{
+}
+
+int ThreadPool::svc (void)
+{
+ try
+ {
+ this->orb_->run ();
+ }
+ catch (...)
+ {
+ }
+ return 0;
+}
diff --git a/TAO/tests/Bug_2417_Regression/publisher.idl b/TAO/tests/Bug_2417_Regression/publisher.idl
new file mode 100644
index 00000000000..51fb10a1e23
--- /dev/null
+++ b/TAO/tests/Bug_2417_Regression/publisher.idl
@@ -0,0 +1,10 @@
+// $Id$
+
+#include "subscriber.idl"
+
+interface Publisher
+{
+ void subscribe(in Subscriber _subscriber);
+
+ oneway void shutdown ();
+};
diff --git a/TAO/tests/Bug_2417_Regression/publisher_impl.cpp b/TAO/tests/Bug_2417_Regression/publisher_impl.cpp
new file mode 100644
index 00000000000..56f9367198a
--- /dev/null
+++ b/TAO/tests/Bug_2417_Regression/publisher_impl.cpp
@@ -0,0 +1,166 @@
+// $Id$
+
+#include "publisher_impl.h"
+#include "ace/OS_NS_sys_time.h"
+#include "ace/OS_NS_time.h"
+#include "ace/Task.h"
+#include "ace/Process_Mutex.h"
+#include <vector>
+
+using namespace std;
+
+struct _Subscriber
+{
+ Subscriber_var subscriber;
+ bool unsubscribed;
+ unsigned int count;
+};
+
+class Publisher_impl::Worker : public ACE_Task_Base
+{
+public:
+ Worker(Publisher_impl * _owner);
+ ~Worker();
+ void addSubscriber(Subscriber_ptr subscriber);
+ virtual int svc (void);
+ void terminate();
+private:
+ bool terminated;
+ vector<_Subscriber> subscribers;
+ ACE_Thread_Mutex mutex;
+ Publisher_impl * owner;
+};
+
+Publisher_impl::Worker::Worker(Publisher_impl * _owner)
+: owner(_owner)
+{
+ terminated = false;
+}
+
+Publisher_impl::Worker::~Worker()
+{
+ terminated = true;
+}
+
+void Publisher_impl::Worker::addSubscriber(Subscriber_ptr subscriber)
+{
+ ACE_Guard<ACE_Thread_Mutex> guard(mutex, 1, 1);
+ subscribers.push_back(_Subscriber());
+ _Subscriber& s = subscribers.back();
+ s.unsubscribed = false;
+ s.subscriber = Subscriber::_duplicate(subscriber);
+ s.count = 0;
+}
+
+int Publisher_impl::Worker::svc (void)
+{
+ double data = 0.0;
+ bool doShutdown = false;
+ unsigned long iteration = 0;
+ ACE_Time_Value tv;
+ tv.set(0.01);
+ while (!terminated)
+ {
+ data += 0.01;
+ ++iteration;
+ {
+ ACE_Guard<ACE_Thread_Mutex> guard(mutex, 1, 1);
+ doShutdown = subscribers.size() > 0;
+ for (vector<_Subscriber>::iterator iter = subscribers.begin(); iter != subscribers.end(); ++iter)
+ {
+ if (!iter->unsubscribed)
+ {
+ doShutdown = false;
+ try
+ {
+ unsigned int i = iter->count;
+ if (!CORBA::is_nil(iter->subscriber))
+ iter->subscriber->onData(data);
+ else
+ iter->unsubscribed = true;
+ ++iter->count;
+ }
+ catch (...)
+ {
+ iter->unsubscribed = true;
+ }
+ }
+ }
+ }
+ if (iteration % 1000 == 0)
+ {
+ ACE_Guard<ACE_Thread_Mutex> guard(mutex, 1, 1);
+ for (vector<_Subscriber>::iterator iter = subscribers.begin(); iter != subscribers.end(); ++iter)
+ {
+ if (!iter->unsubscribed)
+ {
+ try
+ {
+ iter->subscriber->isAlive();
+ }
+ catch (...)
+ {
+ iter->unsubscribed = true;
+ }
+ }
+ }
+ }
+ if (doShutdown)
+ owner->shutdown();
+ else
+ ACE_OS::sleep(tv);
+ }
+ return 0;
+}
+
+void Publisher_impl::Worker::terminate()
+{
+ terminated = true;
+}
+
+Publisher_impl::Publisher_impl(CORBA::ORB_ptr orb)
+: orb_ (CORBA::ORB::_duplicate (orb))
+{
+ worker = new Worker(this);
+ worker->activate();
+}
+
+Publisher_impl::~Publisher_impl()
+{
+ worker->terminate();
+ worker->thr_mgr()->wait();
+ delete worker;
+}
+
+void subscribe (
+ ::Subscriber_ptr subscriber
+ ACE_ENV_ARG_DECL_WITH_DEFAULTS
+ )
+ ACE_THROW_SPEC ((
+ ::CORBA::SystemException
+ ));
+
+void
+Publisher_impl::subscribe(
+ ::Subscriber_ptr subscriber
+ ACE_ENV_ARG_DECL_WITH_DEFAULTS
+ )
+ ACE_THROW_SPEC ((
+ ::CORBA::SystemException
+ ))
+{
+ worker->addSubscriber(subscriber);
+}
+
+void
+Publisher_impl::shutdown (
+ ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS
+ )
+ ACE_THROW_SPEC ((
+ ::CORBA::SystemException
+ ))
+{
+ this->orb_->shutdown (0);
+ worker->terminate();
+}
+
diff --git a/TAO/tests/Bug_2417_Regression/publisher_impl.h b/TAO/tests/Bug_2417_Regression/publisher_impl.h
new file mode 100644
index 00000000000..43a62ae54ac
--- /dev/null
+++ b/TAO/tests/Bug_2417_Regression/publisher_impl.h
@@ -0,0 +1,37 @@
+// $Id$
+
+#ifndef EXPLOIT_PUBLISHER_IMPL_H
+#define EXPLOIT_PUBLISHER_IMPL_H
+
+#include "publisherS.h"
+#include "subscriberC.h"
+
+class Publisher_impl : public POA_Publisher
+{
+ public:
+ Publisher_impl(CORBA::ORB_ptr orb);
+ ~Publisher_impl();
+
+ virtual void subscribe (
+ ::Subscriber_ptr subscriber
+ ACE_ENV_ARG_DECL_WITH_DEFAULTS
+ )
+ ACE_THROW_SPEC ((
+ ::CORBA::SystemException
+ ));
+
+ virtual void shutdown (
+ ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS
+ )
+ ACE_THROW_SPEC ((
+ ::CORBA::SystemException
+ ));
+
+ private:
+ CORBA::ORB_var orb_;
+ class Worker;
+ friend class Worker;
+ Worker * worker;
+};
+
+#endif
diff --git a/TAO/tests/Bug_2417_Regression/run_test.pl b/TAO/tests/Bug_2417_Regression/run_test.pl
new file mode 100755
index 00000000000..c83037f61f2
--- /dev/null
+++ b/TAO/tests/Bug_2417_Regression/run_test.pl
@@ -0,0 +1,49 @@
+eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
+ & eval 'exec perl -S $0 $argv:q'
+ if 0;
+
+# $Id$
+# -*- perl -*-
+
+use lib '../../../bin';
+use PerlACE::Run_Test;
+
+$iorfile = PerlACE::LocalFile ("ior.out");
+unlink $iorfile;
+$status = 0;
+
+$SV = new PerlACE::Process ("server", "");
+
+$CL1 = new PerlACE::Process ("client", "");
+
+$server = $SV->Spawn ();
+
+if ($server != 0) {
+ print STDERR "ERROR: server returned $server\n";
+ exit 1;
+}
+
+if (PerlACE::waitforfile_timed ($iorfile,
+ $PerlACE::wait_interval_for_process_creation) == -1) {
+ print STDERR "ERROR: cannot find file <$iorfile>\n";
+ $SV->Kill (); $SV->TimedWait (1);
+ exit 1;
+}
+
+$CL1->Spawn ();
+
+$client = $CL1->WaitKill (60);
+
+if ($client != 0) {
+ print STDERR "ERROR: client returned $client\n";
+ $status = 1;
+}
+$server = $SV->WaitKill (35);
+
+if ($server != 0) {
+ print STDERR "ERROR: server returned $server\n";
+ $status = 1;
+}
+unlink $iorfile;
+
+exit $status
diff --git a/TAO/tests/Bug_2417_Regression/server.cpp b/TAO/tests/Bug_2417_Regression/server.cpp
new file mode 100644
index 00000000000..8a8ba4c1a2c
--- /dev/null
+++ b/TAO/tests/Bug_2417_Regression/server.cpp
@@ -0,0 +1,93 @@
+// $Id$
+
+#include "publisher_impl.h"
+#include "tao/Messaging/Messaging.h"
+#include "tao/AnyTypeCode/Any.h"
+#include "ace/Get_Opt.h"
+#include "ace/Task.h"
+
+class ThreadPool : public ACE_Task_Base
+{
+public:
+ ThreadPool (CORBA::ORB_ptr orb);
+ virtual int svc (void);
+private:
+ CORBA::ORB_var orb_;
+};
+
+int
+main (int argc, char *argv[])
+{
+ ACE_TRY_NEW_ENV
+ {
+ CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, "");
+ CORBA::Object_var poa_object = orb->resolve_initial_references("RootPOA");
+
+ if (CORBA::is_nil (poa_object.in ()))
+ ACE_ERROR_RETURN ((LM_ERROR, " (%P|%t) Unable to initialize the POA.\n"), 1);
+
+ PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in ());
+ PortableServer::POAManager_var poa_manager =
+ root_poa->the_POAManager();
+
+ Publisher_impl publisher(orb.in ());
+ Publisher_var publisher_var = publisher._this();
+
+ CORBA::String_var ior = orb->object_to_string(publisher_var.in());
+ ACE_DEBUG ((LM_DEBUG, "Activated as <%s>\n", ior.in()));
+
+ // output the ior
+ FILE *output_file= ACE_OS::fopen ("ior.out", "w");
+ if (output_file == 0)
+ ACE_ERROR_RETURN ((LM_ERROR, "Cannot open output file for writing IOR: ior.out"), 1);
+ ACE_OS::fprintf (output_file, "%s", ior.in ());
+ ACE_OS::fclose (output_file);
+
+ poa_manager->activate();
+
+ const CORBA::Object_var pmobj ( orb->resolve_initial_references( "ORBPolicyManager" ) );
+ CORBA::PolicyManager_var policy_manager = CORBA::PolicyManager::_narrow( pmobj.in() );
+
+ CORBA::Any orb_level;
+ orb_level <<= Messaging::SYNC_NONE;
+ CORBA::PolicyList policy_list;
+ policy_list.length(1);
+ policy_list[0] = orb->create_policy(Messaging::SYNC_SCOPE_POLICY_TYPE, orb_level);
+ policy_manager->set_policy_overrides(policy_list, CORBA::SET_OVERRIDE);
+
+ ThreadPool pool (orb.in ());
+ if (pool.activate(THR_NEW_LWP | THR_JOINABLE, 5) != 0)
+ ACE_ERROR_RETURN ((LM_ERROR, "Cannot activate client threads\n"), 1);
+
+ pool.thr_mgr ()->wait ();
+
+ ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
+ }
+ ACE_CATCHANY
+ {
+ ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Exception caught:");
+ return 1;
+ }
+ ACE_ENDTRY;
+
+ return 0;
+}
+
+// ****************************************************************
+
+ThreadPool::ThreadPool(CORBA::ORB_ptr orb)
+: orb_(CORBA::ORB::_duplicate (orb))
+{
+}
+
+int ThreadPool::svc (void)
+{
+ try
+ {
+ this->orb_->run ();
+ }
+ catch (...)
+ {
+ }
+ return 0;
+}
diff --git a/TAO/tests/Bug_2417_Regression/subscriber.idl b/TAO/tests/Bug_2417_Regression/subscriber.idl
new file mode 100644
index 00000000000..4bc284d2979
--- /dev/null
+++ b/TAO/tests/Bug_2417_Regression/subscriber.idl
@@ -0,0 +1,7 @@
+// $Id$
+
+interface Subscriber
+{
+ oneway void onData(in double value);
+ boolean isAlive();
+};
diff --git a/TAO/tests/Bug_2417_Regression/subscriber_impl.cpp b/TAO/tests/Bug_2417_Regression/subscriber_impl.cpp
new file mode 100644
index 00000000000..61f25e23349
--- /dev/null
+++ b/TAO/tests/Bug_2417_Regression/subscriber_impl.cpp
@@ -0,0 +1,45 @@
+// $Id$
+
+#include "subscriber_impl.h"
+#include "ace/OS_NS_stdio.h"
+
+Subscriber_impl::Subscriber_impl(CORBA::ORB_ptr orb)
+: orb_ (CORBA::ORB::_duplicate (orb))
+, count(0)
+{
+}
+
+Subscriber_impl::~Subscriber_impl()
+{
+}
+
+void
+Subscriber_impl::onData (
+ ::CORBA::Double
+ ACE_ENV_ARG_DECL_WITH_DEFAULTS
+ )
+ ACE_THROW_SPEC ((
+ ::CORBA::SystemException
+ ))
+{
+ ++count;
+ if (count > 100)
+ shutdown();
+}
+
+::CORBA::Boolean
+Subscriber_impl::isAlive (
+ ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS
+ )
+ ACE_THROW_SPEC ((
+ ::CORBA::SystemException
+ ))
+{
+ return true;
+}
+
+void Subscriber_impl::shutdown()
+{
+ this->orb_->shutdown (0);
+}
+
diff --git a/TAO/tests/Bug_2417_Regression/subscriber_impl.h b/TAO/tests/Bug_2417_Regression/subscriber_impl.h
new file mode 100644
index 00000000000..4b37f8f7529
--- /dev/null
+++ b/TAO/tests/Bug_2417_Regression/subscriber_impl.h
@@ -0,0 +1,34 @@
+// $Id$
+
+#ifndef EXPLOIT_PUBLISHER_IMPL_H
+#define EXPLOIT_PUBLISHER_IMPL_H
+
+#include "subscriberS.h"
+
+class Subscriber_impl : public POA_Subscriber
+{
+ public:
+ Subscriber_impl(CORBA::ORB_ptr orb);
+ ~Subscriber_impl();
+
+ virtual void onData (
+ ::CORBA::Double value
+ ACE_ENV_ARG_DECL_WITH_DEFAULTS
+ )
+ ACE_THROW_SPEC ((
+ ::CORBA::SystemException
+ ));
+ virtual ::CORBA::Boolean isAlive (
+ ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS
+ )
+ ACE_THROW_SPEC ((
+ ::CORBA::SystemException
+ ));
+
+ void shutdown();
+ private:
+ CORBA::ORB_var orb_;
+ unsigned int count;
+};
+
+#endif