1 #include "Payload_Receiver.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_stdio.h"
4 #include "ace/OS_NS_sys_time.h"
9 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("test.ior");
15 parse_args (int argc
, ACE_TCHAR
*argv
[])
17 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:e:l:"));
20 while ((c
= get_opts ()) != -1)
24 ior_output_file
= get_opts
.opt_arg ();
27 expected
= ACE_OS::atoi(get_opts
.opt_arg());
30 maybe_lost
= ACE_OS::atoi(get_opts
.opt_arg());
33 ACE_ERROR_RETURN ((LM_ERROR
,
35 "-o <iorfile> [-e <expected>] [-l <maybe_lost>]"
40 // Indicates successful parsing of the command line
45 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
47 ACE_DEBUG ((LM_DEBUG
, "(%P) Starting server\n"));
52 CORBA::ORB_init (argc
, argv
);
54 CORBA::Object_var poa_object
=
55 orb
->resolve_initial_references ("RootPOA");
57 if (CORBA::is_nil (poa_object
.in ()))
59 ACE_ERROR_RETURN ((LM_ERROR
,
60 "(%P) Server: Unable to initialize the POA.\n"),
64 PortableServer::POA_var root_poa
=
65 PortableServer::POA::_narrow (poa_object
.in ());
67 PortableServer::POAManager_var poa_manager
=
68 root_poa
->the_POAManager ();
70 if (parse_args (argc
, argv
) != 0)
75 Payload_Receiver
*payload_receiver_impl
;
76 ACE_NEW_RETURN (payload_receiver_impl
,
79 PortableServer::ServantBase_var
80 receiver_owner_transfer (payload_receiver_impl
);
82 PortableServer::ObjectId_var id
=
83 root_poa
->activate_object (payload_receiver_impl
);
85 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
87 Test::Payload_Receiver_var payload_receiver
=
88 Test::Payload_Receiver::_narrow (object
.in ());
90 CORBA::String_var ior
=
91 orb
->object_to_string (payload_receiver
.in ());
93 // If the ior_output_file exists, output the ior to it
94 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
97 ACE_ERROR_RETURN ((LM_ERROR
,
98 "(%P) Server: Cannot open output file for writing IOR: %s",
102 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
103 ACE_OS::fclose (output_file
);
105 poa_manager
->activate ();
107 ACE_DEBUG ((LM_DEBUG
,
108 "(%P) Server waiting for %d (+%d possible) messages...\n",
109 expected
, maybe_lost
));
111 const ACE_Time_Value start_time
= ACE_OS::gettimeofday ();
112 ACE_Time_Value end_time
= start_time
+ ACE_Time_Value (27);
113 ACE_Time_Value runtime
;
115 int maybe_lost_count
= 0;
116 bool stalled
= false;
117 while (payload_receiver_impl
->count () < expected
||
118 payload_receiver_impl
->count (true) < maybe_lost
)
120 int prev_count
= count
;
121 int prev_maybe_lost_count
= maybe_lost_count
;
122 ACE_Time_Value
tv (0, 100 * 1000);
124 count
= payload_receiver_impl
->count ();
125 maybe_lost_count
= payload_receiver_impl
->count (true);
126 if ((count
== prev_count
) ||
127 (maybe_lost_count
== prev_maybe_lost_count
))
132 end_time
+= ACE_Time_Value (3);
133 runtime
= ACE_OS::gettimeofday () - start_time
;
135 else if (ACE_OS::gettimeofday () > end_time
)
137 if (count
< expected
)
139 ACE_DEBUG ((LM_DEBUG
,
140 "(%P) Server: The clients stalled out after %d messages\n",
143 break; // Abort waiting for more messages
154 runtime
= ACE_OS::gettimeofday () - start_time
;
159 if (count
!= expected
)
161 ACE_ERROR ((LM_ERROR
,
162 "(%P) Server did not receive all of the SYNC_WITH_TARGET messages\n"));
166 ACE_DEBUG ((LM_DEBUG
,
167 "(%P) Server got %d of %d SYNC_WITH_TARGET messages\n"
168 " and %d of %d SYNC_WITH_TRANSPORT or SYNC_NONE messages\n"
171 maybe_lost_count
, maybe_lost
,
172 runtime
.sec(), runtime
.usec()));
174 root_poa
->destroy (true, true);
178 ACE_DEBUG ((LM_DEBUG
, "(%P) Ending server (result %d)\n", result
));
181 catch (const CORBA::Exception
& ex
)
183 ACE_DEBUG ((LM_DEBUG
, "(%P) Server terminated by: "));
184 ex
._tao_print_exception ("CORBA Exception:");
188 ACE_DEBUG ((LM_DEBUG
, "(%P) Server terminated by unknown exception\n"));