00001 /* -*- C++ -*- */ 00002 00003 //============================================================================= 00004 /** 00005 * @file MEM_Connector.h 00006 * 00007 * MEM_Connector.h,v 4.18 2005/11/26 03:13:13 ossama Exp 00008 * 00009 * @author Nanbor Wang <nanbor@cs.wustl.edu> 00010 */ 00011 //============================================================================= 00012 00013 #ifndef ACE_MEM_CONNECTOR_H 00014 #define ACE_MEM_CONNECTOR_H 00015 #include /**/ "ace/pre.h" 00016 00017 #include "ace/ACE_export.h" 00018 00019 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00020 # pragma once 00021 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00022 00023 #if (ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1) 00024 00025 #include "ace/SOCK_Connector.h" 00026 #include "ace/MEM_Stream.h" 00027 #include "ace/MEM_Addr.h" 00028 00029 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00030 00031 /** 00032 * @class ACE_MEM_Connector 00033 * 00034 * @brief Defines the format and interface for connecting to a peer 00035 * on a @c ACE_MEM_Stream object. 00036 */ 00037 class ACE_Export ACE_MEM_Connector : public ACE_SOCK_Connector 00038 { 00039 public: 00040 // = Initialization methods. 00041 /// Default constructor. 00042 ACE_MEM_Connector (void); 00043 00044 /** 00045 * Actively connect to a peer, producing a connected @c ACE_MEM_Stream 00046 * object if the connection succeeds. 00047 * 00048 * @param new_stream The @c ACE_MEM_Stream object that will be connected 00049 * to the peer. 00050 * @param remote_sap The address that we are trying to connect to. 00051 * The protocol family of @c remote_sap is used for 00052 * the connected socket. That is, if @c remote_sap 00053 * contains an IPv6 address, a socket with family 00054 * PF_INET6 will be used, else it will be PF_INET. 00055 * @note remote_sap must be an address on the local 00056 * host. 00057 * @param timeout Pointer to an @c ACE_Time_Value object with amount 00058 * of time to wait to connect. If the pointer is 0 00059 * then the call blocks until the connection attempt 00060 * is complete, whether it succeeds or fails. If 00061 * *timeout == {0, 0} then the connection is done 00062 * using nonblocking mode. In this case, if the 00063 * connection can't be made immediately, this method 00064 * returns -1 and errno == EWOULDBLOCK. 00065 * If *timeout > {0, 0} then this is the maximum amount 00066 * of time to wait before timing out; if the specified 00067 * amount of time passes before the connection is made, 00068 * this method returns -1 and errno == ETIME. Note 00069 * the difference between this case and when a blocking 00070 * connect is attmpted that TCP times out - in the latter 00071 * case, errno will be ETIMEDOUT. 00072 * @param local_sap (optional) The local address to bind to. If it's 00073 * the default value of @c ACE_Addr::sap_any then the 00074 * OS will choose an unused port. 00075 * @param reuse_addr (optional) If the value is 1, the local address 00076 * (@c local_sap) is reused, even if it hasn't been 00077 * cleaned up yet. 00078 * @param flags Ignored. 00079 * @param perms Ignored. 00080 */ 00081 ACE_MEM_Connector (ACE_MEM_Stream &new_stream, 00082 const ACE_INET_Addr &remote_sap, 00083 ACE_Time_Value *timeout = 0, 00084 const ACE_Addr &local_sap = ACE_Addr::sap_any, 00085 int reuse_addr = 0, 00086 int flags = 0, 00087 int perms = 0); 00088 00089 /** 00090 * Actively connect to a peer, producing a connected @c ACE_MEM_Stream 00091 * object if the connection succeeds. 00092 * 00093 * @param new_stream The @c ACE_MEM_Stream object that will be connected 00094 * to the peer. 00095 * @param remote_sap The address that we are trying to connect to. 00096 * The protocol family of @c remote_sap is used for 00097 * the connected socket. That is, if @c remote_sap 00098 * contains an IPv6 address, a socket with family 00099 * PF_INET6 will be used, else it will be PF_INET. 00100 * @note remote_sap must be an address on the local 00101 * host. 00102 * @param timeout Pointer to an @c ACE_Time_Value object with amount 00103 * of time to wait to connect. If the pointer is 0 00104 * then the call blocks until the connection attempt 00105 * is complete, whether it succeeds or fails. If 00106 * *timeout == {0, 0} then the connection is done 00107 * using nonblocking mode. In this case, if the 00108 * connection can't be made immediately, this method 00109 * returns -1 and errno == EWOULDBLOCK. 00110 * If *timeout > {0, 0} then this is the maximum amount 00111 * of time to wait before timing out; if the specified 00112 * amount of time passes before the connection is made, 00113 * this method returns -1 and errno == ETIME. Note 00114 * the difference between this case and when a blocking 00115 * connect is attmpted that TCP times out - in the latter 00116 * case, errno will be ETIMEDOUT. 00117 * @param local_sap (optional) The local address to bind to. If it's 00118 * the default value of @c ACE_Addr::sap_any then the 00119 * OS will choose an unused port. 00120 * @param reuse_addr (optional) If the value is 1, the local address 00121 * (@c local_sap) is reused, even if it hasn't been 00122 * cleaned up yet. 00123 * @param flags Ignored. 00124 * @param perms Ignored. 00125 * 00126 * @return Returns 0 if the connection succeeds. If it fails, 00127 * -1 is returned and errno contains a specific error 00128 * code. 00129 */ 00130 int connect (ACE_MEM_Stream &new_stream, 00131 const ACE_INET_Addr &remote_sap, 00132 ACE_Time_Value *timeout = 0, 00133 const ACE_Addr &local_sap = ACE_Addr::sap_any, 00134 int reuse_addr = 0, 00135 int flags = 0, 00136 int perms = 0); 00137 00138 /// Get the preferred signaling strategy. 00139 ACE_MEM_IO::Signal_Strategy preferred_strategy (void) const; 00140 00141 /// Set the preferred signaling strategy. 00142 void preferred_strategy (ACE_MEM_IO::Signal_Strategy strategy); 00143 00144 /// Accessor to underlying malloc options. 00145 /// @deprecated This method has been deprecated. 00146 ACE_MEM_SAP::MALLOC_OPTIONS &malloc_options (void); 00147 00148 // = Meta-type info 00149 typedef ACE_INET_Addr PEER_ADDR; 00150 typedef ACE_MEM_Stream PEER_STREAM; 00151 00152 /// Dump the state of an object. 00153 void dump (void) const; 00154 00155 /// Declare the dynamic allocation hooks. 00156 ACE_ALLOC_HOOK_DECLARE; 00157 00158 private: 00159 /// The acceptor address this connector is connecting to. 00160 ACE_MEM_Addr address_; 00161 00162 /// A cached MALLOC_OPTIONS that the MEM_Connector used to initialize 00163 /// the shared memory malloc update connection establishment. 00164 ACE_MEM_SAP::MALLOC_OPTIONS malloc_options_; 00165 00166 /// Preferred signaling strategy. 00167 ACE_MEM_IO::Signal_Strategy preferred_strategy_; 00168 }; 00169 00170 ACE_END_VERSIONED_NAMESPACE_DECL 00171 00172 #if defined (__ACE_INLINE__) 00173 #include "ace/MEM_Connector.inl" 00174 #endif /* __ACE_INLINE__ */ 00175 00176 #endif /* ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1 */ 00177 00178 #include /**/ "ace/post.h" 00179 #endif /* ACE_MEM_CONNECTOR_H */