ACE_SOCK_Stream object.
More...
#include <SOCK_Connector.h>
Inheritance diagram for ACE_SOCK_Connector:

Public Types | |
| typedef ACE_INET_Addr | PEER_ADDR |
| typedef ACE_SOCK_Stream | PEER_STREAM |
Public Member Functions | |
| ACE_SOCK_Connector (void) | |
| Default constructor. | |
| ACE_SOCK_Connector (ACE_SOCK_Stream &new_stream, const ACE_Addr &remote_sap, const ACE_Time_Value *timeout=0, const ACE_Addr &local_sap=ACE_Addr::sap_any, int reuse_addr=0, int flags=0, int perms=0, int protocol=0) | |
| ACE_SOCK_Connector (ACE_SOCK_Stream &new_stream, const ACE_Addr &remote_sap, ACE_QoS_Params qos_params, const ACE_Time_Value *timeout=0, const ACE_Addr &local_sap=ACE_Addr::sap_any, ACE_Protocol_Info *protocolinfo=0, ACE_SOCK_GROUP g=0, u_long flags=0, int reuse_addr=0, int perms=0) | |
| int | connect (ACE_SOCK_Stream &new_stream, const ACE_Addr &remote_sap, const ACE_Time_Value *timeout=0, const ACE_Addr &local_sap=ACE_Addr::sap_any, int reuse_addr=0, int flags=0, int perms=0, int protocol=0) |
| int | connect (ACE_SOCK_Stream &new_stream, const ACE_Addr &remote_sap, ACE_QoS_Params qos_params, const ACE_Time_Value *timeout=0, const ACE_Addr &local_sap=ACE_Addr::sap_any, ACE_Protocol_Info *protocolinfo=0, ACE_SOCK_GROUP g=0, u_long flags=0, int reuse_addr=0, int perms=0) |
| ~ACE_SOCK_Connector (void) | |
| Default dtor. | |
| int | complete (ACE_SOCK_Stream &new_stream, ACE_Addr *remote_sap=0, const ACE_Time_Value *timeout=0) |
| int | reset_new_handle (ACE_HANDLE handle) |
| Resets any event associations on this handle. | |
| void | dump (void) const |
| Dump the state of an object. | |
Public Attributes | |
| ACE_ALLOC_HOOK_DECLARE | |
| Declare the dynamic allocation hooks. | |
Protected Member Functions | |
| int | shared_open (ACE_SOCK_Stream &new_stream, int protocol_family, int protocol, int reuse_addr) |
| int | shared_open (ACE_SOCK_Stream &new_stream, int protocol_family, int protocol, ACE_Protocol_Info *protocolinfo, ACE_SOCK_GROUP g, u_long flags, int reuse_addr) |
| int | shared_connect_start (ACE_SOCK_Stream &new_stream, const ACE_Time_Value *timeout, const ACE_Addr &local_sap) |
| Perform operations that must be called before <ACE_OS::connect>. | |
| int | shared_connect_finish (ACE_SOCK_Stream &new_stream, const ACE_Time_Value *timeout, int result) |
| Perform operations that must be called after <ACE_OS::connect>. | |
ACE_SOCK_Stream object.
The ACE_SOCK_Connector doesn't have a socket of its own, i.e., it simply "borrows" the one from the ACE_SOCK_Stream that's being connected. The reason for this is that the underlying socket API doesn't use a factory socket to connect data mode sockets. Therefore, there's no need to inherit ACE_SOCK_Connector from ACE_SOCK. A nice side-effect of this is that ACE_SOCK_Connector objects do not store state so they can be used reentrantly in multithreaded programs.
Definition at line 43 of file SOCK_Connector.h.
|
|
Reimplemented in ACE_LSOCK_Connector, and ACE_MEM_Connector. Definition at line 284 of file SOCK_Connector.h. |
|
|
Reimplemented in ACE_LSOCK_Connector, and ACE_MEM_Connector. Definition at line 285 of file SOCK_Connector.h. |
|
|
Default constructor.
Definition at line 19 of file SOCK_Connector.inl. References ACE_TRACE.
00020 {
00021 ACE_TRACE ("ACE_SOCK_Connector::ACE_SOCK_Connector");
00022 }
|
|
||||||||||||||||||||||||||||||||||||
|
Actively connect to a peer, producing a connected
Definition at line 272 of file SOCK_Connector.cpp. References ACE_ERROR, ACE_LIB_TEXT, ACE_TRACE, connect(), ETIME, ETIMEDOUT, EWOULDBLOCK, and LM_ERROR.
00280 {
00281 ACE_TRACE ("ACE_SOCK_Connector::ACE_SOCK_Connector");
00282
00283 if (this->connect (new_stream,
00284 remote_sap,
00285 timeout,
00286 local_sap,
00287 reuse_addr,
00288 flags,
00289 perms,
00290 protocol) == -1
00291 && timeout != 0
00292 && !(errno == EWOULDBLOCK || errno == ETIME || errno == ETIMEDOUT))
00293 ACE_ERROR ((LM_ERROR,
00294 ACE_LIB_TEXT ("%p\n"),
00295 ACE_LIB_TEXT ("ACE_SOCK_Connector::ACE_SOCK_Connector")));
00296 }
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
Actively connect to a peer, producing a connected
Definition at line 299 of file SOCK_Connector.cpp. References ACE_ERROR, ACE_LIB_TEXT, ACE_SOCK_GROUP, ACE_TRACE, connect(), ETIME, ETIMEDOUT, EWOULDBLOCK, and LM_ERROR.
00309 {
00310 ACE_TRACE ("ACE_SOCK_Connector::ACE_SOCK_Connector");
00311
00312 if (this->connect (new_stream,
00313 remote_sap,
00314 qos_params,
00315 timeout,
00316 local_sap,
00317 protocolinfo,
00318 g,
00319 flags,
00320 reuse_addr,
00321 perms) == -1
00322 && timeout != 0
00323 && !(errno == EWOULDBLOCK || errno == ETIME || errno == ETIMEDOUT))
00324 ACE_ERROR ((LM_ERROR,
00325 ACE_LIB_TEXT ("%p\n"),
00326 ACE_LIB_TEXT ("ACE_SOCK_Connector::ACE_SOCK_Connector")));
00327 }
|
|
|
Default dtor.
Definition at line 11 of file SOCK_Connector.inl. References ACE_TRACE.
00012 {
00013 ACE_TRACE ("ACE_SOCK_Connector::~ACE_SOCK_Connector");
00014 }
|
|
||||||||||||||||
|
Try to complete a nonblocking connection that was begun by a previous call to connect with a {0, 0} ACE_Time_Value timeout.
Definition at line 221 of file SOCK_Connector.cpp. References ACE_NON_BLOCKING_BUG_DELAY, ACE_NONBLOCK, ACE_TRACE, ACE_SOCK_Stream::close(), ACE_IPC_SAP::disable(), ACE_Addr::get_addr(), ACE_IPC_SAP::get_handle(), ACE_Addr::get_size(), ACE_OS::getpeername(), ACE::handle_timed_complete(), and ACE_OS::sleep(). Referenced by shared_connect_finish().
00224 {
00225 ACE_TRACE ("ACE_SOCK_Connector::complete");
00226 ACE_HANDLE h = ACE::handle_timed_complete (new_stream.get_handle (),
00227 tv);
00228 // We failed to get connected.
00229 if (h == ACE_INVALID_HANDLE)
00230 {
00231 #if defined (ACE_WIN32)
00232 // Win32 has a timing problem - if you check to see if the
00233 // connection has completed too fast, it will fail - so wait
00234 // <ACE_NON_BLOCKING_BUG_DELAY> microseconds to let it catch up
00235 // then retry to see if it's a real failure.
00236 ACE_Time_Value time (0, ACE_NON_BLOCKING_BUG_DELAY);
00237 ACE_OS::sleep (time);
00238 h = ACE::handle_timed_complete (new_stream.get_handle (),
00239 tv);
00240 if (h == ACE_INVALID_HANDLE)
00241 {
00242 #endif /* ACE_WIN32 */
00243 // Save/restore errno.
00244 ACE_Errno_Guard error (errno);
00245 new_stream.close ();
00246 return -1;
00247 #if defined (ACE_WIN32)
00248 }
00249 #endif /* ACE_WIN32 */
00250 }
00251
00252 if (remote_sap != 0)
00253 {
00254 int len = remote_sap->get_size ();
00255 sockaddr *addr = reinterpret_cast<sockaddr *> (remote_sap->get_addr ());
00256 if (ACE_OS::getpeername (h,
00257 addr,
00258 &len) == -1)
00259 {
00260 // Save/restore errno.
00261 ACE_Errno_Guard error (errno);
00262 new_stream.close ();
00263 return -1;
00264 }
00265 }
00266
00267 // Start out with non-blocking disabled on the <new_stream>.
00268 new_stream.disable (ACE_NONBLOCK);
00269 return 0;
00270 }
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
Actively connect to a peer, producing a connected
Definition at line 181 of file SOCK_Connector.cpp. References ACE_SOCK_GROUP, ACE_TRACE, ACE_OS::connect(), ACE_Addr::get_addr(), ACE_IPC_SAP::get_handle(), ACE_Addr::get_size(), ACE_Addr::get_type(), shared_connect_finish(), shared_connect_start(), and shared_open().
00191 {
00192 ACE_TRACE ("ACE_SOCK_Connector::connect");
00193
00194 if (this->shared_open (new_stream,
00195 remote_sap.get_type (),
00196 0,
00197 protocolinfo,
00198 g,
00199 flags,
00200 reuse_addr) == -1)
00201 return -1;
00202 else if (this->shared_connect_start (new_stream,
00203 timeout,
00204 local_sap) == -1)
00205 return -1;
00206
00207 int result = ACE_OS::connect (new_stream.get_handle (),
00208 reinterpret_cast<sockaddr *> (remote_sap.get_addr ()),
00209 remote_sap.get_size (),
00210 qos_params);
00211
00212 return this->shared_connect_finish (new_stream,
00213 timeout,
00214 result);
00215 }
|
|
||||||||||||||||||||||||||||||||||||
|
Actively connect to a peer, producing a connected
Definition at line 149 of file SOCK_Connector.cpp. References ACE_TRACE, ACE_OS::connect(), ACE_Addr::get_addr(), ACE_IPC_SAP::get_handle(), ACE_Addr::get_size(), ACE_Addr::get_type(), shared_connect_finish(), shared_connect_start(), and shared_open(). Referenced by ACE_SOCK_Connector(), ACE_MEM_Connector::connect(), ACE_LSOCK_Connector::connect(), ACE_TSS_Connection::make_TSS_TYPE(), ACE_Pipe::open(), ACE_Name_Proxy::open(), and ACE_Log_Msg_IPC::open().
00157 {
00158 ACE_TRACE ("ACE_SOCK_Connector::connect");
00159
00160 if (this->shared_open (new_stream,
00161 remote_sap.get_type (),
00162 protocol,
00163 reuse_addr) == -1)
00164 return -1;
00165 else if (this->shared_connect_start (new_stream,
00166 timeout,
00167 local_sap) == -1)
00168 return -1;
00169
00170 int result = ACE_OS::connect (new_stream.get_handle (),
00171 reinterpret_cast<sockaddr *> (remote_sap.get_addr ()),
00172 remote_sap.get_size ());
00173
00174 return this->shared_connect_finish (new_stream,
00175 timeout,
00176 result);
00177 }
|
|
|
Dump the state of an object.
Reimplemented in ACE_LSOCK_Connector, and ACE_MEM_Connector. Definition at line 25 of file SOCK_Connector.cpp. References ACE_TRACE. Referenced by ACE_Name_Proxy::dump().
00026 {
00027 #if defined (ACE_HAS_DUMP)
00028 ACE_TRACE ("ACE_SOCK_Connector::dump");
00029 #endif /* ACE_HAS_DUMP */
00030 }
|
|
|
Resets any event associations on this handle.
Definition at line 25 of file SOCK_Connector.inl. References WSAEventSelect().
00026 {
00027 #if defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)
00028 // Reset the event association
00029 return ::WSAEventSelect ((SOCKET) handle,
00030 0,
00031 0);
00032 #else /* !defined ACE_HAS_WINSOCK2 */
00033 ACE_UNUSED_ARG (handle);
00034 return 0;
00035 #endif /* ACE_WIN32 */
00036 }
|
|
||||||||||||||||
|
Perform operations that must be called after <ACE_OS::connect>.
Definition at line 108 of file SOCK_Connector.cpp. References ACE_NONBLOCK, ACE_TRACE, ACE_SOCK_Stream::close(), complete(), ACE_IPC_SAP::disable(), EINPROGRESS, EISCONN, ETIMEDOUT, EWOULDBLOCK, ACE_Time_Value::sec(), and ACE_Time_Value::usec(). Referenced by connect().
00111 {
00112 ACE_TRACE ("ACE_SOCK_Connector::shared_connect_finish");
00113 // Save/restore errno.
00114 ACE_Errno_Guard error (errno);
00115
00116 if (result == -1 && timeout != 0)
00117 {
00118 // Check whether the connection is in progress.
00119 if (error == EINPROGRESS || error == EWOULDBLOCK)
00120 {
00121 // This expression checks if we were polling.
00122 if (timeout->sec () == 0
00123 && timeout->usec () == 0)
00124 error = EWOULDBLOCK;
00125 // Wait synchronously using timeout.
00126 else if (this->complete (new_stream,
00127 0,
00128 timeout) == -1)
00129 error = errno;
00130 else
00131 return 0;
00132 }
00133 }
00134
00135 // EISCONN is treated specially since this routine may be used to
00136 // check if we are already connected.
00137 if (result != -1 || error == EISCONN)
00138 // Start out with non-blocking disabled on the <new_stream>.
00139 new_stream.disable (ACE_NONBLOCK);
00140 else if (!(error == EWOULDBLOCK || error == ETIMEDOUT))
00141 new_stream.close ();
00142
00143 return result;
00144 }
|
|
||||||||||||||||
|
Perform operations that must be called before <ACE_OS::connect>.
Definition at line 77 of file SOCK_Connector.cpp. References ACE_NONBLOCK, ACE_TRACE, ACE_OS::bind(), ACE_SOCK_Stream::close(), ACE_IPC_SAP::enable(), ACE_Addr::get_addr(), ACE_IPC_SAP::get_handle(), and ACE_Addr::get_size(). Referenced by connect().
00080 {
00081 ACE_TRACE ("ACE_SOCK_Connector::shared_connect_start");
00082
00083 if (local_sap != ACE_Addr::sap_any)
00084 {
00085 sockaddr *laddr = reinterpret_cast<sockaddr *> (local_sap.get_addr ());
00086 int size = local_sap.get_size ();
00087
00088 if (ACE_OS::bind (new_stream.get_handle (),
00089 laddr,
00090 size) == -1)
00091 {
00092 // Save/restore errno.
00093 ACE_Errno_Guard error (errno);
00094 new_stream.close ();
00095 return -1;
00096 }
00097 }
00098
00099 // Enable non-blocking, if required.
00100 if (timeout != 0
00101 && new_stream.enable (ACE_NONBLOCK) == -1)
00102 return -1;
00103 else
00104 return 0;
00105 }
|
|
||||||||||||||||||||||||||||||||
|
Perform operations that ensure the socket is opened using QoS-enabled semantics. Definition at line 52 of file SOCK_Connector.cpp. References ACE_SOCK_GROUP, ACE_TRACE, ACE_IPC_SAP::get_handle(), and ACE_SOCK::open().
00059 {
00060 ACE_TRACE ("ACE_SOCK_Connector::shared_open");
00061
00062 // Only open a new socket if we don't already have a valid handle.
00063 if (new_stream.get_handle () == ACE_INVALID_HANDLE
00064 && new_stream.open (SOCK_STREAM,
00065 protocol_family,
00066 protocol,
00067 protocolinfo,
00068 g,
00069 flags,
00070 reuse_addr) == -1)
00071 return -1;
00072 else
00073 return 0;
00074 }
|
|
||||||||||||||||||||
|
Perform operations that ensure the socket is opened using BSD-style semantics (no QoS). Definition at line 33 of file SOCK_Connector.cpp. References ACE_TRACE, ACE_IPC_SAP::get_handle(), and ACE_SOCK::open(). Referenced by connect().
00037 {
00038 ACE_TRACE ("ACE_SOCK_Connector::shared_open");
00039
00040 // Only open a new socket if we don't already have a valid handle.
00041 if (new_stream.get_handle () == ACE_INVALID_HANDLE
00042 && new_stream.open (SOCK_STREAM,
00043 protocol_family,
00044 protocol,
00045 reuse_addr) == -1)
00046 return -1;
00047 else
00048 return 0;
00049 }
|
|
|
Declare the dynamic allocation hooks.
Reimplemented in ACE_LSOCK_Connector, and ACE_MEM_Connector. Definition at line 291 of file SOCK_Connector.h. |
1.3.6