Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / TAO / tests / Bug_3553_Regression / Bug_3553_Regression_client.cpp
blob7c5e513ae16ff28a86bad3a859a644d295c868a8
1 #include "TestC.h"
2 #include "tao/RTCORBA/RTCORBA.h"
3 #include "tao/Policy_Current.h"
4 #include "tao/Policy_Current.h"
5 #include "ace/Get_Opt.h"
7 int cache_size = 512;
8 int port_nr = 27530;
10 int
11 parse_args (int argc, ACE_TCHAR *argv[])
13 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("c:p:"));
14 int c;
16 while ((c = get_opts ()) != -1)
17 switch (c)
19 case 'c':
20 cache_size = ACE_OS::atoi (get_opts.opt_arg ());
21 break;
23 case 'p':
24 port_nr = ACE_OS::atoi (get_opts.opt_arg ());
25 break;
27 case '?':
28 default:
29 ACE_ERROR_RETURN ((LM_ERROR,
30 "usage: %s "
31 "-c <transport_cache_size>\n"
32 "-p <server_port_nr>\n",
33 argv [0]),
34 -1);
36 // Indicates successful parsing of the command line
37 return 0;
40 int
41 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
43 try
45 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
47 if (parse_args(argc, argv) != 0)
48 return 1;
50 // Get the RTORB.
51 CORBA::Object_var obj = orb->resolve_initial_references ("RTORB");
52 RTCORBA::RTORB_var rtorb = RTCORBA::RTORB::_narrow (obj.in());
53 //create the private connections policy. This means that every connection
54 // to the server uses his own socket.
55 CORBA::PolicyList policies (1);
56 policies.length (1);
57 policies[0] = rtorb->create_private_connection_policy ();
59 CORBA::Object_var pol_current_object = orb->resolve_initial_references ("PolicyCurrent");
61 CORBA::PolicyCurrent_var policy_current =
62 CORBA::PolicyCurrent::_narrow (pol_current_object.in ());
64 if (CORBA::is_nil (policy_current.in ()))
66 ACE_ERROR ((LM_ERROR, "ERROR: Nil policy current\n"));
67 return 1;
69 policy_current->set_policy_overrides (policies, CORBA::ADD_OVERRIDE);
71 Test::Hello_var *hello_array = 0;
72 ACE_NEW_RETURN (hello_array, Test::Hello_var [cache_size], -1);
74 int iter = 1;
75 for (iter = 1; iter <= cache_size; ++iter)
77 char object_string[256];
78 char reference_string[256];
79 ACE_OS::sprintf (reference_string, "TransportCacheTest%d", iter);
80 ACE_OS::sprintf (object_string, "corbaloc:iiop:localhost:%d/", port_nr);
81 ACE_OS::strcat (object_string, reference_string);
83 CORBA::Object_var hello_obj = orb->string_to_object (object_string);
84 orb->register_initial_reference (reference_string, hello_obj.in ());
86 CORBA::String_var ior_string = orb->object_to_string (hello_obj.in());
87 ACE_DEBUG((LM_DEBUG, ACE_TEXT("IOR string for reference %d : %C\n"),
88 iter, ior_string.in ()));
89 hello_array[iter-1] = Test::Hello::_narrow(hello_obj.in ());
91 //now we've got the references -> call each and everyone of them
92 for (iter = 0; iter < cache_size; ++iter)
94 Test::Hello_var hello = hello_array[iter];
95 if (CORBA::is_nil (hello.in ()))
97 ACE_ERROR_RETURN ((LM_DEBUG,
98 ACE_TEXT ("Nil Test::Hello reference\n")),
99 1);
102 CORBA::String_var the_string = hello->get_string ();
104 ACE_DEBUG ((LM_DEBUG, "(%P|%t) - string returned <%C> from reference %d\n",
105 the_string.in (), iter + 1));
107 //shutdown the server
108 if (iter >= 0)
109 hello_array[0]->shutdown ();
111 orb->destroy ();
113 catch (const CORBA::Exception& ex)
115 ex._tao_print_exception ("Exception caught:");
116 return 1;
119 return 0;