Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / AMH_Oneway / client.cpp
blob29df8c17d1b42da60b12311cfd001b64d5e82052
1 #include "ace/Get_Opt.h"
2 #include "TestC.h"
3 #include "ace/OS_NS_unistd.h"
5 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
6 int num_calls = 10;
8 int
9 parse_args (int argc, ACE_TCHAR *argv[])
11 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("n:"));
12 int c;
14 while ((c = get_opts ()) != -1)
15 switch (c)
17 case 'n':
18 num_calls = ACE_OS::atoi (get_opts.opt_arg ());
19 break;
20 default:
21 break;
23 return 0;
26 int
27 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
29 try
31 CORBA::ORB_var orb =
32 CORBA::ORB_init (argc, argv);
34 if (parse_args (argc, argv) != 0)
35 return 1;
37 CORBA::Object_var object =
38 orb->string_to_object (ior);
40 Test::Roundtrip_var roundtrip =
41 Test::Roundtrip::_narrow (object.in ());
43 if (CORBA::is_nil (roundtrip.in ()))
45 ACE_ERROR_RETURN ((LM_ERROR,
46 "Nil Test::Roundtrip reference <%s>\n",
47 ior),
48 1);
51 // Do a couple of calls on the server. If the sever is trying to
52 // do something stupid like sending an exception to us, then it
53 // won't be able to handle more than 1 request from us.
54 Test::Timestamp time = 10;
55 for (int i = 0; i < num_calls; i++)
57 roundtrip->test_method (time);
59 ACE_DEBUG ((LM_DEBUG, "Sent call # %d\n", i));
61 orb->destroy();
62 // The following sleep is a workaround for a defect in the Windows
63 // implementation of sockets (Win XP)
64 // When this client exits after writing to a localhost socket
65 // Windows discards any data that has not been read by the server.
66 // The sleep gives the server time to catch up. num_calls/2 gives
67 // it half a second per request which *really* should be overkill, but
68 // it also means the client will terminate before the server actually
69 // handles the requests (a good thing).
70 // I'm still trying to decide whether this should be a bugzilla entry.
71 // wilsond@ociweb.com
72 ACE_OS::sleep(num_calls/2);
74 catch (const CORBA::Exception& ex)
76 ex._tao_print_exception ("");
77 return 1;
80 return 0;