More tests update
[ACE_TAO.git] / TAO / tests / Bug_2683_Regression / client.cpp
blobf14e73c76792d9ae658bb4ae0c1eb1c70af87510
1 #include "TestC.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/Task.h"
4 #include "ace/OS_NS_unistd.h"
6 class Pinger : public ACE_Task_Base
8 private:
9 const char * ior_;
10 CORBA::ORB_var orb_;
11 bool do_shutdown_;
12 bool stop_;
14 public:
15 Pinger (CORBA::ORB_var &orb, const char *ior)
16 : ior_ (ior),
17 orb_(orb),
18 do_shutdown_ (false),
19 stop_ (false)
23 int svc (void)
25 bool keep_going = true;
26 while (keep_going && !this->stop_)
28 try
30 CORBA::Object_var tmp = this->orb_->string_to_object(this->ior_);
32 Test::IORTable_Shutdown_Race_var target =
33 Test::IORTable_Shutdown_Race::_narrow(tmp.in ());
34 if (CORBA::is_nil (target.in ()))
35 ACE_ERROR_RETURN ((LM_DEBUG,
36 "(%P|%t) Nil target reference <%s>\n",
37 this->ior_),
38 1);
39 target->ping();
40 if (this->do_shutdown_)
42 ACE_DEBUG ((LM_DEBUG,"(%P|%t) Calling shutdown\n"));
43 this->do_shutdown_ = false;
44 target->shutdown ();
47 catch (const CORBA::Exception &ex)
49 ACE_DEBUG ((LM_DEBUG,
50 "(%P|%t) caught an exception - %C\n",ex._name()));
51 keep_going = false;
54 return 0;
57 void killit()
59 do_shutdown_ = true;
62 void stop ()
64 stop_ = true;
69 int port = 0;
70 ACE_TCHAR const * target_host = ACE_TEXT("localhost");
72 int
73 parse_args (int argc, ACE_TCHAR *argv[])
75 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("p:h:"));
76 int c;
78 while ((c = get_opts ()) != -1)
79 switch (c)
81 case 'p':
82 port = ACE_OS::atoi (get_opts.opt_arg ());
83 break;
84 case 'h':
85 target_host = get_opts.opt_arg ();
86 break;
87 case '?':
88 default:
89 ACE_ERROR_RETURN ((LM_ERROR,
90 "usage: %s "
91 "-p <server_port> "
92 "\n",
93 argv [0]),
94 -1);
96 // Indicates successful parsing of the command line
97 return 0;
101 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
105 CORBA::ORB_var orb =
106 CORBA::ORB_init (argc, argv);
108 if (parse_args (argc, argv) != 0)
109 return 1;
111 char ior[100];
112 ACE_OS::sprintf (ior, "corbaloc::%s:%d/Racer",
113 ACE_TEXT_ALWAYS_CHAR (target_host), port);
115 Pinger pinger(orb, ior);
117 ACE_OS::sleep (1);
119 ACE_DEBUG ((LM_DEBUG,"(%P|%t) client - starting client threads\n"));
121 pinger.activate (THR_NEW_LWP | THR_JOINABLE, 5);
123 ACE_OS::sleep (1);
125 ACE_DEBUG ((LM_DEBUG,"(%P|%t) client - All running, time to shutdown server\n"));
126 pinger.killit();
128 ACE_OS::sleep (2);
130 ACE_DEBUG ((LM_DEBUG,"(%P|%t) client - Stopping client threads\n"));
131 pinger.stop ();
133 pinger.wait();
134 ACE_DEBUG ((LM_DEBUG,"(%P|%t) client done\n"));
137 catch (const CORBA::Exception &ex)
139 ACE_DEBUG ((LM_DEBUG,"Main caught %s\n",ex._name()));
140 return 1;
143 return 0;