You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2006/10/03 19:43:55 UTC

svn commit: r452581 - in /incubator/activemq/activemq-cpp/trunk/activemq-cpp: ./ src/main/activemq/network/ src/main/activemq/util/

Author: chirino
Date: Tue Oct  3 10:43:55 2006
New Revision: 452581

URL: http://svn.apache.org/viewvc?view=rev&rev=452581
Log:
We can now use automake to compile on cygwin.  
 - Use standard bsd socket calls instead of the winsock crap (perhaps we should switch back to the win sock crap though.. example program core dumps when it terminates)
 - Cygwin does not implement the uuid apis.. so use the Windows versions for that
 - Cygwin does not define/implement the addrinfo struct and related fuctions so use gethostbyname instead

Modified:
    incubator/activemq/activemq-cpp/trunk/activemq-cpp/configure.ac
    incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/ServerSocket.cpp
    incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketInputStream.cpp
    incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketOutputStream.cpp
    incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/TcpSocket.cpp
    incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/TcpSocket.h
    incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Guid.cpp
    incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Guid.h

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/configure.ac
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/configure.ac?view=diff&rev=452581&r1=452580&r2=452581
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/configure.ac (original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/configure.ac Tue Oct  3 10:43:55 2006
@@ -75,7 +75,7 @@
   cygwin* ) ## Cygwin configuration
     # LIBS="-lwinmm -lm";
     CFLAGS="$CFLAGS -pthread" 
-    LIBS="$LIBS -lm -lpthread"
+    LIBS="$LIBS -lm -lpthread -luuid -lrpcrt4"
     ;;
 
   *) ## Unix configuration
@@ -86,6 +86,33 @@
     CFLAGS="$CFLAGS -pthread" 
     LIBS="$LIBS -lm -lpthread -luuid"
 esac
+
+##
+## Not all platforms define addrinfo and related functions
+##
+AC_MSG_CHECKING([whether struct addrinfo is defined])
+AC_TRY_COMPILE(
+  [ #include <stdio.h>
+    #ifdef HAVE_UNISTD_H
+    # include <unistd.h>
+    #endif
+    #include <sys/types.h>
+    #include <sys/socket.h>
+    #include <netdb.h>
+  ],
+  [
+    do {
+      struct addrinfo a;
+      (void) a.ai_flags;
+    } while(0)
+  ],
+  [ 
+    AC_MSG_RESULT(yes)
+    AC_DEFINE(HAVE_STRUCT_ADDRINFO,, [define if you have struct addrinfo])
+  ],
+  [
+    AC_MSG_RESULT(no)
+  ])
 
 DX_HTML_FEATURE(ON)
 DX_CHM_FEATURE(OFF)

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/ServerSocket.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/ServerSocket.cpp?view=diff&rev=452581&r1=452580&r2=452581
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/ServerSocket.cpp (original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/ServerSocket.cpp Tue Oct  3 10:43:55 2006
@@ -128,13 +128,15 @@
     bind_addr.sin_port = htons((short)port);
     bind_addr.sin_addr.s_addr = 0; // To be set later down...
     memset(&bind_addr.sin_zero, 0, sizeof(bind_addr.sin_zero));
-
+	int status;
+	
     // Resolve name
+#if defined(HAVE_STRUCT_ADDRINFO)    
     ::addrinfo hints;
     memset(&hints, 0, sizeof(addrinfo));
     hints.ai_family = PF_INET;
     struct addrinfo *res_ptr = NULL;
-    int status = ::getaddrinfo(host, NULL, &hints, &res_ptr);
+    status = ::getaddrinfo(host, NULL, &hints, &res_ptr);
     if( status != 0 || res_ptr == NULL) {
         throw SocketException( __FILE__, __LINE__, ::strerror( errno ) );
     }
@@ -143,6 +145,14 @@
     assert(sizeof(((sockaddr_in*)res_ptr->ai_addr)->sin_addr.s_addr) == 4);
     bind_addr.sin_addr.s_addr = ((sockaddr_in*)res_ptr->ai_addr)->sin_addr.s_addr;
     freeaddrinfo(res_ptr);
+#else
+	struct ::hostent *he = ::gethostbyname(host);
+	if( he == NULL ) {
+        throw SocketException( __FILE__, __LINE__, "Failed to resolve hostname" );
+	}
+	bind_addr.sin_addr.s_addr = *((in_addr_t *)he->h_addr);
+#endif
+
 
     // Set the socket to reuse the address.
     int value = 1;

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketInputStream.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketInputStream.cpp?view=diff&rev=452581&r1=452580&r2=452581
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketInputStream.cpp (original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketInputStream.cpp Tue Oct  3 10:43:55 2006
@@ -14,8 +14,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
- 
-#if (defined(unix) || defined(__APPLE__)) && !defined(__CYGWIN__)
+
+#include <activemq/util/Config.h>
+
+#if !defined(HAVE_WINSOCK2_H) 
     #include <sys/poll.h>
     #include <sys/socket.h>
     #include <errno.h>
@@ -50,8 +52,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 int SocketInputStream::available() const{
    
-   
-#if defined(unix) && !defined(__CYGWIN__)
+#if !defined(HAVE_WINSOCK2_H) 
     
     // Poll the socket for input.
     pollfd fd;
@@ -108,7 +109,7 @@
         // Check for typical error conditions.
         if( len < 0 )
         {
-            #if defined(unix) && !defined(__CYGWIN__)
+			#if !defined(HAVE_WINSOCK2_H) 
          
                 // If the socket was temporarily unavailable - just try again.
                 if( errno == EAGAIN ){

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketOutputStream.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketOutputStream.cpp?view=diff&rev=452581&r1=452580&r2=452581
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketOutputStream.cpp (original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/SocketOutputStream.cpp Tue Oct  3 10:43:55 2006
@@ -16,8 +16,9 @@
  */
  
 #include "SocketOutputStream.h"
+#include <activemq/util/Config.h>
 
-#if defined( unix ) && !defined( __CYGWIN__ )
+#if !defined(HAVE_WINSOCK2_H)
     #include <sys/socket.h>
     extern int errno;
 #else

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/TcpSocket.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/TcpSocket.cpp?view=diff&rev=452581&r1=452580&r2=452581
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/TcpSocket.cpp (original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/TcpSocket.cpp Tue Oct  3 10:43:55 2006
@@ -48,7 +48,7 @@
 using namespace activemq::network;
 using namespace activemq::io;
 
-#if !defined( unix ) || defined( __CYGWIN__ )
+#if defined(HAVE_WINSOCK2_H)
 
     // Static socket initializer needed for winsock
 
@@ -79,7 +79,7 @@
     inputStream = NULL;
     outputStream = NULL;
    
-    #if !defined( unix ) || defined( __CYGWIN__ )
+	#if defined(HAVE_WINSOCK2_H)
         if( staticSocketInitializer.getSocketInitError() != NULL ) {
             throw *staticSocketInitializer.getSocketInitError();
         }
@@ -139,24 +139,34 @@
     target_addr.sin_addr.s_addr = 0; // To be set later down...
     memset( &target_addr.sin_zero, 0, sizeof( target_addr.sin_zero ) );
 
+	int status;
+	
     // Resolve name
+#if defined(HAVE_STRUCT_ADDRINFO)    
     addrinfo hints;
     memset(&hints, 0, sizeof(addrinfo));
     hints.ai_family = PF_INET;
     struct addrinfo *res_ptr = NULL;
     
-    int status = ::getaddrinfo( host, NULL, &hints, &res_ptr );
+    status = ::getaddrinfo( host, NULL, &hints, &res_ptr );
     if( status != 0 || res_ptr == NULL){      
         throw SocketException( __FILE__, __LINE__, 
             "Socket::connect - %s", ::strerror( errno ) );        
     }
-    
+     
     assert(res_ptr->ai_addr->sa_family == AF_INET);
     // Porting: On both 32bit and 64 bit systems that we compile to soo far, sin_addr 
     // is a 32 bit value, not an unsigned long.
     assert( sizeof( ( ( sockaddr_in* )res_ptr->ai_addr )->sin_addr.s_addr ) == 4 );
     target_addr.sin_addr.s_addr = ( ( sockaddr_in* )res_ptr->ai_addr )->sin_addr.s_addr;
     freeaddrinfo( res_ptr );
+#else
+	struct ::hostent *he = ::gethostbyname(host);
+	if( he == NULL ) {
+        throw SocketException( __FILE__, __LINE__, "Failed to resolve hostname" );
+	}
+	target_addr.sin_addr.s_addr = *((in_addr_t *)he->h_addr);
+#endif
    
     // Attempt the connection to the server.
     status = ::connect( socketHandle, 
@@ -193,7 +203,7 @@
     {
         ::shutdown( socketHandle, 2 );
         
-        #if defined(unix) && !defined(__CYGWIN__)
+		#if !defined(HAVE_WINSOCK2_H)
             ::close( socketHandle );
         #else
            ::closesocket( socketHandle );
@@ -287,7 +297,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 void TcpSocket::setSoTimeout ( const int millisecs ) throw ( SocketException )
 {
-    #if defined( unix ) && !defined( __CYGWIN__ )
+	#if !defined(HAVE_WINSOCK2_H)
         timeval timot;
         timot.tv_sec = millisecs / 1000;
         timot.tv_usec = (millisecs % 1000) * 1000;
@@ -302,7 +312,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 int TcpSocket::getSoTimeout() const throw( SocketException )
 {
-    #if defined( unix ) && !defined( __CYGWIN__ )
+	#if !defined(HAVE_WINSOCK2_H)
         timeval timot;
         timot.tv_sec = 0;
         timot.tv_usec = 0;
@@ -314,7 +324,7 @@
   
     ::getsockopt(socketHandle, SOL_SOCKET, SO_RCVTIMEO, (char*) &timot, &size);
   
-    #if defined( unix ) && !defined( __CYGWIN__ )
+	#if !defined(HAVE_WINSOCK2_H)
         return (timot.tv_sec * 1000) + (timot.tv_usec / 1000);
     #else
         return timot;

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/TcpSocket.h
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/TcpSocket.h?view=diff&rev=452581&r1=452580&r2=452581
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/TcpSocket.h (original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/network/TcpSocket.h Tue Oct  3 10:43:55 2006
@@ -22,6 +22,8 @@
 #include <activemq/io/InputStream.h>
 #include <activemq/io/OutputStream.h>
 
+#include <activemq/util/Config.h>
+
 namespace activemq{
 namespace network{
    
@@ -201,7 +203,7 @@
        
     protected:
    
-        #if !defined( unix ) || defined( __CYGWIN__ )
+		#if defined(HAVE_WINSOCK2_H)
       
             // WINDOWS needs initialization of winsock
             class StaticSocketInitializer {

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Guid.cpp
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Guid.cpp?view=diff&rev=452581&r1=452580&r2=452581
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Guid.cpp (original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Guid.cpp Tue Oct  3 10:43:55 2006
@@ -25,7 +25,7 @@
 Guid::Guid(void)
 {
     // Clear internal uuid, would pass isNull
-    #if (defined( unix ) || defined(__APPLE__)) && !defined( __CYGWIN__ )
+    #if (defined( HAVE_UUID_H ) || defined(HAVE_UUID_UUID_H)) 
         memset(&uuid, 0, sizeof(uuid_t));
     #else
         ::UuidCreateNil(&uuid);
@@ -62,7 +62,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 bool Guid::isNull(void) const
 {
-    #if (defined( unix ) || defined(__APPLE__)) && !defined( __CYGWIN__ )
+    #if !defined(HAVE_OBJBASE_H) 
         // Check the uuid APIs is null method
         return uuid_is_null(*(const_cast<uuid_t*>(&uuid))) == 1 ? true : false;
     #else
@@ -77,7 +77,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 void Guid::setNull(void)
 {
-    #if (defined( unix ) || defined(__APPLE__)) && !defined( __CYGWIN__ )
+    #if !defined(HAVE_OBJBASE_H) 
         // use the uuid function to clear
         uuid_clear(uuid);
     #else
@@ -88,7 +88,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 Guid& Guid::createGUID(void) throw( RuntimeException )
 {
-    #if (defined( unix ) || defined(__APPLE__)) && !defined( __CYGWIN__ )
+    #if !defined(HAVE_OBJBASE_H) 
         // Use the uuid_generate method to create a new GUID
         uuid_generate(uuid);
     #else
@@ -111,7 +111,7 @@
 {
     std::string uuid_str = "";
 
-    #if (defined( unix ) || defined(__APPLE__)) && !defined( __CYGWIN__ )
+    #if !defined(HAVE_OBJBASE_H) 
         // Create storage for the string buffer
         char buffer[36] = {0};
       
@@ -155,7 +155,7 @@
     unsigned char* buffer = new unsigned char[getRawBytesSize()];
    
     // copy our buffer
-    #if (defined( unix ) || defined(__APPLE__)) && !defined( __CYGWIN__ )
+    #if !defined(HAVE_OBJBASE_H) 
         uuid_copy(buffer, *(const_cast<uuid_t*>(&uuid)));
     #else
         memcpy(buffer, &uuid, getRawBytesSize());
@@ -176,7 +176,7 @@
     }
    
     // Copy the data
-    #if (defined( unix ) || defined(__APPLE__)) && !defined( __CYGWIN__ )
+    #if !defined(HAVE_OBJBASE_H) 
         memcpy(uuid, bytes, getRawBytesSize());
     #else
         memcpy(&uuid, bytes, getRawBytesSize());
@@ -188,7 +188,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 int Guid::getRawBytesSize(void) const
 {
-    #if (defined( unix ) || defined(__APPLE__)) && !defined( __CYGWIN__ )
+    #if !defined(HAVE_OBJBASE_H) 
         return sizeof(uuid_t);
     #else
         return sizeof(::GUID);
@@ -198,7 +198,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 Guid::operator const unsigned char*() const
 {
-    #if (defined( unix ) || defined(__APPLE__)) && !defined( __CYGWIN__ )
+    #if !defined(HAVE_OBJBASE_H) 
         return &uuid[0];
     #else
         return reinterpret_cast<const unsigned char*>(&uuid);
@@ -209,7 +209,7 @@
 Guid& Guid::operator=( const Guid& source )
    throw ( IllegalArgumentException )
 {
-    #if (defined( unix ) || defined(__APPLE__)) && !defined( __CYGWIN__ )
+    #if !defined(HAVE_OBJBASE_H) 
         // Use the uuid method to copy
         uuid_copy(uuid, *(const_cast<uuid_t*>(&source.uuid)));
     #else
@@ -224,7 +224,7 @@
 Guid& Guid::operator=( const std::string& source ) 
     throw ( IllegalArgumentException )
 {
-    #if (defined( unix ) || defined(__APPLE__)) && !defined( __CYGWIN__ )
+    #if !defined(HAVE_OBJBASE_H) 
         // Parse a uuid from the passed in string
         uuid_parse( const_cast<char*>(source.c_str()), uuid );
     #else
@@ -252,7 +252,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 bool Guid::operator==( const Guid& source ) const
 {
-    #if (defined( unix ) || defined(__APPLE__)) && !defined( __CYGWIN__ )
+    #if !defined(HAVE_OBJBASE_H) 
         // uuid_compare returns 0 for equal
         return uuid_compare(
                 *(const_cast<uuid_t*>(&uuid)), 
@@ -290,7 +290,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 bool Guid::operator<( const Guid& source ) const
 {
-    #if (defined( unix ) || defined(__APPLE__)) && !defined( __CYGWIN__ )
+    #if !defined(HAVE_OBJBASE_H) 
         // uuid_compare returns 0 for equal
         return uuid_compare(
                  *(const_cast<uuid_t*>(&uuid)), 
@@ -316,7 +316,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 bool Guid::operator<=( const Guid& source ) const
 {
-    #if (defined( unix ) || defined(__APPLE__)) && !defined( __CYGWIN__ )
+    #if !defined(HAVE_OBJBASE_H) 
         // uuid_compare returns 0 for equal
         return uuid_compare(
                  *(const_cast<uuid_t*>(&uuid)), 
@@ -342,7 +342,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 bool Guid::operator>( const Guid& source ) const
 {
-    #if (defined( unix ) || defined(__APPLE__)) && !defined( __CYGWIN__ )
+    #if !defined(HAVE_OBJBASE_H) 
         // uuid_compare returns 0 for equal
         return uuid_compare(
                  *(const_cast<uuid_t*>(&uuid)), 
@@ -368,7 +368,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 bool Guid::operator>=( const Guid& source ) const
 {
-    #if (defined( unix ) || defined(__APPLE__)) && !defined( __CYGWIN__ )
+    #if !defined(HAVE_OBJBASE_H) 
         // uuid_compare returns 0 for equal
         return uuid_compare(
                  *(const_cast<uuid_t*>(&uuid)), 

Modified: incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Guid.h
URL: http://svn.apache.org/viewvc/incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Guid.h?view=diff&rev=452581&r1=452580&r2=452581
==============================================================================
--- incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Guid.h (original)
+++ incubator/activemq/activemq-cpp/trunk/activemq-cpp/src/main/activemq/util/Guid.h Tue Oct  3 10:43:55 2006
@@ -21,17 +21,14 @@
 #include <activemq/exceptions/IllegalArgumentException.h>
 #include <activemq/util/Config.h>
 
-#if defined(HAVE_UUID_UUID_H)
-    #include <uuid/uuid.h>
-#endif
-#if defined(HAVE_UUID_H)
-    #include "uuid.h"
-#endif
-#if defined(HAVE_OBJBASE_H)
+// #if defined(HAVE_OBJBASE_H) && defined(HAVE_RPCDCE_H) 
+#if defined(HAVE_OBJBASE_H)  
     #include <objbase.h>
-#endif
-#if defined(HAVE_RPCDCE_H)
     #include <rpcdce.h>
+#elif defined(HAVE_UUID_UUID_H)
+    #include <uuid/uuid.h>    
+#elif defined(HAVE_UUID_H)
+    #include <uuid.h>
 #endif
 
 #include <string>