00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file SOCK_SEQPACK_Connector.h 00006 * 00007 * SOCK_SEQPACK_Connector.h,v 4.12 2005/11/26 03:13:13 ossama Exp 00008 * 00009 * @author Patrick J. Lardieri <plardier@atl.lmco.com> 00010 * @author Gaurav Naik, Lockheed Martin ATL 00011 * @author based on SOCK_STREAM_Connector 00012 * by Douglas C. Schmidt <schmidt@dre.vanderbilt.edu> 00013 * 00014 */ 00015 //============================================================================= 00016 00017 #ifndef ACE_SOCK_SEQPACK_CONNECTOR_H 00018 #define ACE_SOCK_SEQPACK_CONNECTOR_H 00019 00020 #include /**/ "ace/pre.h" 00021 00022 #include "ace/ACE_export.h" 00023 00024 #include "ace/SOCK_SEQPACK_Association.h" 00025 #include "ace/Multihomed_INET_Addr.h" 00026 00027 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00028 # pragma once 00029 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00030 00031 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00032 00033 // Forward declarations. 00034 class ACE_Time_Value; 00035 00036 /** 00037 * @class ACE_SOCK_SEQPACK_Connector 00038 * 00039 * @brief Defines a factory that actively connects to a remote IP 00040 * address and TCP port, creating a new @c ACE_SOCK_SEQPACK_Association object. 00041 * 00042 * The @c ACE_SOCK_SEQPACK_Connector doesn't have a socket of its own, 00043 * i.e., it simply "borrows" the one from the @c ACE_SOCK_SEQPACK_Association 00044 * that's being connected. The reason for this is that the 00045 * underlying socket API doesn't use a factory socket to connect 00046 * data mode sockets. Therefore, there's no need to inherit 00047 * @c ACE_SOCK_SEQPACK_Connector from @c ACE_SOCK. A nice side-effect of 00048 * this is that @c ACE_SOCK_SEQPACK_Connector objects do not store state so 00049 * they can be used reentrantly in multithreaded programs. 00050 */ 00051 class ACE_Export ACE_SOCK_SEQPACK_Connector 00052 { 00053 public: 00054 // = Initialization and termination methods. 00055 /// Default constructor. 00056 ACE_SOCK_SEQPACK_Connector (void); 00057 00058 /** 00059 * Actively connect to a peer, producing a connected @c ACE_SOCK_SEQPACK_Association 00060 * object if the connection succeeds. 00061 * 00062 * @param new_association The @c ACE_SOCK_SEQPACK_Association object that will be connected 00063 * to the peer. 00064 * @param remote_sap The address that we are trying to connect to. 00065 * The protocol family of @c remote_sap is used for 00066 * the connected socket. That is, if @c remote_sap 00067 * contains an IPv6 address, a socket with family 00068 * PF_INET6 will be used, else it will be PF_INET. 00069 * @param timeout Pointer to an @c ACE_Time_Value object with amount 00070 * of time to wait to connect. If the pointer is 0 00071 * then the call blocks until the connection attempt 00072 * is complete, whether it succeeds or fails. If 00073 * *timeout == {0, 0} then the connection is done 00074 * using nonblocking mode. In this case, if the 00075 * connection can't be made immediately, this method 00076 * returns -1 and errno == EWOULDBLOCK. 00077 * If *timeout > {0, 0} then this is the maximum amount 00078 * of time to wait before timing out; if the specified 00079 * amount of time passes before the connection is made, 00080 * this method returns -1 and errno == ETIME. Note 00081 * the difference between this case and when a blocking 00082 * connect is attmpted that TCP times out - in the latter 00083 * case, errno will be ETIMEDOUT. 00084 * @param local_sap (optional) The local address to bind to. If it's 00085 * the default value of @c ACE_Addr::sap_any then the 00086 * OS will choose an unused port. 00087 * @param reuse_addr (optional) If the value is 1, the local address 00088 * (@c local_sap) is reused, even if it hasn't been 00089 * cleaned up yet. 00090 * @param flags Ignored. 00091 * @param perms Ignored. 00092 * @param protocol (optional) If value is 0, default SOCK_STREAM 00093 * protocol is selected by kernel (typically TCP). 00094 * 00095 * @return Returns 0 if the connection succeeds. If it fails, 00096 * -1 is returned and errno contains a specific error 00097 * code. 00098 */ 00099 ACE_SOCK_SEQPACK_Connector (ACE_SOCK_SEQPACK_Association &new_association, 00100 const ACE_Addr &remote_sap, 00101 const ACE_Time_Value *timeout = 0, 00102 const ACE_Addr &local_sap = ACE_Addr::sap_any, 00103 int reuse_addr = 0, 00104 int flags = 0, 00105 int perms = 0, 00106 int protocol = 132); 00107 00108 /** 00109 * Actively connect to a peer, producing a connected @c ACE_SOCK_SEQPACK_Association 00110 * object if the connection succeeds. 00111 * 00112 * @param new_association The @c ACE_SOCK_SEQPACK_Association object that will be connected 00113 * to the peer. 00114 * @param remote_sap The address that we are trying to connect to. 00115 * The protocol family of @c remote_sap is used for 00116 * the connected socket. That is, if @c remote_sap 00117 * contains an IPv6 address, a socket with family 00118 * PF_INET6 will be used, else it will be PF_INET. 00119 * @param timeout Pointer to an @c ACE_Time_Value object with amount 00120 * of time to wait to connect. If the pointer is 0 00121 * then the call blocks until the connection attempt 00122 * is complete, whether it succeeds or fails. If 00123 * *timeout == {0, 0} then the connection is done 00124 * using nonblocking mode. In this case, if the 00125 * connection can't be made immediately, this method 00126 * returns -1 and errno == EWOULDBLOCK. 00127 * If *timeout > {0, 0} then this is the maximum amount 00128 * of time to wait before timing out; if the specified 00129 * amount of time passes before the connection is made, 00130 * this method returns -1 and errno == ETIME. Note 00131 * the difference between this case and when a blocking 00132 * connect is attmpted that TCP times out - in the latter 00133 * case, errno will be ETIMEDOUT. 00134 * @param local_sap (optional) The set of local addresses for SCTP to 00135 * bind to. 00136 * @param reuse_addr (optional) If the value is 1, the local address 00137 * (@c local_sap) is reused, even if it hasn't been 00138 * cleaned up yet. 00139 * @param flags Ignored. 00140 * @param perms Ignored. 00141 * @param protocol (optional) If value is 0, default SOCK_STREAM 00142 * protocol is selected by kernel (typically TCP). 00143 * 00144 * @return Returns 0 if the connection succeeds. If it fails, 00145 * -1 is returned and errno contains a specific error 00146 * code. 00147 */ 00148 ACE_SOCK_SEQPACK_Connector (ACE_SOCK_SEQPACK_Association &new_association, 00149 const ACE_Addr &remote_sap, 00150 const ACE_Time_Value *timeout, 00151 const ACE_Multihomed_INET_Addr &local_sap, 00152 int reuse_addr = 0, 00153 int flags = 0, 00154 int perms = 0, 00155 int protocol = 132); 00156 00157 /** 00158 * Actively connect to a peer, producing a connected @c ACE_SOCK_SEQPACK_Association 00159 * object if the connection succeeds. 00160 * 00161 * @param new_association The @c ACE_SOCK_SEQPACK_Association object that will be connected 00162 * to the peer. 00163 * @param remote_sap The address that we are trying to connect to. 00164 * The protocol family of @c remote_sap is used for 00165 * the connected socket. That is, if @c remote_sap 00166 * contains an IPv6 address, a socket with family 00167 * PF_INET6 will be used, else it will be PF_INET. 00168 * @param timeout Pointer to an @c ACE_Time_Value object with amount 00169 * of time to wait to connect. If the pointer is 0 00170 * then the call blocks until the connection attempt 00171 * is complete, whether it succeeds or fails. If 00172 * *timeout == {0, 0} then the connection is done 00173 * using nonblocking mode. In this case, if the 00174 * connection can't be made immediately, this method 00175 * returns -1 and errno == EWOULDBLOCK. 00176 * If *timeout > {0, 0} then this is the maximum amount 00177 * of time to wait before timing out; if the specified 00178 * amount of time passes before the connection is made, 00179 * this method returns -1 and errno == ETIME. Note 00180 * the difference between this case and when a blocking 00181 * connect is attmpted that TCP times out - in the latter 00182 * case, errno will be ETIMEDOUT. 00183 * @param local_sap (optional) The local address to bind to. If it's 00184 * the default value of @c ACE_Addr::sap_any then the 00185 * OS will choose an unused port. 00186 * @param reuse_addr (optional) If the value is 1, the local address 00187 * (@c local_sap) is reused, even if it hasn't been 00188 * cleaned up yet. 00189 * @param flags Ignored. 00190 * @param perms Ignored. 00191 * @param protocol (optional) If value is 0, default SOCK_STREAM 00192 * protocol is selected by kernel (typically TCP). 00193 * 00194 * @return Returns 0 if the connection succeeds. If it fails, 00195 * -1 is returned and errno contains a specific error 00196 * code. 00197 */ 00198 int connect (ACE_SOCK_SEQPACK_Association &new_association, 00199 const ACE_Addr &remote_sap, 00200 const ACE_Time_Value *timeout = 0, 00201 const ACE_Addr &local_sap = ACE_Addr::sap_any, 00202 int reuse_addr = 0, 00203 int flags = 0, 00204 int perms = 0, 00205 int protocol = 132); 00206 00207 /** 00208 * Actively connect to a peer, producing a connected @c ACE_SOCK_SEQPACK_Association 00209 * object if the connection succeeds. 00210 * 00211 * @param new_association The @c ACE_SOCK_SEQPACK_Association object that will be connected 00212 * to the peer. 00213 * @param remote_sap The address that we are trying to connect to. 00214 * The protocol family of @c remote_sap is used for 00215 * the connected socket. That is, if @c remote_sap 00216 * contains an IPv6 address, a socket with family 00217 * PF_INET6 will be used, else it will be PF_INET. 00218 * @param timeout Pointer to an @c ACE_Time_Value object with amount 00219 * of time to wait to connect. If the pointer is 0 00220 * then the call blocks until the connection attempt 00221 * is complete, whether it succeeds or fails. If 00222 * *timeout == {0, 0} then the connection is done 00223 * using nonblocking mode. In this case, if the 00224 * connection can't be made immediately, this method 00225 * returns -1 and errno == EWOULDBLOCK. 00226 * If *timeout > {0, 0} then this is the maximum amount 00227 * of time to wait before timing out; if the specified 00228 * amount of time passes before the connection is made, 00229 * this method returns -1 and errno == ETIME. Note 00230 * the difference between this case and when a blocking 00231 * connect is attmpted that TCP times out - in the latter 00232 * case, errno will be ETIMEDOUT. 00233 * @param local_sap (optional) The set of local addresses for SCTP to 00234 * bind to. 00235 * @param reuse_addr (optional) If the value is 1, the local address 00236 * (@c local_sap) is reused, even if it hasn't been 00237 * cleaned up yet. 00238 * @param flags Ignored. 00239 * @param perms Ignored. 00240 * @param protocol (optional) If value is 0, default SOCK_STREAM 00241 * protocol is selected by kernel (typically TCP). 00242 * 00243 * @return Returns 0 if the connection succeeds. If it fails, 00244 * -1 is returned and errno contains a specific error 00245 * code. 00246 */ 00247 00248 int connect (ACE_SOCK_SEQPACK_Association &new_association, 00249 const ACE_Addr &remote_sap, 00250 const ACE_Time_Value *timeout, 00251 const ACE_Multihomed_INET_Addr &local_sap, 00252 int reuse_addr = 0, 00253 int flags = 0, 00254 int perms = 0, 00255 int protocol = 132); 00256 00257 /// Default dtor. 00258 ~ACE_SOCK_SEQPACK_Connector (void); 00259 00260 // = Completion routine. 00261 /** 00262 * Try to complete a nonblocking connection that was begun by a 00263 * previous call to connect with a {0, 0} ACE_Time_Value timeout. 00264 * @see connect(). 00265 * 00266 * @param new_association The @c ACE_SOCK_SEQPACK_Association object that will be connected 00267 * to the peer. 00268 * @param remote_sap If non-0, it points to the @c ACE_INET_Addr object 00269 * that will contain the address of the connected peer. 00270 * @param timeout Same values and return value possibilites as for 00271 * connect(). @see connect(). 00272 */ 00273 int complete (ACE_SOCK_SEQPACK_Association &new_association, 00274 ACE_Addr *remote_sap = 0, 00275 const ACE_Time_Value *timeout = 0); 00276 00277 /// Resets any event associations on this handle 00278 int reset_new_handle (ACE_HANDLE handle); 00279 00280 // = Meta-type info 00281 typedef ACE_Multihomed_INET_Addr PEER_ADDR; 00282 typedef ACE_SOCK_SEQPACK_Association PEER_STREAM; 00283 00284 /// Dump the state of an object. 00285 void dump (void) const; 00286 00287 /// Declare the dynamic allocation hooks. 00288 ACE_ALLOC_HOOK_DECLARE; 00289 00290 protected: 00291 /// Perform operations that ensure the socket is opened using 00292 /// BSD-style semantics (no QoS). 00293 int shared_open (ACE_SOCK_SEQPACK_Association &new_association, 00294 int protocol_family, 00295 int protocol, 00296 int reuse_addr); 00297 00298 /// Perform operations that ensure the socket is opened using 00299 /// QoS-enabled semantics. 00300 int shared_open (ACE_SOCK_SEQPACK_Association &new_association, 00301 int protocol_family, 00302 int protocol, 00303 ACE_Protocol_Info *protocolinfo, 00304 ACE_SOCK_GROUP g, 00305 u_long flags, 00306 int reuse_addr); 00307 00308 /// Perform operations that must be called before <ACE_OS::connect>. 00309 int shared_connect_start (ACE_SOCK_SEQPACK_Association &new_association, 00310 const ACE_Time_Value *timeout, 00311 const ACE_Addr &local_sap); 00312 00313 int shared_connect_start (ACE_SOCK_SEQPACK_Association &new_association, 00314 const ACE_Time_Value *timeout, 00315 const ACE_Multihomed_INET_Addr &local_sap); 00316 00317 /// Perform operations that must be called after <ACE_OS::connect>. 00318 int shared_connect_finish (ACE_SOCK_SEQPACK_Association &new_association, 00319 const ACE_Time_Value *timeout, 00320 int result); 00321 }; 00322 00323 ACE_END_VERSIONED_NAMESPACE_DECL 00324 00325 #if defined (__ACE_INLINE__) 00326 #include "ace/SOCK_SEQPACK_Connector.inl" 00327 #endif /* __ACE_INLINE__ */ 00328 00329 #include /**/ "ace/post.h" 00330 00331 #endif /* ACE_SOCK_SEQPACK_CONNECTOR_H */