axis-c-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nadira...@apache.org
Subject svn commit: r940916 - in /axis/axis1/c/trunk/src/transport/axis3: HTTPChannel/HTTPChannel.cpp HTTPSSLChannel/HTTPSSLChannel.cpp
Date Tue, 04 May 2010 15:48:57 GMT
Author: nadiramra
Date: Tue May  4 15:48:56 2010
New Revision: 940916

URL: http://svn.apache.org/viewvc?rev=940916&view=rev
Log:
AXISCPP-1069 Use inet_addr first if hostname begins with number to avoid gethostbyname timeout

Modified:
    axis/axis1/c/trunk/src/transport/axis3/HTTPChannel/HTTPChannel.cpp
    axis/axis1/c/trunk/src/transport/axis3/HTTPSSLChannel/HTTPSSLChannel.cpp

Modified: axis/axis1/c/trunk/src/transport/axis3/HTTPChannel/HTTPChannel.cpp
URL: http://svn.apache.org/viewvc/axis/axis1/c/trunk/src/transport/axis3/HTTPChannel/HTTPChannel.cpp?rev=940916&r1=940915&r2=940916&view=diff
==============================================================================
--- axis/axis1/c/trunk/src/transport/axis3/HTTPChannel/HTTPChannel.cpp (original)
+++ axis/axis1/c/trunk/src/transport/axis3/HTTPChannel/HTTPChannel.cpp Tue May  4 15:48:56
2010
@@ -16,6 +16,8 @@
 // !!! Must be first thing in file !!!
 #include "../../../platforms/PlatformAutoSense.hpp"
 
+#include <ctype.h>
+
 #include "HTTPChannel.hpp"
 
 #include "../../../common/AxisTrace.h"
@@ -592,23 +594,27 @@ OpenChannel()
     svAddr.sin_family = AF_INET;
     svAddr.sin_port = htons( port);
 
-    // Probably this is the host-name of the server we are connecting to...
+    // Host names must start with a character (RFC1035)...so if it starts with a number,
let us first
+    // assume it is dotted decimal format...and if it fails, we will then assume it is a
host name.
+    // We do this so that we avoid long DNS timeouts if we use gethostbyname() first.
+    svAddr.sin_addr.s_addr = -1;
+    if (isdigit(host[0]))
+    {
 #ifdef __OS400__
-    if( (pHostEntry = gethostbyname( (char *)host)))
+        svAddr.sin_addr.s_addr = inet_addr( (char *)host);
 #else
-    if( (pHostEntry = gethostbyname( host)))
+        svAddr.sin_addr.s_addr = inet_addr( host);
 #endif
-    {
-        svAddr.sin_addr.s_addr = ((struct in_addr *) pHostEntry->h_addr)->s_addr;
     }
-    else
+
+    if (svAddr.sin_addr.s_addr == -1)
     {
-        // No this is the IP address
 #ifdef __OS400__
-        svAddr.sin_addr.s_addr = inet_addr( (char *)host);
+        if( (pHostEntry = gethostbyname( (char *)host)))
 #else
-        svAddr.sin_addr.s_addr = inet_addr( host);
+        if( (pHostEntry = gethostbyname( host)))
 #endif
+            svAddr.sin_addr.s_addr = ((struct in_addr *) pHostEntry->h_addr)->s_addr;
     }
 
     // Attempt to connect to the remote server.
@@ -810,4 +816,4 @@ enableTrace(const char* logFilePath, con
 {
     AxisTrace::setLogFilter(filters);
     AxisTrace::startTrace(logFilePath, false);
-}
\ No newline at end of file
+}

Modified: axis/axis1/c/trunk/src/transport/axis3/HTTPSSLChannel/HTTPSSLChannel.cpp
URL: http://svn.apache.org/viewvc/axis/axis1/c/trunk/src/transport/axis3/HTTPSSLChannel/HTTPSSLChannel.cpp?rev=940916&r1=940915&r2=940916&view=diff
==============================================================================
--- axis/axis1/c/trunk/src/transport/axis3/HTTPSSLChannel/HTTPSSLChannel.cpp (original)
+++ axis/axis1/c/trunk/src/transport/axis3/HTTPSSLChannel/HTTPSSLChannel.cpp Tue May  4 15:48:56
2010
@@ -16,6 +16,8 @@
 // !!! Must be first thing in file !!!
 #include "../../../platforms/PlatformAutoSense.hpp"
 
+#include <ctype.h>
+
 #include "HTTPSSLChannel.hpp"
 
 #include "../../../common/AxisTrace.h"
@@ -706,16 +708,15 @@ OpenChannel()
     svAddr.sin_family = AF_INET;
     svAddr.sin_port = htons( port);
 
-    // Probably this is the host-name of the server we are connecting to...
-    if( (pHostEntry = gethostbyname( host)))
-    {
-        svAddr.sin_addr.s_addr = ((struct in_addr *) pHostEntry->h_addr)->s_addr;
-    }
-    else
-    {
-        // No this is the IP address
+    // Host names must start with a character (RFC1035)...so if it starts with a number,
let us first
+    // assume it is dotted decimal format...and if it fails, we will then assume it is a
host name.
+    // We do this so that we avoid long DNS timeouts if we use gethostbyname() first.
+    svAddr.sin_addr.s_addr = -1;
+    if (isdigit(host[0]))
         svAddr.sin_addr.s_addr = inet_addr( host);
-    }
+
+    if ((svAddr.sin_addr.s_addr == -1) && (pHostEntry = gethostbyname( host)))
+        svAddr.sin_addr.s_addr = ((struct in_addr *) pHostEntry->h_addr)->s_addr;
 
     // Attempt to connect to the remote server.
     if( connect( m_Sock, (struct sockaddr *) &svAddr, sizeof (svAddr)) == SOCKET_ERROR)



Mime
View raw message