Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / HandleExhaustion / client.cpp
blob827ee12269b6abc2e02ae736f9ec8445b1bd0a8d
1 #include "TestC.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_unistd.h"
4 #include "ace/streams.h"
6 static const ACE_TCHAR *ior = ACE_TEXT ("file://server.ior");
8 int
9 parse_args (int argc, ACE_TCHAR *argv[])
11 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:x"));
12 int c;
14 while ((c = get_opts ()) != -1)
15 switch (c)
17 case 'k':
18 ior = get_opts.opt_arg ();
19 break;
21 case '?':
22 default:
23 ACE_ERROR_RETURN ((LM_ERROR,
24 "usage: %s "
25 "-k <ior> "
26 "\n",
27 argv [0]),
28 -1);
30 // Indicates successful parsing of the command line
31 return 0;
34 int
35 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
37 #if defined (ACE_WIN32)
38 ACE_UNUSED_ARG (argc);
39 ACE_UNUSED_ARG (argv);
40 cout << "HandleExhaustion test not available on Windows" << endl;
41 #else
42 try
44 CORBA::ORB_var orb =
45 CORBA::ORB_init (argc, argv);
47 if (parse_args (argc, argv) != 0)
48 return 1;
50 CORBA::Object_var tmp =
51 orb->string_to_object (ior);
53 Test_var test = Test::_narrow(tmp.in ());
55 if (CORBA::is_nil (test.in ()))
57 ACE_ERROR_RETURN ((LM_DEBUG, "Nil Test reference <%s>\n", ior), 1);
60 // Try a few times until we run out of "trys" or we no longer get
61 // an exception. Some times it takes a little while to begin
62 // accepting again on AIX.
63 for(size_t i = 0; i < 10; i++)
64 try
66 cout << "Client: calling simple, i = " << i << endl;
67 // This first invocation will actually cause the connection to
68 // the server. Since the server has run out of file handles,
69 // it can not accept the new connection. On AIX, this will
70 // receive a CORBA::COMM_FAILURE exception because it doesn't
71 // complete in a timely manner. It does not mean that the test
72 // has failed, as long as the server performs the correct
73 // function.
74 test->simple ();
75 break;
77 catch (const CORBA::COMM_FAILURE&)
79 cout << "Client: simple raised COMMFAIL, i = " << i << endl;
80 ACE_OS::sleep (1);
83 cout << "Client: calling simple again" << endl;
84 test->simple ();
85 cout << "Client: calling shutdown" << endl;
86 test->shutdown ();
88 orb->destroy ();
90 catch (const CORBA::Exception& ex)
92 ex._tao_print_exception ("Exception caught:");
93 return 1;
95 #endif /* ACE_WIN32 */
96 return 0;