summaryrefslogtreecommitdiff
path: root/tests/SOCK_Connector_Test.cpp
diff options
context:
space:
mode:
authorSteve Huston <shuston@riverace.com>1997-09-25 23:59:09 +0000
committerSteve Huston <shuston@riverace.com>1997-09-25 23:59:09 +0000
commit0fba8bcbf5dd43d8a811a082e4645c528dfca10f (patch)
tree8640213c5d74e465dd725676a6950a8be52cc02b /tests/SOCK_Connector_Test.cpp
parent4d4a1e64de6fd843d1fa09190e75ac292683e931 (diff)
downloadATCD-0fba8bcbf5dd43d8a811a082e4645c528dfca10f.tar.gz
Now tries to look for another host to try a non-blocking connect to.
It will try the first one which isn't the system it's running on, unless it's on Win32 or VxWorks.
Diffstat (limited to 'tests/SOCK_Connector_Test.cpp')
-rw-r--r--tests/SOCK_Connector_Test.cpp46
1 files changed, 45 insertions, 1 deletions
diff --git a/tests/SOCK_Connector_Test.cpp b/tests/SOCK_Connector_Test.cpp
index 5b698642acc..b8e096feda2 100644
--- a/tests/SOCK_Connector_Test.cpp
+++ b/tests/SOCK_Connector_Test.cpp
@@ -22,18 +22,62 @@
#include "ace/SOCK_Connector.h"
#include "ace/SOCK_Stream.h"
#include "test_config.h"
+#if !defined(ACE_WIN32) && !defined(VXWORKS)
+#include <sys/utsname.h>
+#endif
+
+
+// The original problem this program tested for was incorrectly saying
+// a non-blocking connect completed successfully when it didn't. The
+// test doesn't always work when done to localhost (platform-dependant)
+// so we look around for another host - any other one will do.
+static void
+find_another_host(char other_host[])
+{
+
+ strcpy(other_host, "localhost"); // If all else fails
+
+ // These gethost-type things don't work everywhere.
+#if !defined(ACE_WIN32) && !defined(VXWORKS)
+ struct hostent *h;
+ struct utsname un;
+
+ uname(&un);
+ h = gethostbyname(un.nodename);
+ strcpy(other_host, h->h_name); // Use me if can't find another
+
+ sethostent(1);
+ while ((h = gethostent()) != NULL) {
+ if (strcmp(h->h_name, "localhost") == 0)
+ continue;
+ if (strcmp(h->h_name, other_host) != 0) { // If not me
+ strcpy(other_host, h->h_name);
+ break;
+ }
+ }
+ endhostent();
+
+#endif // ACE_WIN32, VXWORKS
+
+ return;
+
+}
static int
fail_no_listener_nonblocking(void)
{
+char test_host[256];
int status;
-ACE_INET_Addr nobody_home((u_short)4242, "mambo"); // "localhost"
+ACE_INET_Addr nobody_home;
ACE_SOCK_Connector con;
ACE_SOCK_Stream sock;
ACE_Time_Value nonblock(0, 0);
+ find_another_host(test_host);
+ ACE_DEBUG((LM_DEBUG, "Testing to host %s\n", test_host));
+ nobody_home.set((u_short)4242, test_host);
status = con.connect(sock, nobody_home, &nonblock);
ACE_ASSERT(status == -1); // Need a port that will fail