summaryrefslogtreecommitdiff
path: root/ace/SOCK_Connector.cpp
diff options
context:
space:
mode:
authorschmidt <douglascraigschmidt@users.noreply.github.com>1999-07-18 21:56:49 +0000
committerschmidt <douglascraigschmidt@users.noreply.github.com>1999-07-18 21:56:49 +0000
commitdf505ef0bb08baeb35a63c79147c105953d9a21c (patch)
tree99ee8799a4af71d1331db06c061471034f014ffb /ace/SOCK_Connector.cpp
parent7f6c541f08e32b48a3f391bbd21e25f530d499c7 (diff)
downloadATCD-df505ef0bb08baeb35a63c79147c105953d9a21c.tar.gz
ChangeLogTag:Sun Jul 18 14:30:54 1999 Douglas C. Schmidt <schmidt@tango.cs.wustl.edu>
Diffstat (limited to 'ace/SOCK_Connector.cpp')
-rw-r--r--ace/SOCK_Connector.cpp113
1 files changed, 81 insertions, 32 deletions
diff --git a/ace/SOCK_Connector.cpp b/ace/SOCK_Connector.cpp
index f5f1ab00077..49ecdb8a8f7 100644
--- a/ace/SOCK_Connector.cpp
+++ b/ace/SOCK_Connector.cpp
@@ -21,14 +21,13 @@ ACE_SOCK_Connector::dump (void) const
}
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_SOCK_Connector::shared_open (ACE_SOCK_Stream &new_stream,
+ int protocol_family,
+ int protocol,
+ int reuse_addr)
{
- ACE_TRACE ("ACE_SOCK_Connector::shared_connect_start");
+ ACE_TRACE ("ACE_SOCK_Connector::shared_open");
+
// 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,
@@ -36,10 +35,48 @@ ACE_SOCK_Connector::shared_connect_start (ACE_SOCK_Stream &new_stream,
protocol,
reuse_addr) == -1)
return -1;
- else if (local_sap != ACE_Addr::sap_any)
+ else
+ return 0;
+}
+
+int
+ACE_SOCK_Connector::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)
+{
+ ACE_TRACE ("ACE_SOCK_Connector::shared_open");
+
+ // 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,
+ protocol_family,
+ protocol,
+ protocolinfo,
+ g,
+ flags,
+ reuse_addr) == -1)
+ return -1;
+ else
+ return 0;
+}
+
+int
+ACE_SOCK_Connector::shared_connect_start (ACE_SOCK_Stream &new_stream,
+ ACE_Time_Value *timeout,
+ const ACE_Addr &local_sap)
+{
+ ACE_TRACE ("ACE_SOCK_Connector::shared_connect_start");
+
+ if (local_sap != ACE_Addr::sap_any)
{
- sockaddr *laddr = (sockaddr *) local_sap.get_addr ();
+ sockaddr *laddr = ACE_reinterpret_cast (sockaddr *,
+ local_sap.get_addr ());
size_t size = local_sap.get_size ();
+
if (ACE_OS::bind (new_stream.get_handle (),
laddr,
size) == -1)
@@ -52,7 +89,8 @@ ACE_SOCK_Connector::shared_connect_start (ACE_SOCK_Stream &new_stream,
}
// Enable non-blocking, if required.
- if (timeout != 0 && new_stream.enable (ACE_NONBLOCK) == -1)
+ if (timeout != 0
+ && new_stream.enable (ACE_NONBLOCK) == -1)
return -1;
else
return 0;
@@ -73,7 +111,8 @@ ACE_SOCK_Connector::shared_connect_finish (ACE_SOCK_Stream &new_stream,
if (error == EINPROGRESS || error == EWOULDBLOCK)
{
// This expression checks if we were polling.
- if (timeout->sec () == 0 && timeout->usec () == 0)
+ if (timeout->sec () == 0
+ && timeout->usec () == 0)
error = EWOULDBLOCK;
// Wait synchronously using timeout.
else if (this->complete (new_stream,
@@ -95,6 +134,7 @@ ACE_SOCK_Connector::shared_connect_finish (ACE_SOCK_Stream &new_stream,
return result;
}
+
// Actively connect and produce a new ACE_SOCK_Stream if things go well...
int
@@ -109,16 +149,19 @@ ACE_SOCK_Connector::connect (ACE_SOCK_Stream &new_stream,
int protocol)
{
ACE_TRACE ("ACE_SOCK_Connector::connect");
- if (this->shared_connect_start (new_stream,
- timeout,
- local_sap,
- reuse_addr,
- protocol_family,
- protocol) == -1)
+ if (this->shared_open (new_stream,
+ protocol_family,
+ protocol,
+ reuse_addr) == -1)
+ return -1;
+ else if (this->shared_connect_start (new_stream,
+ timeout,
+ local_sap) == -1)
return -1;
int result = ACE_OS::connect (new_stream.get_handle (),
- (sockaddr *) remote_sap.get_addr (),
+ ACE_reinterpret_cast (sockaddr *,
+ remote_sap.get_addr ()),
remote_sap.get_size ());
return this->shared_connect_finish (new_stream,
@@ -132,25 +175,31 @@ ACE_SOCK_Connector::connect (ACE_SOCK_Stream &new_stream,
ACE_QoS_Params qos_params,
ACE_Time_Value *timeout,
const ACE_Addr &local_sap,
- ACE_Protocol_Info * /* protocolinfo */,
- ACE_SOCK_GROUP /* g */,
- u_long /* flags */,
+ ACE_Protocol_Info * protocolinfo,
+ ACE_SOCK_GROUP g,
+ u_long flags,
int reuse_addr,
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)
+ if (this->shared_open (new_stream,
+ protocol_family,
+ protocol,
+ protocolinfo,
+ g,
+ flags,
+ reuse_addr) == -1)
+ return -1;
+ else if (this->shared_connect_start (new_stream,
+ timeout,
+ local_sap) == -1)
return -1;
int result = ACE_OS::connect (new_stream.get_handle (),
- (sockaddr *) remote_sap.get_addr (),
+ ACE_reinterpret_cast (sockaddr *,
+ remote_sap.get_addr ()),
remote_sap.get_size (),
qos_params);
@@ -169,8 +218,8 @@ ACE_SOCK_Connector::complete (ACE_SOCK_Stream &new_stream,
ACE_TRACE ("ACE_SOCK_Connector::complete");
#if defined (ACE_HAS_BROKEN_NON_BLOCKING_CONNECTS)
// Win32 has a timing problem - if you check to see if the
- // connection has completed too fast, it will fail - so wait 1
- // millisecond to let it catch up.
+ // connection has completed too fast, it will fail - so wait
+ // <ACE_NON_BLOCKING_BUG_DELAY> microseconds to let it catch up.
ACE_Time_Value time (0, ACE_NON_BLOCKING_BUG_DELAY);
ACE_OS::sleep (time);
#endif /* ACE_HAS_BROKEN_NON_BLOCKING_CONNECTS */
@@ -187,8 +236,8 @@ ACE_SOCK_Connector::complete (ACE_SOCK_Stream &new_stream,
else if (remote_sap != 0)
{
int len = remote_sap->get_size ();
- sockaddr *addr = (sockaddr *) remote_sap->get_addr ();
-
+ sockaddr *addr = ACE_reinterpret_cast (sockaddr *,
+ remote_sap->get_addr ());
if (ACE_OS::getpeername (h,
addr,
&len) == -1)