1 #include "Client_Task.h"
2 #include "ace/Get_Opt.h"
3 #include "tao/Messaging/Messaging.h"
5 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
9 // There are 3 clients so the server should expect:
10 // 3 * NUM_MSGS * NUM_THRDS total messages.
11 const int NUM_MSGS
= 100;
12 const int NUM_THRDS
= 2;
13 const int MSG_SIZE
= 4096;
17 parse_args (int argc
, ACE_TCHAR
*argv
[])
19 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("k:"));
22 while ((c
= get_opts ()) != -1)
26 ior
= get_opts
.opt_arg ();
31 ACE_ERROR_RETURN ((LM_ERROR
,
38 // Indicates successful parsing of the command line
43 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
45 ACE_DEBUG ((LM_DEBUG
, "(%P) Starting client\n"));
50 CORBA::ORB_init (argc
, argv
);
52 if (parse_args (argc
, argv
) != 0)
57 CORBA::Object_var tmp
=
58 orb
->string_to_object(ior
);
60 Test::Payload_Receiver_var payload_receiver
=
61 Test::Payload_Receiver::_narrow(tmp
.in ());
63 if (CORBA::is_nil (payload_receiver
.in ()))
65 ACE_ERROR_RETURN ((LM_DEBUG
,
66 "(%P) Nil coordinator reference <%s>\n",
71 Client_Task
task0 (ACE_Thread_Manager::instance (),
72 payload_receiver
.in (),
76 Messaging::SYNC_WITH_TARGET
,
77 ACE_CString("Sync_With_Target"));
78 Client_Task
task1 (ACE_Thread_Manager::instance (),
79 payload_receiver
.in (),
83 Messaging::SYNC_WITH_TRANSPORT
,
84 ACE_CString("Sync_With_Transport"));
85 Client_Task
task2 (ACE_Thread_Manager::instance (),
86 payload_receiver
.in (),
91 ACE_CString("Sync_None"));
93 if (TAO_debug_level
> 0)
95 ACE_DEBUG ((LM_DEBUG
, "(%P) Client: Activating threads\n"));
97 if (task0
.activate (THR_NEW_LWP
| THR_JOINABLE
, NUM_THRDS
, 1) == -1)
99 ACE_ERROR ((LM_ERROR
, "(%P) Client: Error activating %s task\n", task0
.ID ()));
101 if (task1
.activate (THR_NEW_LWP
| THR_JOINABLE
, NUM_THRDS
, 1) == -1)
103 ACE_ERROR ((LM_ERROR
, "(%P) Client: Error activating %s task\n", task1
.ID ()));
105 if (task2
.activate (THR_NEW_LWP
| THR_JOINABLE
, NUM_THRDS
, 1) == -1)
107 ACE_ERROR ((LM_ERROR
, "(%P) Client: Error activating %s task\n", task2
.ID ()));
110 ACE_Time_Value end_time
= ACE_OS::gettimeofday() + ACE_Time_Value(30);
111 while (ACE_OS::gettimeofday() < end_time
)
113 ACE_Time_Value
tv (0, 100 * 1000);
115 if (task0
.done() && task1
.done() && task2
.done())
119 ACE_Thread_Manager::instance ()->wait ();
120 if (TAO_debug_level
> 0)
122 ACE_DEBUG ((LM_DEBUG
, "(%P) Client: Threads finished posting\n"));
125 while (orb
->work_pending())
127 ACE_Time_Value
tv(0, 100 * 1000);
131 if (TAO_debug_level
> 0)
133 ACE_DEBUG ((LM_DEBUG
, "(%P) Client: work finished\n"));
136 // Allow time for the server to process messages at the other end
137 // of the tcpip link before we destroy the sockets and rip down
138 // any pending messages it may have buffered up. Note this is ONLY
139 // for the benifit of the SYNC_NONE and SYNC_WITH_TRANSPORT messages.
140 ACE_Time_Value
tv (4, 0);
144 catch (const CORBA::Exception
& ex
)
146 ACE_DEBUG ((LM_DEBUG
, "(%P) Client: "));
147 ex
._tao_print_exception ("CORBA Exception caught:");
152 ACE_DEBUG ((LM_DEBUG
, "(%P) Client caught unknown exception\n"));
156 ACE_DEBUG ((LM_DEBUG
, "(%P) Ending client (result 0)\n"));