2 //=============================================================================
4 * @file Cached_Accept_Conn_Test.h
6 * Define class needed for generating templates.
8 * @author Kirthika Parameswaran <kirthika@cs.wustl.edu>
10 //=============================================================================
13 #ifndef ACE_TESTS_CACHED_ACCEPT_CONN_TEST_H
14 #define ACE_TESTS_CACHED_ACCEPT_CONN_TEST_H
16 #include "ace/SOCK_Connector.h"
17 #include "ace/SOCK_Acceptor.h"
18 #include "ace/SOCK_Stream.h"
19 #include "ace/INET_Addr.h"
20 #include "ace/Acceptor.h"
21 #include "ace/Connector.h"
22 #include "ace/Svc_Handler.h"
23 #include "ace/Caching_Utility_T.h"
24 #include "ace/Cached_Connect_Strategy_T.h"
25 #include "ace/Handle_Gobbler.h"
27 class Client_Svc_Handler
: public ACE_Svc_Handler
<ACE_SOCK_STREAM
, ACE_NULL_SYNCH
>
30 Client_Svc_Handler (ACE_Thread_Manager
*t
= 0);
31 int open (void *v
= 0);
32 int close (u_long flags
= 0);
35 class Server_Svc_Handler
: public ACE_Svc_Handler
<ACE_SOCK_STREAM
, ACE_NULL_SYNCH
>
38 Server_Svc_Handler (ACE_Thread_Manager
*t
= 0);
39 int open (void *v
= 0);
42 typedef size_t ATTRIBUTES
;
43 typedef std::pair
<Client_Svc_Handler
*, ATTRIBUTES
>
45 typedef ACE_Refcounted_Hash_Recyclable
<ACE_INET_Addr
>
47 typedef ACE_Hash
<ACE_ADDR
> H_KEY
;
48 typedef ACE_Equal_To
<ACE_ADDR
> C_KEYS
;
50 typedef ACE_Hash_Map_Manager_Ex
<ACE_ADDR
, CACHED_HANDLER
, H_KEY
, C_KEYS
, ACE_Null_Mutex
>
52 typedef ACE_Hash_Map_Iterator_Ex
<ACE_ADDR
, CACHED_HANDLER
, H_KEY
, C_KEYS
, ACE_Null_Mutex
>
54 typedef ACE_Hash_Map_Reverse_Iterator_Ex
<ACE_ADDR
, CACHED_HANDLER
, H_KEY
, C_KEYS
, ACE_Null_Mutex
>
55 HASH_MAP_REVERSE_ITERATOR
;
57 typedef ACE_Recyclable_Handler_Cleanup_Strategy
<ACE_ADDR
, CACHED_HANDLER
, HASH_MAP
>
59 typedef ACE_Recyclable_Handler_Caching_Utility
<ACE_ADDR
, CACHED_HANDLER
, HASH_MAP
, HASH_MAP_ITERATOR
, ATTRIBUTES
>
62 typedef ACE_LRU_Caching_Strategy
<ATTRIBUTES
, CACHING_UTILITY
>
65 typedef ACE_LFU_Caching_Strategy
<ATTRIBUTES
, CACHING_UTILITY
>
67 typedef ACE_FIFO_Caching_Strategy
<ATTRIBUTES
, CACHING_UTILITY
>
68 FIFO_CACHING_STRATEGY
;
69 typedef ACE_Null_Caching_Strategy
<ATTRIBUTES
, CACHING_UTILITY
>
70 NULL_CACHING_STRATEGY
;
71 typedef ACE_Caching_Strategy_Adapter
<ATTRIBUTES
, CACHING_UTILITY
, LRU_CACHING_STRATEGY
>
72 LRU_CACHING_STRATEGY_ADAPTER
;
73 typedef ACE_Caching_Strategy_Adapter
<ATTRIBUTES
, CACHING_UTILITY
, LFU_CACHING_STRATEGY
>
74 LFU_CACHING_STRATEGY_ADAPTER
;
75 typedef ACE_Caching_Strategy_Adapter
<ATTRIBUTES
, CACHING_UTILITY
, FIFO_CACHING_STRATEGY
>
76 FIFO_CACHING_STRATEGY_ADAPTER
;
77 typedef ACE_Caching_Strategy_Adapter
<ATTRIBUTES
, CACHING_UTILITY
, NULL_CACHING_STRATEGY
>
78 NULL_CACHING_STRATEGY_ADAPTER
;
79 typedef ACE_Caching_Strategy
<ATTRIBUTES
, CACHING_UTILITY
>
82 typedef ACE_Strategy_Acceptor
<Server_Svc_Handler
, ACE_SOCK_ACCEPTOR
>
85 typedef ACE_Strategy_Connector
<Client_Svc_Handler
, ACE_SOCK_CONNECTOR
>
88 typedef ACE_NOOP_Creation_Strategy
<Client_Svc_Handler
>
89 NULL_CREATION_STRATEGY
;
91 typedef ACE_NOOP_Concurrency_Strategy
<Client_Svc_Handler
>
92 NULL_ACTIVATION_STRATEGY
;
94 typedef ACE_Cached_Connect_Strategy_Ex
<Client_Svc_Handler
, ACE_SOCK_CONNECTOR
, CACHING_STRATEGY
, ATTRIBUTES
, ACE_SYNCH_NULL_MUTEX
>
95 CACHED_CONNECT_STRATEGY
;
97 template <class SVC_HANDLER
, ACE_PEER_ACCEPTOR_1
>
98 class Accept_Strategy
: public ACE_Accept_Strategy
<SVC_HANDLER
, ACE_PEER_ACCEPTOR_2
>
102 Accept_Strategy (CACHED_CONNECT_STRATEGY
&caching_connect_strategy
);
105 * Initialize the <peer_acceptor_> with <local_addr>. If the
106 * process runs out of descriptors, the unsed svc_handlers from the
107 * CONNECTION CACHE are removed.
109 int open (const ACE_PEER_ACCEPTOR_ADDR
&local_addr
,
110 bool restart
= false);
113 * The default behavior delegates to the <accept> method of the
114 * PEER_ACCEPTOR. A check is made here for the process running out
115 * of file descriptors. If so, the CONNECTION CACHE is purged of
116 * some idle svc_handlers.
118 int accept_svc_handler (SVC_HANDLER
*svc_handler
);
121 typedef ACE_Accept_Strategy
<SVC_HANDLER
, ACE_PEER_ACCEPTOR_2
> ACCEPT_STRATEGY_BASE
;
123 /// Handler for removing cached connections.
124 int out_of_sockets_handler ();
126 CACHED_CONNECT_STRATEGY
&caching_connect_strategy_
;
129 #endif /* ACE_TESTS_CACHED_ACCEPT_CONN_TEST_H */