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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
// $Id$
// ============================================================================
//
// = LIBRARY
// ace
//
// = FILENAME
// Asynch_Acceptor.h
//
// = AUTHOR
// Irfan Pyarali (irfan@cs.wustl.edu)
//
// ============================================================================
#ifndef ACE_ASYNCH_ACCEPTOR_H
#include "ace/pre.h"
#define ACE_ASYNCH_ACCEPTOR_H
#include "ace/OS.h"
#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */
#if defined (ACE_WIN32) || defined (ACE_HAS_AIO_CALLS)
// This only works on platforms that support async i/o.
#include "ace/Asynch_IO.h"
// Forward declarations
class ACE_Message_Block;
class ACE_INET_Addr;
template <class HANDLER>
class ACE_Asynch_Acceptor : public ACE_Handler
{
// = TITLE
// This class is an example of the Acceptor Pattern. This class
// will accept new connections and create new HANDLER to handle
// the new connections.
//
// = DESCRIPTION
// Unlike the <ACE_Acceptor>, however, this class is designed to
// be used asynchronously.
public:
ACE_Asynch_Acceptor (void);
// A do nothing constructor.
virtual ~ACE_Asynch_Acceptor (void);
// Virtual destruction
virtual int open (const ACE_INET_Addr &address,
size_t bytes_to_read = 0,
int pass_addresses = 0,
int backlog = ACE_DEFAULT_BACKLOG,
int reuse_addr = 1,
ACE_Proactor *proactor = 0,
int validate_new_connection = 0,
int reissue_accept = 1,
int number_of_initial_accepts = -1);
// This starts the listening process at the port specified by
// <address>. ACE_Asynch_Acceptor initiates the AcceptEx calls with
// <bytes_to_read>. The buffer for the initial data will be created
// by ACE_Asynch_Acceptor. This buffer will be passed to the
// handler in the <ACE_Service_Handler::open> callback. If this
// buffer is required past the <open> callback, the
// ACE_Service_Handler must copy the data. If the <pass_addresses>
// flag is set, ACE_Asynch_Acceptor will call
// <ACE_Service_Handler::addresses> before calling
// <ACE_Service_Handler::open>. The <backlog> parameter specifies
// the listen backlog and the outstanding AcceptEx calls.
// <number_of_initial_accepts> is the number of asynchronous accepts
// that are started at the end of <open>. If
// <number_of_initial_accepts> is -1, then
// <number_of_initial_accepts> is set to <backlog> and hence
// <backlog> number of asynchronous accepts are started.
virtual ACE_HANDLE get_handle (void) const;
// Get the underlying handle.
virtual void set_handle (ACE_HANDLE handle);
// Set the underlying listen handle. It is the user's responsibility
// to make sure that the old listen handle has been appropriately
// closed and the all outstanding asynchronous operations have
// either completed or have been canceled on the old listen handle.
virtual int accept (size_t bytes_to_read = 0, const void *act = 0);
// This initiates a new asynchronous accept through the <AcceptEx>
// call.
virtual int cancel (void);
// This cancels all pending accepts operations that were issued by
// the calling thread. The function does not cancel accept
// operations issued by other threads.
virtual int validate_new_connection (const ACE_INET_Addr &remote_address);
// Template method for address validation.
//
// Default implemenation always validates the remote address.
virtual int should_reissue_accept (void);
// Template method for deciding whether to reissue accept.
//
// Default implemenation always returns this->reissue_accept_.
//
// These are low level tweaking methods
//
virtual int pass_addresses (void) const;
virtual void pass_addresses (int new_value);
// Set and get flag that indicates if parsing and passing of
// addresses to the service_handler is necessary.
virtual int validate_new_connection (void) const;
virtual void validate_new_connection (int new_value);
// Set and get flag that indicates if address validation is
// required.
virtual int reissue_accept (void) const;
virtual void reissue_accept (int new_value);
// Set and get flag that indicates if a new accept should be
// reissued when a accept completes.
virtual int bytes_to_read (void) const;
virtual void bytes_to_read (int new_value);
// Set and get bytes to be read with the <accept> call.
static size_t address_size (void);
// This is required by the AcceptEx call.
protected:
virtual void handle_accept (const ACE_Asynch_Accept::Result &result);
// This is called when an outstanding accept completes.
ACE_HANDLE handle (void) const;
// Return the listen handle.
void parse_address (const ACE_Asynch_Accept::Result &result,
ACE_INET_Addr &remote_address,
ACE_INET_Addr &local_address);
// This parses the address from read buffer.
virtual HANDLER *make_handler (void);
// This is the template method used to create new handler.
// Subclasses must overwrite this method if a new handler creation
// strategy is required.
private:
ACE_HANDLE listen_handle_;
// Handle used to listen for new connections.
ACE_Asynch_Accept asynch_accept_;
// <Asynch_Accept> used to make life easier :-)
int pass_addresses_;
// Flag that indicates if parsing of addresses is necessary.
int validate_new_connection_;
// Flag that indicates if address validation is required.
int reissue_accept_;
// Flag that indicates if a new accept should be reissued when a
// accept completes.
int bytes_to_read_;
// Bytes to be read with the <accept> call.
};
#if defined (__ACE_INLINE__)
#include "ace/Asynch_Acceptor.i"
#endif /* __ACE_INLINE__ */
#if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
#include "ace/Asynch_Acceptor.cpp"
#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
#pragma implementation ("Asynch_Acceptor.cpp")
#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
#endif /* ACE_WIN32 || ACE_HAS_AIO_CALLS */
#include "ace/post.h"
#endif /* ACE_ASYNCH_ACCEPTOR_H */
|