summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorStephen D. Huston <shuston@apache.org>2009-10-12 23:52:31 +0000
committerStephen D. Huston <shuston@apache.org>2009-10-12 23:52:31 +0000
commitc334c00f057442d8a0f87d0d64291446b10b5942 (patch)
tree6929a933de1a0e023bd210af34f898b02f907e93 /cpp/src
parentc27427b9c259e29f89a392ac5f786ff41f24709b (diff)
downloadqpid-python-c334c00f057442d8a0f87d0d64291446b10b5942.tar.gz
Add new SocketAddress.cpp and requisite adjustments; a few install improvements
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@824545 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/CMakeLists.txt7
-rw-r--r--cpp/src/qpid/sys/windows/AsynchIO.cpp2
-rwxr-xr-xcpp/src/qpid/sys/windows/Socket.cpp61
-rw-r--r--cpp/src/qpid/sys/windows/SocketAddress.cpp70
4 files changed, 108 insertions, 32 deletions
diff --git a/cpp/src/CMakeLists.txt b/cpp/src/CMakeLists.txt
index 8f2ccda91d..0c8606c4de 100644
--- a/cpp/src/CMakeLists.txt
+++ b/cpp/src/CMakeLists.txt
@@ -333,6 +333,7 @@ if (CMAKE_SYSTEM_NAME STREQUAL Windows)
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 @@ set_target_properties (qpidbroker PROPERTIES VERSION ${qpidc_version})
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 @@ add_library (qmf SHARED ${qmf_SOURCES})
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 @@ add_library (qmfengine SHARED ${qmfengine_SOURCES})
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})
diff --git a/cpp/src/qpid/sys/windows/AsynchIO.cpp b/cpp/src/qpid/sys/windows/AsynchIO.cpp
index 475b18600d..971f0bb665 100644
--- a/cpp/src/qpid/sys/windows/AsynchIO.cpp
+++ b/cpp/src/qpid/sys/windows/AsynchIO.cpp
@@ -216,7 +216,7 @@ AsynchConnector::AsynchConnector(const Socket& sock,
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;
}
diff --git a/cpp/src/qpid/sys/windows/Socket.cpp b/cpp/src/qpid/sys/windows/Socket.cpp
index a89b0dff1b..8e6233bbf8 100755
--- a/cpp/src/qpid/sys/windows/Socket.cpp
+++ b/cpp/src/qpid/sys/windows/Socket.cpp
@@ -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 @@ Socket::Socket(IOHandlePrivate* h) :
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::setNonblocking() const {
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));
}
diff --git a/cpp/src/qpid/sys/windows/SocketAddress.cpp b/cpp/src/qpid/sys/windows/SocketAddress.cpp
new file mode 100644
index 0000000000..a3e03c9be8
--- /dev/null
+++ b/cpp/src/qpid/sys/windows/SocketAddress.cpp
@@ -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;
+}
+
+}}