Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / HandleExhaustion / client.cpp
blob57af23d012d71ff97832091fa4a9a766c5cd17d5
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.
62 for(size_t i = 0; i < 10; i++)
63 try
65 cout << "Client: calling simple, i = " << i << endl;
66 // This first invocation will actually cause the connection to
67 // the server. Since the server has run out of file handles,
68 // it can not accept the new connection. On some platforms, this will
69 // receive a CORBA::COMM_FAILURE exception because it doesn't
70 // complete in a timely manner. It does not mean that the test
71 // has failed, as long as the server performs the correct
72 // function.
73 test->simple ();
74 break;
76 catch (const CORBA::COMM_FAILURE&)
78 cout << "Client: simple raised COMMFAIL, i = " << i << endl;
79 ACE_OS::sleep (1);
82 cout << "Client: calling simple again" << endl;
83 test->simple ();
84 cout << "Client: calling shutdown" << endl;
85 test->shutdown ();
87 orb->destroy ();
89 catch (const CORBA::Exception& ex)
91 ex._tao_print_exception ("Exception caught:");
92 return 1;
94 #endif /* ACE_WIN32 */
95 return 0;