summaryrefslogtreecommitdiff
path: root/ace/SOCK_Connector.cpp
diff options
context:
space:
mode:
authorschmidt <douglascraigschmidt@users.noreply.github.com>1999-06-14 02:17:02 +0000
committerschmidt <douglascraigschmidt@users.noreply.github.com>1999-06-14 02:17:02 +0000
commitb4a501994dd71bacf8c727a8a11e8c57a023e1fc (patch)
treecd090e6574f0f1d2f35adc0dd6d719c5c0d9b90e /ace/SOCK_Connector.cpp
parenta43d81d54a95a6fd5359d4733b7e3c1e4f02bd6b (diff)
downloadATCD-b4a501994dd71bacf8c727a8a11e8c57a023e1fc.tar.gz
*** empty log message ***
Diffstat (limited to 'ace/SOCK_Connector.cpp')
-rw-r--r--ace/SOCK_Connector.cpp255
1 files changed, 182 insertions, 73 deletions
diff --git a/ace/SOCK_Connector.cpp b/ace/SOCK_Connector.cpp
index 6a1edc9028d..9938d839f4a 100644
--- a/ace/SOCK_Connector.cpp
+++ b/ace/SOCK_Connector.cpp
@@ -20,22 +20,15 @@ ACE_SOCK_Connector::dump (void) const
ACE_TRACE ("ACE_SOCK_Connector::dump");
}
-// Actively connect and produce a new ACE_SOCK_Stream if things go well...
-
-int
-ACE_SOCK_Connector::connect (ACE_SOCK_Stream &new_stream,
- const ACE_Addr &remote_sap,
- ACE_Time_Value *timeout,
- const ACE_Addr &local_sap,
- int reuse_addr,
- int /* flags */,
- int /* perms */,
- int protocol_family,
- int protocol)
+int
+ACE_SOCK_Connector::shared_connect_start (ACE_SOCK_Stream &new_stream,
+ ACE_Time_Value *timeout,
+ const ACE_Addr &local_sap,
+ int reuse_addr,
+ int protocol_family,
+ int protocol)
{
- ACE_TRACE ("ACE_SOCK_Connector::connect");
- int result = 0;
-
+ ACE_TRACE ("ACE_SOCK_Connector::shared_connect_start");
// Only open a new socket if we don't already have a valid handle.
if (new_stream.get_handle () == ACE_INVALID_HANDLE
&& new_stream.open (SOCK_STREAM,
@@ -43,65 +36,126 @@ ACE_SOCK_Connector::connect (ACE_SOCK_Stream &new_stream,
protocol,
reuse_addr) == -1)
return -1;
-
- sockaddr *raddr = (sockaddr *) remote_sap.get_addr ();
- size_t rsize = remote_sap.get_size ();
-
- if (local_sap != ACE_Addr::sap_any)
+ else if (local_sap != ACE_Addr::sap_any)
{
sockaddr *laddr = (sockaddr *) local_sap.get_addr ();
size_t size = local_sap.get_size ();
- result = ACE_OS::bind (new_stream.get_handle (),
- laddr,
- size);
-
- if (result == -1)
+ if (ACE_OS::bind (new_stream.get_handle (),
+ laddr,
+ size) == -1)
{
+ // Save/restore errno.
+ ACE_Errno_Guard error (errno);
new_stream.close ();
return -1;
}
}
// Enable non-blocking, if required.
- if (timeout != 0)
+ if (timeout != 0 && new_stream.enable (ACE_NONBLOCK) == -1)
+ return -1;
+ else
+ return 0;
+}
+
+int
+ACE_SOCK_Connector::shared_connect_finish (ACE_SOCK_Stream &new_stream,
+ ACE_Time_Value *timeout,
+ int result)
+{
+ ACE_TRACE ("ACE_SOCK_Connector::shared_connect_finish");
+ // Save/restore errno.
+ ACE_Errno_Guard error (errno);
+
+ if (result == -1 && timeout != 0)
{
- if (new_stream.enable (ACE_NONBLOCK) == -1)
- result = -1;
-
- if (ACE_OS::connect (new_stream.get_handle (), raddr, rsize) == -1)
+ // Check whether the connection is in progress.
+ if (error == EINPROGRESS || error == EWOULDBLOCK)
{
- result = -1;
-
- // Check whether the connection is in progress.
- if (errno == EINPROGRESS || errno == EWOULDBLOCK)
- {
- // This expression checks if we were polling.
- if (timeout->sec () == 0 && timeout->usec () == 0)
- errno = EWOULDBLOCK;
- // Wait synchronously
- else if (this->complete (new_stream, 0, timeout) != -1)
- return 0;
- }
+ // This expression checks if we were polling.
+ if (timeout->sec () == 0 && timeout->usec () == 0)
+ error = EWOULDBLOCK;
+ // Wait synchronously using timeout.
+ else if (this->complete (new_stream,
+ 0,
+ timeout) == -1)
+ error = errno;
+ else
+ return 0;
}
}
- // Do a blocking connect.
- else if (ACE_OS::connect (new_stream.get_handle (), raddr, rsize) == -1)
- result = -1;
// EISCONN is treated specially since this routine may be used to
// check if we are already connected.
- if (result != -1 || errno == EISCONN)
+ if (result != -1 || error == EISCONN)
// Start out with non-blocking disabled on the <new_stream>.
new_stream.disable (ACE_NONBLOCK);
- else if (!(errno == EWOULDBLOCK || errno == ETIMEDOUT))
- {
- // Save/restore errno.
- ACE_Errno_Guard error (errno);
- new_stream.close ();
- }
-
+ else if (!(error == EWOULDBLOCK || error == ETIMEDOUT))
+ new_stream.close ();
+
return result;
}
+// Actively connect and produce a new ACE_SOCK_Stream if things go well...
+
+int
+ACE_SOCK_Connector::connect (ACE_SOCK_Stream &new_stream,
+ const ACE_Addr &remote_sap,
+ ACE_Time_Value *timeout,
+ const ACE_Addr &local_sap,
+ int reuse_addr,
+ int /* flags */,
+ int /* perms */,
+ int protocol_family,
+ int protocol)
+{
+ ACE_TRACE ("ACE_SOCK_Connector::connect");
+ if (this->shared_connect_start (new_stream,
+ timeout,
+ local_sap,
+ reuse_addr,
+ protocol_family,
+ protocol) == -1)
+ return -1;
+
+ int result = ACE_OS::connect (new_stream.get_handle (),
+ (sockaddr *) remote_sap.get_addr (),
+ remote_sap.get_size ());
+
+ return this->shared_connect_finish (new_stream,
+ timeout,
+ result);
+}
+
+int
+ACE_SOCK_Connector::connect (ACE_SOCK_Stream &new_stream,
+ const ACE_Addr &remote_sap,
+ ACE_Connect_QoS_Params qos_params,
+ ACE_Time_Value *timeout,
+ const ACE_Addr &local_sap,
+ int reuse_addr,
+ int /* flags */,
+ int /* perms */,
+ int protocol_family,
+ int protocol)
+{
+ ACE_TRACE ("ACE_SOCK_Connector::connect");
+ if (this->shared_connect_start (new_stream,
+ timeout,
+ local_sap,
+ reuse_addr,
+ protocol_family,
+ protocol) == -1)
+ return -1;
+
+ int result = ACE_OS::connect (new_stream.get_handle (),
+ (sockaddr *) remote_sap.get_addr (),
+ remote_sap.get_size (),
+ qos_params);
+
+ return this->shared_connect_finish (new_stream,
+ timeout,
+ result);
+}
// Try to complete a non-blocking connection.
@@ -118,8 +172,9 @@ ACE_SOCK_Connector::complete (ACE_SOCK_Stream &new_stream,
ACE_Time_Value time (0, ACE_NON_BLOCKING_BUG_DELAY);
ACE_OS::sleep (time);
#endif /* ACE_HAS_BROKEN_NON_BLOCKING_CONNECTS */
- ACE_HANDLE h = ACE::handle_timed_complete (new_stream.get_handle (), tv);
-
+ ACE_HANDLE h = ACE::handle_timed_complete (new_stream.get_handle (),
+ tv);
+ // We failed to get connected.
if (h == ACE_INVALID_HANDLE)
{
// Save/restore errno.
@@ -127,28 +182,82 @@ ACE_SOCK_Connector::complete (ACE_SOCK_Stream &new_stream,
new_stream.close ();
return -1;
}
- else // We've successfully connected!
+ else if (remote_sap != 0)
{
- if (remote_sap != 0)
+ int len = remote_sap->get_size ();
+ sockaddr *addr = (sockaddr *) remote_sap->get_addr ();
+
+ if (ACE_OS::getpeername (h,
+ addr,
+ &len) == -1)
{
- int len;
-
- len = remote_sap->get_size ();
- sockaddr *addr = (sockaddr *) remote_sap->get_addr ();
-
- if (ACE_OS::getpeername (h, addr, &len) == -1)
- {
- // Save/restore errno.
- ACE_Errno_Guard error (errno);
- new_stream.close ();
- return -1;
- }
+ // Save/restore errno.
+ ACE_Errno_Guard error (errno);
+ new_stream.close ();
+ return -1;
}
-
- // Start out with non-blocking disabled on the <new_stream>.
- new_stream.disable (ACE_NONBLOCK);
- return 0;
}
+
+ // Start out with non-blocking disabled on the <new_stream>.
+ new_stream.disable (ACE_NONBLOCK);
+ return 0;
}
+ACE_SOCK_Connector::ACE_SOCK_Connector (ACE_SOCK_Stream &new_stream,
+ const ACE_Addr &remote_sap,
+ ACE_Time_Value *timeout,
+ const ACE_Addr &local_sap,
+ int reuse_addr,
+ int flags,
+ int perms,
+ int protocol_family,
+ int protocol)
+{
+ ACE_TRACE ("ACE_SOCK_Connector::ACE_SOCK_Connector");
+
+ if (this->connect (new_stream,
+ remote_sap,
+ timeout,
+ local_sap,
+ reuse_addr,
+ flags,
+ perms,
+ protocol_family,
+ protocol) == -1
+ && timeout != 0
+ && !(errno == EWOULDBLOCK || errno == ETIME))
+ ACE_ERROR ((LM_ERROR,
+ ASYS_TEXT ("%p\n"),
+ ASYS_TEXT ("ACE_SOCK_Connector::ACE_SOCK_Connector")));
+}
+
+ACE_SOCK_Connector::ACE_SOCK_Connector (ACE_SOCK_Stream &new_stream,
+ const ACE_Addr &remote_sap,
+ ACE_Connect_QoS_Params qos_params,
+ ACE_Time_Value *timeout,
+ const ACE_Addr &local_sap,
+ int reuse_addr,
+ int flags,
+ int perms,
+ int protocol_family,
+ int protocol)
+{
+ ACE_TRACE ("ACE_SOCK_Connector::ACE_SOCK_Connector");
+
+ if (this->connect (new_stream,
+ remote_sap,
+ qos_params,
+ timeout,
+ local_sap,
+ reuse_addr,
+ flags,
+ perms,
+ protocol_family,
+ protocol) == -1
+ && timeout != 0
+ && !(errno == EWOULDBLOCK || errno == ETIME))
+ ACE_ERROR ((LM_ERROR,
+ ASYS_TEXT ("%p\n"),
+ ASYS_TEXT ("ACE_SOCK_Connector::ACE_SOCK_Connector")));
+}