Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / DIOP / UDP_Client_i.cpp
blobec477c40297e04bc6dc3c2eb1cc36a63eebc738b
1 #include "UDP_Client_i.h"
2 #include "ace/SString.h"
3 #include "ace/OS_NS_unistd.h"
5 // This is the interface program that accesses the remote object
7 // Constructor.
8 UDP_Client_i::UDP_Client_i (CORBA::ORB_ptr orb,
9 UDP_ptr udp,
10 UDP_ptr udpHandler,
11 ACE_UINT32 msec,
12 ACE_UINT32 iterations)
13 : orb_ (CORBA::ORB::_duplicate (orb))
14 , udp_ (UDP::_duplicate (udp))
15 , udpHandler_ (UDP::_duplicate (udpHandler))
16 , delay_ (msec)
17 , iterations_ (iterations)
22 //Destructor.
23 UDP_Client_i::~UDP_Client_i (void)
25 //no-op
28 int
29 UDP_Client_i::svc (void)
31 ACE_CString client_name ("UDP");
33 char pid[256];
34 ACE_OS::sprintf (pid,
35 "%u",
36 static_cast<u_int> (ACE_OS::getpid ()));
37 client_name += "_";
38 client_name += pid;
41 try
43 CORBA::String_var corba_client_name =
44 CORBA::string_dup (client_name.c_str ());
46 for (ACE_UINT32 i = 0;
47 i < iterations_;
48 i++)
50 udp_->invoke (corba_client_name.in (),
51 udpHandler_.inout (),
52 i);
54 ACE_DEBUG ((LM_DEBUG,
55 "invoked %C %d, going to wait %d ms\n",
56 corba_client_name.in (),
58 delay_));
59 ACE_Time_Value tv (0, delay_ * 1000);
60 ACE_OS::sleep (tv); // wait to not flood the server
63 // shut down remote ORB
64 for (int c = 0; c < 10; ++c)
65 udp_->shutdown ();
67 ACE_Time_Value tv (0, 500); // 50ms
68 ACE_OS::sleep (tv); // let the previous request go through
70 // Shut down local ORB, trigger the end of the ORB event loop
71 // in the main thread.
72 orb_->shutdown ();
75 catch (const CORBA::Exception& ex)
77 ex._tao_print_exception ("\tException");
78 return -1;
82 return 0;