Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / Server_Connection_Purging / client.cpp
blobff54e4840192f9090714121b9ed0fe17b9a93f1f
1 #include "ace/Get_Opt.h"
2 #include "ace/Log_Msg.h"
3 #include "ace/SOCK_Connector.h"
4 #include "ace/TP_Reactor.h"
5 #include "ace/Reactor.h"
7 const ACE_TCHAR *host = ACE_TEXT("localhost");
8 static int port = 10008;
9 const int iter = 55;
10 int purged_handles = 0;
12 int
13 parse_args (int argc, ACE_TCHAR *argv[])
15 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("h:p:"));
16 int c;
18 while ((c = get_opts ()) != -1)
19 switch (c)
21 case 'h':
22 host = get_opts.opt_arg ();
23 break;
24 case 'p':
25 port = ACE_OS::atoi (get_opts.opt_arg ());
26 break;
27 case '?':
28 default:
29 ACE_ERROR_RETURN ((LM_ERROR,
30 "usage: %s "
31 "-h <host> "
32 "-p <port>"
33 "-i <iterations>"
34 "\n",
35 argv [0]),
36 -1);
39 // Indicates successful parsing of the command line
40 return 0;
43 class Purging_Handler : public ACE_Event_Handler
45 public:
46 virtual int handle_input (ACE_HANDLE h);
47 virtual int handle_close (ACE_HANDLE h,
48 ACE_Reactor_Mask m);
51 int
52 Purging_Handler::handle_input (ACE_HANDLE )
54 return -1;
57 int
58 Purging_Handler::handle_close (ACE_HANDLE h,
59 ACE_Reactor_Mask )
61 if (purged_handles % 10 == 0)
62 ACE_DEBUG ((LM_DEBUG,
63 "(%P|%t) purging handle [%d]\n",
64 h));
66 ++purged_handles;
68 return 0;
71 int
72 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
74 if (parse_args (argc, argv) == -1)
75 return -1;
77 ACE_Select_Reactor sr;
79 ACE_Reactor reac (&sr);
81 ACE_Reactor::instance (&reac);
83 ACE_SOCK_Stream stream[iter];
85 ACE_SOCK_Connector connector[iter];
87 Purging_Handler ph[iter];
89 ACE_INET_Addr addr (port,
90 host);
93 ACE_Reactor *singleton =
94 ACE_Reactor::instance ();
96 for (int i = 0; i != iter; ++i)
98 if (connector[i].connect (stream[i],
99 addr) == -1)
100 ACE_ERROR_RETURN ((LM_ERROR,
101 "Error while connecting: %p\n",
102 "client"),
103 -1);
105 if (stream[i].get_handle () == ACE_INVALID_HANDLE)
106 ACE_ERROR_RETURN ((LM_ERROR,
107 "Got invalid handles after connecting the [%d] time\n",i),
108 -1);
109 if (singleton->register_handler (stream[i].get_handle (),
110 &ph[i],
111 ACE_Event_Handler::READ_MASK) == -1)
112 ACE_ERROR_RETURN ((LM_ERROR,
113 "Registration failed\n"),
114 -1);
116 // ACE_Time_Value tv (1);
118 // while (singleton->handle_events (&tv) >= 1);
121 // Handle events moved to here to prevent this test taking best part
122 // of a minute
123 ACE_Time_Value tv (3);
125 while (singleton->handle_events (&tv) >= 1)
127 // No action.
130 // Remove the handlers to avoid the possibility of the reactor
131 // using any of them after they leave the scope (those that haven't
132 // been closed and removed already, that is).
133 for (int j = 0; j != iter; ++j)
135 singleton->remove_handler (stream[j].get_handle (),
136 ACE_Event_Handler::READ_MASK);
139 if ((iter - purged_handles) > 20)
140 ACE_ERROR_RETURN ((LM_ERROR,
141 "(%P|%t) Purging hasnt worked at all\n"),
142 -1);
144 return 0;