Also use Objects as part of an operation but as a result don't generate Any operation...
[ACE_TAO.git] / ACE / ace / Asynch_Connector.h
blob584c29fb0dd9f26fce4e1927a2fa8896319758c6
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)) && !defined(ACE_HAS_WINCE)
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 (void);
50 /// Virtual destruction
51 virtual ~ACE_Asynch_Connector (void);
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 (void);
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 (void) 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 (void) const;
122 virtual void validate_new_connection (bool new_value);
124 protected:
126 /// This is called when an outstanding accept completes.
127 virtual void handle_connect (const ACE_Asynch_Connect::Result &result);
130 /// This parses the address from read buffer.
131 void parse_address (const ACE_Asynch_Connect::Result &result,
132 ACE_INET_Addr &remote_address,
133 ACE_INET_Addr &local_address);
135 /// Return the asynch Connect object.
136 ACE_Asynch_Connect & asynch_connect (void);
139 * This is the template method used to create new handler.
140 * Subclasses must overwrite this method if a new handler creation
141 * strategy is required.
143 virtual HANDLER *make_handler (void);
145 private:
146 /// Asynch_Connect used to make life easier :-)
147 ACE_Asynch_Connect asynch_connect_;
149 /// Flag that indicates if parsing of addresses is necessary.
150 bool pass_addresses_;
152 /// Flag that indicates if address validation is required.
153 bool validate_new_connection_;
156 ACE_END_VERSIONED_NAMESPACE_DECL
158 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
159 #include "ace/Asynch_Connector.cpp"
160 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
162 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
163 #pragma implementation ("Asynch_Connector.cpp")
164 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
166 #endif /* ACE_WIN32 || ACE_HAS_AIO_CALLS */
167 #include /**/ "ace/post.h"
168 #endif /* ACE_ASYNCH_CONNECTOR_H */