Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / Asynch_Connector.h
blobaa1f763411a7627f106bbb17ff58deb5b358fb46
1 /* -*- C++ -*- */
3 //=============================================================================
4 /**
5 * @file Asynch_Connector.h
7 * @author Alexander Libman <alibman@ihug.com.au>
8 */
9 //=============================================================================
11 #ifndef ACE_ASYNCH_CONNECTOR_H
12 #define ACE_ASYNCH_CONNECTOR_H
13 #include /**/ "ace/pre.h"
15 #include /**/ "ace/config-all.h"
17 #if !defined (ACE_LACKS_PRAGMA_ONCE)
18 # pragma once
19 #endif /* ACE_LACKS_PRAGMA_ONCE */
21 #if defined (ACE_WIN32) || defined (ACE_HAS_AIO_CALLS)
22 // This only works on platforms that support async i/o.
24 #include "ace/Asynch_IO.h"
25 #include "ace/INET_Addr.h"
27 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
29 // Forward declarations
30 class ACE_Message_Block;
32 /**
33 * @class ACE_Asynch_Connector
35 * @brief This class is an example of the Connector pattern. This class
36 * will establish new connections and create new HANDLER objects to handle
37 * the new connections.
39 * Unlike the ACE_Connector, however, this class is designed to
40 * be used asynchronously with the ACE Proactor framework.
43 template <class HANDLER>
44 class ACE_Asynch_Connector : public ACE_Handler
46 public:
47 /// A do nothing constructor.
48 ACE_Asynch_Connector ();
50 /// Virtual destruction
51 virtual ~ACE_Asynch_Connector () = default;
53 /**
54 * This opens asynch connector
56 virtual int open (bool pass_addresses = false,
57 ACE_Proactor *proactor = 0,
58 bool validate_new_connection = true);
60 /// This initiates a new asynchronous connect
61 virtual int connect (const ACE_INET_Addr &remote_sap,
62 const ACE_INET_Addr &local_sap =
63 (const ACE_INET_Addr &)ACE_Addr::sap_any,
64 int reuse_addr = 1,
65 const void *act = 0);
67 /**
68 * This cancels all pending accepts operations that were issued by
69 * the calling thread.
71 * @note On Windows, this method does not cancel connect operations
72 * issued by other threads.
74 * @note On POSIX, delegates cancelation to ACE_POSIX_Asynch_Connect.
76 virtual int cancel ();
79 /**
80 * Template method to validate peer before service is opened.
81 * This method is called when the connection attempt completes,
82 * whether it succeeded or failed, if the @a validate_connection
83 * argument to @c open() was non-zero or the @c validate_new_connection()
84 * method is called to turn this feature on. The default implementation
85 * returns 0. Users can (and probably should) reimplement this method
86 * to learn about the success or failure of the connection attempt.
87 * If the connection completed successfully, this method can be used to
88 * perform validation of the peer using it's address, running an
89 * authentication procedure (such as SSL) or anything else necessary or
90 * desireable. The return value from this method determines whether or
91 * not ACE will continue opening the service or abort the connection.
93 * @param result Result of the connection acceptance. Use
94 * result.success() to determine success or failure of
95 * the connection attempt.
96 * @param remote Peer's address. If the connection failed, this object
97 * is undefined.
98 * @param local Local address connection was completed from. If the
99 * connection failed, this object is undefined.
101 * @retval -1 ACE_Asynch_Connector will close the connection, and
102 * the service will not be opened.
103 * @retval 0 Service opening will proceeed.
104 * @return Return value is ignored if the connection attempt failed.
106 virtual int validate_connection (const ACE_Asynch_Connect::Result& result,
107 const ACE_INET_Addr &remote,
108 const ACE_INET_Addr& local);
111 // These are low level tweaking methods
114 /// Set and get flag that indicates if parsing and passing of
115 /// addresses to the service_handler is necessary.
116 virtual bool pass_addresses () const;
117 virtual void pass_addresses (bool new_value);
119 /// Set and get flag that indicates if address validation is
120 /// required.
121 virtual bool validate_new_connection () const;
122 virtual void validate_new_connection (bool new_value);
124 protected:
125 /// This is called when an outstanding accept completes.
126 virtual void handle_connect (const ACE_Asynch_Connect::Result &result);
129 /// This parses the address from read buffer.
130 void parse_address (const ACE_Asynch_Connect::Result &result,
131 ACE_INET_Addr &remote_address,
132 ACE_INET_Addr &local_address);
134 /// Return the asynch Connect object.
135 ACE_Asynch_Connect & asynch_connect ();
138 * This is the template method used to create new handler.
139 * Subclasses must overwrite this method if a new handler creation
140 * strategy is required.
142 virtual HANDLER *make_handler ();
144 private:
145 /// Asynch_Connect used to make life easier :-)
146 ACE_Asynch_Connect asynch_connect_;
148 /// Flag that indicates if parsing of addresses is necessary.
149 bool pass_addresses_;
151 /// Flag that indicates if address validation is required.
152 bool validate_new_connection_;
155 ACE_END_VERSIONED_NAMESPACE_DECL
157 #include "ace/Asynch_Connector.cpp"
159 #endif /* ACE_WIN32 || ACE_HAS_AIO_CALLS */
160 #include /**/ "ace/post.h"
161 #endif /* ACE_ASYNCH_CONNECTOR_H */