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;
10 int purged_handles
= 0;
13 parse_args (int argc
, ACE_TCHAR
*argv
[])
15 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("h:p:"));
18 while ((c
= get_opts ()) != -1)
22 host
= get_opts
.opt_arg ();
25 port
= ACE_OS::atoi (get_opts
.opt_arg ());
29 ACE_ERROR_RETURN ((LM_ERROR
,
39 // Indicates successful parsing of the command line
43 class Purging_Handler
: public ACE_Event_Handler
46 virtual int handle_input (ACE_HANDLE h
);
47 virtual int handle_close (ACE_HANDLE h
,
52 Purging_Handler::handle_input (ACE_HANDLE
)
58 Purging_Handler::handle_close (ACE_HANDLE h
,
61 if (purged_handles
% 10 == 0)
63 "(%P|%t) purging handle [%d]\n",
72 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
74 if (parse_args (argc
, argv
) == -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
,
93 ACE_Reactor
*singleton
=
94 ACE_Reactor::instance ();
96 for (int i
= 0; i
!= iter
; ++i
)
98 if (connector
[i
].connect (stream
[i
],
100 ACE_ERROR_RETURN ((LM_ERROR
,
101 "Error while connecting: %p\n",
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
),
109 if (singleton
->register_handler (stream
[i
].get_handle (),
111 ACE_Event_Handler::READ_MASK
) == -1)
112 ACE_ERROR_RETURN ((LM_ERROR
,
113 "Registration failed\n"),
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
123 ACE_Time_Value
tv (3);
125 while (singleton
->handle_events (&tv
) >= 1)
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"),