1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
// $Id$
// ============================================================================
//
// = LIBRARY
// tests
//
// = FILENAME
// Cache_Accept_Conn_Test.h
//
// = DESCRIPTION
// Define class needed for generating templates. IBM C++ requires this to
// be in its own file for auto template instantiation.
//
// = AUTHOR
// Kirthika Parameswaran <kirthika@cs.wustl.edu>
//
// ============================================================================
#ifndef ACE_TESTS_CACHED_ACCEPT_CONN_TEST_H
#define ACE_TESTS_CACHED_ACCEPT_CONN_TEST_H
#include "ace/Strategies.h"
#include "ace/SOCK_Connector.h"
#include "ace/SOCK_Acceptor.h"
#include "ace/SOCK_Stream.h"
#include "ace/INET_Addr.h"
#include "ace/Acceptor.h"
#include "ace/Connector.h"
#include "ace/Svc_Handler.h"
#include "ace/Synch.h"
#include "ace/Caching_Utility_T.h"
#include "ace/Cached_Connect_Strategy_T.h"
#include "ace/Handle_Gobbler.h"
class Client_Svc_Handler : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH>
{
public:
Client_Svc_Handler (ACE_Thread_Manager *t = 0);
int open (void *v = 0);
int close (u_long flags = 0);
};
class Server_Svc_Handler : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH>
{
public:
Server_Svc_Handler (ACE_Thread_Manager *t = 0);
int open (void *v = 0);
};
typedef size_t ATTRIBUTES;
typedef ACE_Pair<Client_Svc_Handler *, ATTRIBUTES>
CACHED_HANDLER;
typedef ACE_Refcounted_Hash_Recyclable<ACE_INET_Addr>
ACE_ADDR;
typedef ACE_Hash<ACE_ADDR> H_KEY;
typedef ACE_Equal_To<ACE_ADDR> C_KEYS;
typedef ACE_Hash_Map_Manager_Ex<ACE_ADDR, CACHED_HANDLER, H_KEY, C_KEYS, ACE_Null_Mutex>
HASH_MAP;
typedef ACE_Hash_Map_Iterator_Ex<ACE_ADDR, CACHED_HANDLER, H_KEY, C_KEYS, ACE_Null_Mutex>
HASH_MAP_ITERATOR;
typedef ACE_Hash_Map_Reverse_Iterator_Ex<ACE_ADDR, CACHED_HANDLER, H_KEY, C_KEYS, ACE_Null_Mutex>
HASH_MAP_REVERSE_ITERATOR;
typedef ACE_Recyclable_Handler_Cleanup_Strategy<ACE_ADDR, CACHED_HANDLER, HASH_MAP>
CLEANUP_STRATEGY;
typedef ACE_Recyclable_Handler_Caching_Utility<ACE_ADDR, CACHED_HANDLER, HASH_MAP, HASH_MAP_ITERATOR, ATTRIBUTES>
CACHING_UTILITY;
typedef ACE_LRU_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>
LRU_CACHING_STRATEGY;
#if defined (ACE_HAS_BROKEN_EXTENDED_TEMPLATES)
typedef LRU_CACHING_STRATEGY
CACHING_STRATEGY;
#else
typedef ACE_LFU_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>
LFU_CACHING_STRATEGY;
typedef ACE_FIFO_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>
FIFO_CACHING_STRATEGY;
typedef ACE_Null_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>
NULL_CACHING_STRATEGY;
typedef ACE_Caching_Strategy_Adapter<ATTRIBUTES, CACHING_UTILITY, LRU_CACHING_STRATEGY>
LRU_CACHING_STRATEGY_ADAPTER;
typedef ACE_Caching_Strategy_Adapter<ATTRIBUTES, CACHING_UTILITY, LFU_CACHING_STRATEGY>
LFU_CACHING_STRATEGY_ADAPTER;
typedef ACE_Caching_Strategy_Adapter<ATTRIBUTES, CACHING_UTILITY, FIFO_CACHING_STRATEGY>
FIFO_CACHING_STRATEGY_ADAPTER;
typedef ACE_Caching_Strategy_Adapter<ATTRIBUTES, CACHING_UTILITY, NULL_CACHING_STRATEGY>
NULL_CACHING_STRATEGY_ADAPTER;
typedef ACE_Caching_Strategy<ATTRIBUTES, CACHING_UTILITY>
CACHING_STRATEGY;
#endif /* ACE_HAS_BROKEN_EXTENDED_TEMPLATES */
typedef ACE_Strategy_Acceptor<Server_Svc_Handler, ACE_SOCK_ACCEPTOR>
ACCEPTOR;
typedef ACE_Strategy_Connector<Client_Svc_Handler, ACE_SOCK_CONNECTOR>
STRATEGY_CONNECTOR;
typedef ACE_NOOP_Creation_Strategy<Client_Svc_Handler>
NULL_CREATION_STRATEGY;
typedef ACE_NOOP_Concurrency_Strategy<Client_Svc_Handler>
NULL_ACTIVATION_STRATEGY;
typedef ACE_Cached_Connect_Strategy_Ex<Client_Svc_Handler, ACE_SOCK_CONNECTOR, CACHING_STRATEGY, ATTRIBUTES, ACE_SYNCH_NULL_MUTEX>
CACHED_CONNECT_STRATEGY;
template <class SVC_HANDLER, ACE_PEER_ACCEPTOR_1>
class Accept_Strategy : public ACE_Accept_Strategy<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>
{
public:
Accept_Strategy (CACHED_CONNECT_STRATEGY &caching_connect_strategy);
// Constructor.
int open (const ACE_PEER_ACCEPTOR_ADDR &local_addr,
int restart = 0);
// Initialize the <peer_acceptor_> with <local_addr>. If the
// process runs out of descriptors, the unsed svc_handlers from the
// CONNECTION CACHE are removed.
int accept_svc_handler (SVC_HANDLER *svc_handler);
// The default behavior delegates to the <accept> method of the
// PEER_ACCEPTOR. A check is made here for the process running out
// of file descriptors. If so, the CONNECTION CACHE is purged of
// some idle svc_handlers.
protected:
typedef ACE_Accept_Strategy<SVC_HANDLER, ACE_PEER_ACCEPTOR_2> ACCEPT_STRATEGY_BASE;
int out_of_sockets_handler (void);
// Handler for removing cached connections.
CACHED_CONNECT_STRATEGY &caching_connect_strategy_;
};
#endif /* ACE_TESTS_CACHED_ACCEPT_CONN_TEST_H */
|