You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by sh...@apache.org on 2009/10/13 01:52:31 UTC

svn commit: r824545 - in /qpid/trunk/qpid/cpp: CMakeLists.txt src/CMakeLists.txt src/qpid/sys/windows/AsynchIO.cpp src/qpid/sys/windows/Socket.cpp src/qpid/sys/windows/SocketAddress.cpp

Author: shuston
Date: Mon Oct 12 23:52:31 2009
New Revision: 824545

URL: http://svn.apache.org/viewvc?rev=824545&view=rev
Log:
Add new SocketAddress.cpp and requisite adjustments; a few install improvements

Added:
    qpid/trunk/qpid/cpp/src/qpid/sys/windows/SocketAddress.cpp   (with props)
Modified:
    qpid/trunk/qpid/cpp/CMakeLists.txt
    qpid/trunk/qpid/cpp/src/CMakeLists.txt
    qpid/trunk/qpid/cpp/src/qpid/sys/windows/AsynchIO.cpp
    qpid/trunk/qpid/cpp/src/qpid/sys/windows/Socket.cpp

Modified: qpid/trunk/qpid/cpp/CMakeLists.txt
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/CMakeLists.txt?rev=824545&r1=824544&r2=824545&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/CMakeLists.txt (original)
+++ qpid/trunk/qpid/cpp/CMakeLists.txt Mon Oct 12 23:52:31 2009
@@ -101,6 +101,27 @@
        "Directory to load client plug-in modules from")
   set (QPIDD_MODULE_DIR plugins/broker CACHE STRING
        "Directory to load broker plug-in modules from")
+
+  # The WCF/C++ client is built separately (it doesn't have a CMakeLists.txt)
+  # but installed with the C++ components on Windows.
+  # Don't freak out if it's not there (but it may be good to freak out if
+  # building the real one...)
+  install (PROGRAMS
+           ../wcf/src/Apache/Qpid/Channel/bin/Debug/Apache.Qpid.Channel.dll
+           ../wcf/src/Apache/Qpid/Channel/bin/Debug/Apache.Qpid.Interop.dll
+           DESTINATION ${QPID_INSTALL_LIBDIR}
+           COMPONENT ${QPID_COMPONENT_CLIENT}
+           OPTIONAL)
+# Not sure about this syntax yet... or how to only do it if Client is installed.
+#  set (CPACK_NSIS_EXTRA_INSTALL_COMMANDS "
+#       gacutil -I '$INSTDIR\\${QPID_INSTALL_LIBDIR}\\Apache.Qpid.Channel.dll'
+#       gacutil -I '$INSTDIR\\${QPID_INSTALL_LIBDIR}\\Apache.Qpid.Interop.dll'
+#      ")
+#  set (CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS "
+#       gacutil /u 'Apache.Qpid.Channel'
+#       gacutil /u 'Apache.Qpid.Interop'
+#      ")
+
 endif (WIN32)
 if (CMAKE_SYSTEM_NAME STREQUAL Linux)
   # Set up install locations. Since the Linux install puts some files in

Modified: qpid/trunk/qpid/cpp/src/CMakeLists.txt
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/CMakeLists.txt?rev=824545&r1=824544&r2=824545&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/CMakeLists.txt (original)
+++ qpid/trunk/qpid/cpp/src/CMakeLists.txt Mon Oct 12 23:52:31 2009
@@ -333,6 +333,7 @@
     qpid/sys/windows/PollableCondition.cpp
     qpid/sys/windows/Shlib.cpp
     qpid/sys/windows/Socket.cpp
+    qpid/sys/windows/SocketAddress.cpp
     qpid/sys/windows/StrError.cpp
     qpid/sys/windows/SystemInfo.cpp
     qpid/sys/windows/Thread.cpp
@@ -739,7 +740,7 @@
 if (MSVC)
   set_target_properties (qpidbroker PROPERTIES COMPILE_FLAGS /wd4290)
 endif (MSVC)
-install (TARGETS qpidbroker LIBRARY
+install (TARGETS qpidbroker
          DESTINATION ${QPID_INSTALL_LIBDIR}
          COMPONENT ${QPID_COMPONENT_BROKER})
 
@@ -773,7 +774,7 @@
 target_link_libraries (qmf qmfengine)
 set_target_properties (qmf PROPERTIES
                        VERSION ${qmf_version})
-install (TARGETS qmf LIBRARY
+install (TARGETS qmf OPTIONAL
          DESTINATION ${QPID_INSTALL_LIBDIR}
          COMPONENT ${QPID_COMPONENT_QMF})
 
@@ -807,7 +808,7 @@
 target_link_libraries (qmfengine qpidclient)
 set_target_properties (qmfengine PROPERTIES
                        VERSION ${qmfengine_version})
-install (TARGETS qmfengine
+install (TARGETS qmfengine OPTIONAL
          DESTINATION ${QPID_INSTALL_LIBDIR}
          COMPONENT ${QPID_COMPONENT_QMF})
 

Modified: qpid/trunk/qpid/cpp/src/qpid/sys/windows/AsynchIO.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/windows/AsynchIO.cpp?rev=824545&r1=824544&r2=824545&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/sys/windows/AsynchIO.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/sys/windows/AsynchIO.cpp Mon Oct 12 23:52:31 2009
@@ -216,7 +216,7 @@
         connCallback(socket);
     } catch(std::exception& e) {
         if (failCallback)
-            failCallback(-1, std::string(e.what()));
+            failCallback(socket, -1, std::string(e.what()));
         socket.close();
         delete &socket;
     }

Modified: qpid/trunk/qpid/cpp/src/qpid/sys/windows/Socket.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/windows/Socket.cpp?rev=824545&r1=824544&r2=824545&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/sys/windows/Socket.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/sys/windows/Socket.cpp Mon Oct 12 23:52:31 2009
@@ -20,19 +20,18 @@
  */
 
 #include "qpid/sys/Socket.h"
+#include "qpid/sys/SocketAddress.h"
 #include "qpid/sys/windows/IoHandlePrivate.h"
 #include "qpid/sys/windows/check.h"
 #include "qpid/sys/Time.h"
 
 #include <cstdlib>
 #include <string.h>
-#include <iostream>
-#include <memory.h>
 
 #include <winsock2.h>
-#include <ws2tcpip.h>
 
 #include <boost/format.hpp>
+#include <boost/lexical_cast.hpp>
 
 // Need to initialize WinSock. Ideally, this would be a singleton or embedded
 // in some one-time initialization function. I tried boost singleton and could
@@ -149,6 +148,27 @@
 	IOHandle(h)
 {}
 
+void
+Socket::createSocket(const SocketAddress& sa) const
+{
+    SOCKET& socket = impl->fd;
+    if (socket != INVALID_SOCKET) Socket::close();
+
+    SOCKET s = ::socket (getAddrInfo(sa).ai_family,
+                         getAddrInfo(sa).ai_socktype,
+                         0);
+    if (s == INVALID_SOCKET) throw QPID_WINDOWS_ERROR(WSAGetLastError());
+    socket = s;
+
+    try {
+        if (nonblocking) setNonblocking();
+    } catch (std::exception&) {
+        closesocket(s);
+        socket = INVALID_SOCKET;
+        throw;
+    }
+}
+
 void Socket::setTimeout(const Duration& interval) const
 {
     const SOCKET& socket = impl->fd;
@@ -170,41 +190,26 @@
 
 void Socket::connect(const std::string& host, uint16_t port) const
 {
-    std::stringstream portstream;
-    portstream << port << std::ends;
-    std::string portstr = portstream.str();
-    std::stringstream namestream;
-    namestream << host << ":" << port;
-    connectname = namestream.str();
+    SocketAddress sa(host, boost::lexical_cast<std::string>(port));
+    connect(sa);
+}
 
+void
+Socket::connect(const SocketAddress& addr) const
+{
     const SOCKET& socket = impl->fd;
-    // TODO: Be good to make this work for IPv6 as well as IPv4. Would require
-    // other changes, such as waiting to create the socket until after we
-    // have the address family. Maybe unbundle the translation of names here;
-    // use TcpAddress to resolve things and make this class take a TcpAddress
-    // and grab its address family to create the socket.
-    struct addrinfo hints;
-    memset(&hints, 0, sizeof(hints));
-    hints.ai_family = AF_INET;   // We always creating AF_INET-only sockets.
-    hints.ai_socktype = SOCK_STREAM; // We always do TCP
-    addrinfo *addrs;
-    int status = getaddrinfo(host.c_str(), portstr.c_str(), &hints, &addrs);
-    if (status != 0)
-        throw Exception(QPID_MSG("Cannot resolve " << host << ": " <<
-                                 gai_strerror(status)));
-    addrinfo *addr = addrs;
+    const addrinfo *addrs = &(getAddrInfo(addr));
     int error = 0;
     WSASetLastError(0);
-    while (addr != 0) {
-        if ((::connect(socket, addr->ai_addr, addr->ai_addrlen) == 0) ||
+    while (addrs != 0) {
+        if ((::connect(socket, addrs->ai_addr, addrs->ai_addrlen) == 0) ||
             (WSAGetLastError() == WSAEWOULDBLOCK))
             break;
         // Error... save this error code and see if there are other address
         // to try before throwing the exception.
         error = WSAGetLastError();
-        addr = addr->ai_next;
+        addrs = addrs->ai_next;
     }
-    freeaddrinfo(addrs);
     if (error)
         throw qpid::Exception(QPID_MSG(strError(error) << ": " << connectname));
 }

Added: qpid/trunk/qpid/cpp/src/qpid/sys/windows/SocketAddress.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/windows/SocketAddress.cpp?rev=824545&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/sys/windows/SocketAddress.cpp (added)
+++ qpid/trunk/qpid/cpp/src/qpid/sys/windows/SocketAddress.cpp Mon Oct 12 23:52:31 2009
@@ -0,0 +1,70 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#include "qpid/sys/SocketAddress.h"
+
+#include "qpid/sys/windows/check.h"
+
+#include <ws2tcpip.h>
+#include <string.h>
+
+namespace qpid {
+namespace sys {
+
+SocketAddress::SocketAddress(const std::string& host0, const std::string& port0) :
+    host(host0),
+    port(port0),
+    addrInfo(0)
+{
+    ::addrinfo hints;
+    ::memset(&hints, 0, sizeof(hints));
+    hints.ai_family = AF_INET; // In order to allow AF_INET6 we'd have to change createTcp() as well
+    hints.ai_socktype = SOCK_STREAM;
+
+    const char* node = 0;
+    if (host.empty()) {
+        hints.ai_flags |= AI_PASSIVE;
+    } else {
+        node = host.c_str();
+    }
+    const char* service = port.empty() ? "0" : port.c_str();
+
+    int n = ::getaddrinfo(node, service, &hints, &addrInfo);
+    if (n != 0)
+        throw Exception(QPID_MSG("Cannot resolve " << host << ": " << ::gai_strerror(n)));
+}
+
+SocketAddress::~SocketAddress()
+{
+    ::freeaddrinfo(addrInfo);
+}
+
+std::string SocketAddress::asString() const
+{
+    return host + ":" + port;
+}
+
+const ::addrinfo& getAddrInfo(const SocketAddress& sa)
+{
+    return *sa.addrInfo;
+}
+
+}}

Propchange: qpid/trunk/qpid/cpp/src/qpid/sys/windows/SocketAddress.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: qpid/trunk/qpid/cpp/src/qpid/sys/windows/SocketAddress.cpp
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org