#include <Asynch_Acceptor.h>
Inheritance diagram for ACE_Asynch_Acceptor:


Public Methods | |
| ACE_Asynch_Acceptor (void) | |
| A do nothing constructor. More... | |
| virtual | ~ACE_Asynch_Acceptor (void) |
| Virtual destruction. More... | |
| 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) |
| virtual ACE_HANDLE | get_handle (void) const |
| Get the underlying handle. More... | |
| virtual void | set_handle (ACE_HANDLE handle) |
| virtual int | accept (size_t bytes_to_read=0, const void *act=0) |
| This initiates a new asynchronous accept operation. More... | |
| virtual int | cancel (void) |
| virtual int | validate_connection (const ACE_Asynch_Accept::Result &result, const ACE_INET_Addr &remote, const ACE_INET_Addr &local) |
| virtual int | validate_new_connection (const ACE_INET_Addr &remote_address) |
| virtual int | should_reissue_accept (void) |
| virtual int | pass_addresses (void) const |
| Get flag that indicates if parsing and passing of addresses to the service_handler is necessary. More... | |
| virtual void | pass_addresses (int new_value) |
| Set flag that indicates if parsing and passing of addresses to the service_handler is necessary. More... | |
| virtual int | validate_new_connection (void) const |
| Get flag that indicates if address validation is required. More... | |
| virtual void | validate_new_connection (int new_value) |
| Set flag that indicates if address validation is required. More... | |
| virtual int | reissue_accept (void) const |
| Get flag that indicates if a new accept should be reissued when a accept completes. More... | |
| virtual void | reissue_accept (int new_value) |
| Set flag that indicates if a new accept should be reissued when a accept completes. More... | |
| virtual size_t | bytes_to_read (void) const |
| Get bytes to be read with the <accept> call. More... | |
| virtual void | bytes_to_read (size_t new_value) |
| Set bytes to be read with the <accept> call. More... | |
Static Public Methods | |
| size_t | address_size (void) |
| This is required by the AcceptEx call. More... | |
Protected Methods | |
| virtual void | handle_accept (const ACE_Asynch_Accept::Result &result) |
| This is called when an outstanding accept completes. More... | |
| ACE_HANDLE | handle (void) const |
| Return the listen handle. More... | |
| void | handle (ACE_HANDLE h) |
| Set the listen handle. More... | |
| 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. More... | |
| ACE_Asynch_Accept & | asynch_accept (void) |
| Return the asynch accept object. More... | |
| virtual HANDLER * | make_handler (void) |
Private Attributes | |
| ACE_HANDLE | listen_handle_ |
| Handle used to listen for new connections. More... | |
| ACE_Asynch_Accept | asynch_accept_ |
| <Asynch_Accept> used to make life easier :-). More... | |
| int | pass_addresses_ |
| Flag that indicates if parsing of addresses is necessary. More... | |
| int | validate_new_connection_ |
| Flag that indicates if address validation is required. More... | |
| int | reissue_accept_ |
| Flag that indicates if a new accept should be reissued when a accept completes. More... | |
| size_t | bytes_to_read_ |
| Bytes to be read with the <accept> call. More... | |
Unlike the <ACE_Acceptor>, however, this class is designed to be used asynchronously.
Definition at line 44 of file Asynch_Acceptor.h.
|
||||||||||
|
A do nothing constructor.
Definition at line 27 of file Asynch_Acceptor.cpp.
00028 : listen_handle_ (ACE_INVALID_HANDLE), 00029 pass_addresses_ (0), 00030 validate_new_connection_ (0), 00031 reissue_accept_ (1), 00032 bytes_to_read_ (0) 00033 { 00034 } |
|
||||||||||
|
Virtual destruction.
Definition at line 37 of file Asynch_Acceptor.cpp.
00038 {
00039 //this->asynch_accept_.close ();
00040
00041 // Close down the listen socket
00042 // if (this->listen_handle_ != ACE_INVALID_HANDLE)
00043 // ACE_OS::closesocket (this->listen_handle_);
00044 }
|
|
||||||||||||||||
|
This initiates a new asynchronous accept operation.
You need only call this method if the reissue_accept argument passed to Definition at line 162 of file Asynch_Acceptor.cpp. References ACE_Asynch_Accept::accept, ACE_NEW_RETURN, ACE_TRACE, address_size, asynch_accept_, bytes_to_read, and ACE_Message_Block::release. Referenced by handle_accept, and open.
00163 {
00164 ACE_TRACE ("ACE_Asynch_Acceptor<>::accept");
00165
00166 ACE_Message_Block *message_block = 0;
00167 size_t space_needed = bytes_to_read + 2 * this->address_size ();
00168
00169 // Create a new message block big enough for the addresses and data
00170 ACE_NEW_RETURN (message_block,
00171 ACE_Message_Block (space_needed),
00172 -1);
00173
00174 // Initiate asynchronous accepts
00175 if (this->asynch_accept_.accept (*message_block,
00176 bytes_to_read,
00177 ACE_INVALID_HANDLE,
00178 act) == -1)
00179 {
00180 // Cleanup on error
00181 message_block->release ();
00182 return -1;
00183 }
00184 return 0;
00185 }
|
|
||||||||||
|
This is required by the AcceptEx call.
Definition at line 401 of file Asynch_Acceptor.cpp. Referenced by accept.
00402 {
00403 return sizeof (sockaddr) + sizeof (sockaddr_in);
00404 }
|
|
||||||||||
|
Return the asynch accept object.
Definition at line 383 of file Asynch_Acceptor.cpp. References asynch_accept_.
00384 {
00385 return this->asynch_accept_;
00386 }
|
|
||||||||||
|
Set bytes to be read with the <accept> call.
Definition at line 449 of file Asynch_Acceptor.cpp. References bytes_to_read_.
00450 {
00451 this->bytes_to_read_ = new_value;
00452 }
|
|
||||||||||
|
Get bytes to be read with the <accept> call.
Definition at line 443 of file Asynch_Acceptor.cpp. References bytes_to_read_. Referenced by accept, and open.
00444 {
00445 return this->bytes_to_read_;
00446 }
|
|
||||||||||
|
Cancels all pending accepts operations issued by this object.
Definition at line 306 of file Asynch_Acceptor.cpp. References ACE_TRACE, asynch_accept_, ACE_Asynch_Operation::cancel, and listen_handle_.
00307 {
00308 ACE_TRACE ("ACE_Asynch_Acceptor<>::cancel");
00309
00310 // All I/O operations that are canceled will complete with the error
00311 // ERROR_OPERATION_ABORTED. All completion notifications for the I/O
00312 // operations will occur normally.
00313 #if (defined (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0)) \
00314 && ( (defined (_MSC_VER) && (_MSC_VER > 1020)) \
00315 || (defined (__BORLANDC__) && (__BORLANDC__ >= 0x530)))
00316 return (int) ::CancelIo (this->listen_handle_);
00317 #else
00318 //ACE_NOTSUP_RETURN (-1);
00319 // Supported now
00320 return this->asynch_accept_.cancel();
00321
00322 #endif /* (defined (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0)) && ((defined (_MSC_VER) && (_MSC_VER > 1020)) || (defined (__BORLANDC__) && (__BORLANDC__ >= 0x530))) */
00323 }
|
|
||||||||||
|
Get the underlying handle.
Definition at line 156 of file Asynch_Acceptor.cpp. References listen_handle_.
00157 {
00158 return this->listen_handle_;
00159 }
|
|
||||||||||
|
Set the listen handle.
Reimplemented from ACE_Handler. Definition at line 377 of file Asynch_Acceptor.cpp. References ACE_Handler::handle.
00378 {
00379 ACE_Handler::handle (h);
00380 }
|
|
||||||||||
|
Return the listen handle.
Reimplemented from ACE_Handler. Definition at line 371 of file Asynch_Acceptor.cpp. References listen_handle_.
00372 {
00373 return this->listen_handle_;
00374 }
|
|
||||||||||
|
This is called when an outstanding accept completes.
Reimplemented from ACE_Handler. Definition at line 188 of file Asynch_Acceptor.cpp. References accept, ACE_Asynch_Accept::Result::accept_handle, ACE_TRACE, ACE_Asynch_Result::act, ACE_OS::closesocket, listen_handle_, make_handler, ACE_Asynch_Accept::Result::message_block, parse_address, pass_addresses_, ACE_Message_Block::release, ACE_OS::setsockopt, should_reissue_accept, ACE_Asynch_Result::success, validate_connection, validate_new_connection, and validate_new_connection_.
00189 {
00190 #if (defined (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0)) || (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)) || defined (ACE_HAS_AIO_CALLS)
00191
00192 ACE_TRACE ("ACE_Asynch_Acceptor<>::handle_accept");
00193
00194 // Variable for error tracking
00195 int error = 0;
00196
00197 // If the asynchronous accept fails.
00198 if (!result.success () ||
00199 result.accept_handle() == ACE_INVALID_HANDLE )
00200 {
00201 error = 1;
00202 }
00203
00204 #if !defined (ACE_HAS_AIO_CALLS)
00205 // In order to use accept handle with other Window Sockets 1.1
00206 // functions, we call the setsockopt function with the
00207 // SO_UPDATE_ACCEPT_CONTEXT option. This option initializes the
00208 // socket so that other Windows Sockets routines to access the
00209 // socket correctly.
00210 if (!error &&
00211 ACE_OS::setsockopt (result.accept_handle (),
00212 SOL_SOCKET,
00213 SO_UPDATE_ACCEPT_CONTEXT,
00214 (char *) &this->listen_handle_,
00215 sizeof (this->listen_handle_)) == -1)
00216 {
00217 error = 1;
00218 }
00219 #endif /* ACE_HAS_AIO_CALLS */
00220
00221 // Parse address.
00222 ACE_INET_Addr local_address;
00223 ACE_INET_Addr remote_address;
00224 if (!error &&
00225 (this->validate_new_connection_ || this->pass_addresses_))
00226 // Parse the addresses.
00227 this->parse_address (result,
00228 remote_address,
00229 local_address);
00230
00231 // Validate remote address
00232 if (!error &&
00233 this->validate_new_connection_ &&
00234 (this->validate_connection (result, remote_address, local_address) == -1
00235 || this->validate_new_connection (remote_address) == -1))
00236 {
00237 error = 1;
00238 }
00239
00240 HANDLER *new_handler = 0;
00241 if (!error)
00242 {
00243 // The Template method
00244 new_handler = this->make_handler ();
00245 if (new_handler == 0)
00246 {
00247 error = 1;
00248 }
00249 }
00250
00251 // If no errors
00252 if (!error)
00253 {
00254 // Update the Proactor.
00255 new_handler->proactor (this->proactor ());
00256
00257 // Pass the addresses
00258 if (this->pass_addresses_)
00259 new_handler->addresses (remote_address,
00260 local_address);
00261
00262 // Pass the ACT
00263 if (result.act () != 0)
00264 new_handler->act (result.act ());
00265
00266 // Set up the handler's new handle value
00267 new_handler->handle (result.accept_handle ());
00268
00269 // Initiate the handler
00270 new_handler->open (result.accept_handle (),
00271 result.message_block ());
00272 }
00273
00274 // On failure, no choice but to close the socket
00275 if (error &&
00276 result.accept_handle() != ACE_INVALID_HANDLE )
00277 ACE_OS::closesocket (result.accept_handle ());
00278
00279 // Delete the dynamically allocated message_block
00280 result.message_block ().release ();
00281
00282 // Start off another asynchronous accept to keep the backlog going
00283 if (this->should_reissue_accept ())
00284 this->accept (this->bytes_to_read_);
00285 #endif /* (defined (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0)) || (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)) || defined (ACE_HAS_AIO_CALLS */
00286 }
|
|
||||||||||
|
This is the template method used to create new handler. Subclasses must overwrite this method if a new handler creation strategy is required. Definition at line 389 of file Asynch_Acceptor.cpp. References ACE_NEW_RETURN. Referenced by handle_accept.
00390 {
00391 // Default behavior
00392 HANDLER *handler = 0;
00393 ACE_NEW_RETURN (handler,
00394 HANDLER,
00395 0);
00396 return handler;
00397 }
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
Definition at line 47 of file Asynch_Acceptor.cpp. References accept, ACE_ERROR_RETURN, ACE_LIB_TEXT, ACE_TRACE, asynch_accept_, ACE_OS::bind, ACE_Sock_Connect::bind_port, bytes_to_read, bytes_to_read_, ACE_INET_Addr::get_addr, ACE_Addr::get_size, ACE_Addr::get_type, ACE_OS::listen, listen_handle_, LM_ERROR, ACE_Asynch_Accept::open, pass_addresses, pass_addresses_, ACE_Handler::proactor, reissue_accept, reissue_accept_, ACE_OS::setsockopt, ACE_OS::socket, validate_new_connection, and validate_new_connection_.
00056 {
00057 ACE_TRACE ("ACE_Asynch_Acceptor<>::open");
00058
00059 this->proactor (proactor);
00060 this->pass_addresses_ = pass_addresses;
00061 this->bytes_to_read_ = bytes_to_read;
00062 this->validate_new_connection_ = validate_new_connection;
00063 this->reissue_accept_ = reissue_accept;
00064
00065 // Create the listener socket
00066 this->listen_handle_ = ACE_OS::socket (address.get_type (), SOCK_STREAM, 0);
00067 if (this->listen_handle_ == ACE_INVALID_HANDLE)
00068 ACE_ERROR_RETURN ((LM_ERROR,
00069 ACE_LIB_TEXT ("%p\n"),
00070 ACE_LIB_TEXT ("ACE_OS::socket")),
00071 -1);
00072 // Initialize the ACE_Asynch_Accept
00073 if (this->asynch_accept_.open (*this,
00074 this->listen_handle_,
00075 0,
00076 this->proactor ()) == -1)
00077 ACE_ERROR_RETURN ((LM_ERROR,
00078 ACE_LIB_TEXT ("%p\n"),
00079 ACE_LIB_TEXT ("ACE_Asynch_Accept::open")),
00080 -1);
00081 if (reuse_addr)
00082 {
00083 // Reuse the address
00084 int one = 1;
00085 if (ACE_OS::setsockopt (this->listen_handle_,
00086 SOL_SOCKET,
00087 SO_REUSEADDR,
00088 (const char*) &one,
00089 sizeof one) == -1)
00090 ACE_ERROR_RETURN ((LM_ERROR,
00091 ACE_LIB_TEXT ("%p\n"),
00092 ACE_LIB_TEXT ("ACE_OS::setsockopt")),
00093 -1);
00094 }
00095
00096 // If port is not specified, bind to any port.
00097 static ACE_INET_Addr sa (ACE_sap_any_cast (const ACE_INET_Addr &));
00098
00099 if (address == sa &&
00100 ACE_Sock_Connect::bind_port (this->listen_handle_) == -1)
00101 ACE_ERROR_RETURN ((LM_ERROR,
00102 ACE_LIB_TEXT ("%p\n"),
00103 ACE_LIB_TEXT ("ACE::bind_port")),
00104 -1);
00105
00106 // Bind to the specified port.
00107 if (ACE_OS::bind (this->listen_handle_,
00108 ACE_reinterpret_cast (sockaddr *,
00109 address.get_addr ()),
00110 address.get_size ()) == -1)
00111 ACE_ERROR_RETURN ((LM_ERROR,
00112 "%p\n",
00113 "ACE_OS::bind"),
00114 -1);
00115
00116 // Start listening.
00117 if (ACE_OS::listen (this->listen_handle_, backlog) == -1)
00118 ACE_ERROR_RETURN ((LM_ERROR,
00119 "%p\n",
00120 "ACE_OS::listen"),
00121 -1);
00122
00123 // For the number of <intial_accepts>.
00124 if (number_of_initial_accepts == -1)
00125 number_of_initial_accepts = backlog;
00126
00127 for (int i = 0; i < number_of_initial_accepts; i++)
00128 // Initiate accepts.
00129 if (this->accept (bytes_to_read) == -1)
00130 ACE_ERROR_RETURN ((LM_ERROR,
00131 "%p\n",
00132 "ACE_Asynch_Acceptor::accept"),
00133 -1);
00134 return 0;
00135 }
|
|
||||||||||||||||||||
|
This parses the address from read buffer.
Definition at line 326 of file Asynch_Acceptor.cpp. References ACE_Asynch_Accept::Result::accept_handle, ACE_TRACE, ENOTSUP, ACE_SOCK::get_local_addr, ACE_SOCK::get_remote_addr, ACE_Asynch_Accept::Result::message_block, ACE_Message_Block::rd_ptr, and ACE_INET_Addr::set. Referenced by handle_accept.
00330 {
00331 ACE_TRACE ("ACE_Asynch_Acceptor<>::parse_address");
00332
00333 #if defined (ACE_HAS_AIO_CALLS)
00334
00335 // Use an ACE_SOCK to get the addresses - it knows how to deal with
00336 // ACE_INET_Addr objects and get IPv4/v6 addresses.
00337 ACE_SOCK_Stream str (result.accept_handle ());
00338 str.get_local_addr (local_address);
00339 str.get_remote_addr (remote_address);
00340
00341 #elif (defined (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0)) || (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0))
00342
00343 ACE_Message_Block &message_block = result.message_block ();
00344
00345 sockaddr *local_addr = 0;
00346 sockaddr *remote_addr = 0;
00347 int local_size = 0;
00348 int remote_size = 0;
00349
00350 ::GetAcceptExSockaddrs (message_block.rd_ptr (),
00351 ACE_static_cast (DWORD, this->bytes_to_read_),
00352 ACE_static_cast (DWORD, this->address_size ()),
00353 ACE_static_cast (DWORD, this->address_size ()),
00354 &local_addr,
00355 &local_size,
00356 &remote_addr,
00357 &remote_size);
00358
00359 local_address.set (ACE_reinterpret_cast (sockaddr_in *, local_addr),
00360 local_size);
00361 remote_address.set (ACE_reinterpret_cast (sockaddr_in *, remote_addr),
00362 remote_size);
00363 #else
00364 // just in case
00365 errno = ENOTSUP;
00366 #endif /* (defined (ACE_HAS_WINNT4) && (ACE_HAS_WINNT4 != 0)) || (defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)) */
00367 return;
00368 }
|
|
||||||||||
|
Set flag that indicates if parsing and passing of addresses to the service_handler is necessary.
Definition at line 413 of file Asynch_Acceptor.cpp. References pass_addresses_.
00414 {
00415 this->pass_addresses_ = new_value;
00416 }
|
|
||||||||||
|
Get flag that indicates if parsing and passing of addresses to the service_handler is necessary.
Definition at line 407 of file Asynch_Acceptor.cpp. References pass_addresses_. Referenced by open.
00408 {
00409 return this->pass_addresses_;
00410 }
|
|
||||||||||
|
Set flag that indicates if a new accept should be reissued when a accept completes.
Definition at line 437 of file Asynch_Acceptor.cpp. References reissue_accept_.
00438 {
00439 this->reissue_accept_ = new_value;
00440 }
|
|
||||||||||
|
Get flag that indicates if a new accept should be reissued when a accept completes.
Definition at line 431 of file Asynch_Acceptor.cpp. References reissue_accept_. Referenced by open.
00432 {
00433 return this->reissue_accept_;
00434 }
|
|
||||||||||
|
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. Definition at line 138 of file Asynch_Acceptor.cpp. References ACE_ERROR, ACE_LIB_TEXT, ACE_TRACE, asynch_accept_, listen_handle_, LM_ERROR, and ACE_Asynch_Accept::open.
00139 {
00140 ACE_TRACE ("ACE_Asynch_Acceptor<>::set_handle");
00141
00142 // Take ownership of the <listen_handle>
00143 this->listen_handle_ = listen_handle;
00144
00145 // Reinitialize the ACE_Asynch_Accept
00146 if (this->asynch_accept_.open (*this,
00147 this->listen_handle_,
00148 0,
00149 this->proactor ()) == -1)
00150 ACE_ERROR ((LM_ERROR,
00151 ACE_LIB_TEXT ("%p\n"),
00152 ACE_LIB_TEXT ("ACE_Asynch_Accept::open")));
00153 }
|
|
||||||||||
|
Template method for deciding whether to reissue accept. This hook method is called after each accept completes to decide if another accept should be initiated. If the method returns a non-zero value, another accept is initiated.
The default implemenation always returns the value passed as the Definition at line 455 of file Asynch_Acceptor.cpp. References reissue_accept_. Referenced by handle_accept.
00456 {
00457 return this->reissue_accept_;
00458 }
|
|
||||||||||||||||||||
|
Template method to validate peer before service is opened. This method is called after a new connection is accepted if the validate_connection argument to
Definition at line 290 of file Asynch_Acceptor.cpp. Referenced by handle_accept.
00293 {
00294 // Default implementation always validates the remote address.
00295 return 0;
00296 }
|
|
||||||||||
|
Set flag that indicates if address validation is required.
Definition at line 425 of file Asynch_Acceptor.cpp. References validate_new_connection_.
00426 {
00427 this->validate_new_connection_ = new_value;
00428 }
|
|
||||||||||
|
Get flag that indicates if address validation is required.
Definition at line 419 of file Asynch_Acceptor.cpp. References validate_new_connection_. Referenced by handle_accept.
00420 {
00421 return this->validate_new_connection_;
00422 }
|
|
||||||||||
|
This hook method is called after a connection is accepted if so specified on the call to the The default implemenation always return 0. Definition at line 299 of file Asynch_Acceptor.cpp. Referenced by open.
00300 {
00301 // Default implementation always validates the remote address.
00302 return 0;
00303 }
|
|
|||||
|
<Asynch_Accept> used to make life easier :-).
Definition at line 260 of file Asynch_Acceptor.h. Referenced by accept, asynch_accept, cancel, open, and set_handle. |
|
|||||
|
Bytes to be read with the <accept> call.
Definition at line 273 of file Asynch_Acceptor.h. Referenced by bytes_to_read, and open. |
|
|||||
|
Handle used to listen for new connections.
Definition at line 257 of file Asynch_Acceptor.h. Referenced by cancel, get_handle, handle, handle_accept, open, and set_handle. |
|
|||||
|
Flag that indicates if parsing of addresses is necessary.
Definition at line 263 of file Asynch_Acceptor.h. Referenced by handle_accept, open, and pass_addresses. |
|
|||||
|
Flag that indicates if a new accept should be reissued when a accept completes.
Definition at line 270 of file Asynch_Acceptor.h. Referenced by open, reissue_accept, and should_reissue_accept. |
|
|||||
|
Flag that indicates if address validation is required.
Definition at line 266 of file Asynch_Acceptor.h. Referenced by handle_accept, open, and validate_new_connection. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002