diff options
| author | Andrew Stitcher <astitcher@apache.org> | 2009-10-09 03:38:15 +0000 |
|---|---|---|
| committer | Andrew Stitcher <astitcher@apache.org> | 2009-10-09 03:38:15 +0000 |
| commit | d5dd2ec98167c5c5b00a14edc471d5f7e2a312a4 (patch) | |
| tree | de2538d65dd68f9201a3ccc59609f4ecaaed09d4 /cpp/src/qpid/sys | |
| parent | 7d7ba3c0a123df4e2af0ae19bec67ae40f58111f (diff) | |
| download | qpid-python-d5dd2ec98167c5c5b00a14edc471d5f7e2a312a4.tar.gz | |
Added in passive socket address to SocketAddress and use in Socket::listen()
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@823391 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/sys')
| -rw-r--r-- | cpp/src/qpid/sys/posix/Socket.cpp | 11 | ||||
| -rw-r--r-- | cpp/src/qpid/sys/posix/SocketAddress.cpp | 11 |
2 files changed, 15 insertions, 7 deletions
diff --git a/cpp/src/qpid/sys/posix/Socket.cpp b/cpp/src/qpid/sys/posix/Socket.cpp index c309e2d6a2..02004b1999 100644 --- a/cpp/src/qpid/sys/posix/Socket.cpp +++ b/cpp/src/qpid/sys/posix/Socket.cpp @@ -161,15 +161,14 @@ int Socket::listen(uint16_t port, int backlog) const const int& socket = impl->fd; int yes=1; QPID_POSIX_CHECK(setsockopt(socket,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(yes))); - struct sockaddr_in name; - name.sin_family = AF_INET; - name.sin_port = htons(port); - name.sin_addr.s_addr = 0; - if (::bind(socket, (struct sockaddr*)&name, sizeof(name)) < 0) + + SocketAddress sa("", boost::lexical_cast<std::string>(port)); + if (::bind(socket, getAddrInfo(sa).ai_addr, getAddrInfo(sa).ai_addrlen) < 0) throw Exception(QPID_MSG("Can't bind to port " << port << ": " << strError(errno))); if (::listen(socket, backlog) < 0) throw Exception(QPID_MSG("Can't listen on port " << port << ": " << strError(errno))); - + + struct sockaddr_in name; socklen_t namelen = sizeof(name); if (::getsockname(socket, (struct sockaddr*)&name, &namelen) < 0) throw QPID_POSIX_ERROR(errno); diff --git a/cpp/src/qpid/sys/posix/SocketAddress.cpp b/cpp/src/qpid/sys/posix/SocketAddress.cpp index 79008d3944..fe8812299c 100644 --- a/cpp/src/qpid/sys/posix/SocketAddress.cpp +++ b/cpp/src/qpid/sys/posix/SocketAddress.cpp @@ -39,7 +39,16 @@ SocketAddress::SocketAddress(const std::string& host0, const std::string& port0) ::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; - int n = ::getaddrinfo(host.c_str(), port.c_str(), &hints, &addrInfo); + + 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))); } |
