Author: astitcher Date: Fri Oct 9 03:38:15 2009 New Revision: 823391 URL: http://svn.apache.org/viewvc?rev=823391&view=rev Log: Added in passive socket address to SocketAddress and use in Socket::listen()
Modified: qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.cpp qpid/trunk/qpid/cpp/src/qpid/sys/posix/SocketAddress.cpp Modified: qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.cpp URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.cpp?rev=823391&r1=823390&r2=823391&view=diff ============================================================================== --- qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.cpp (original) +++ qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.cpp Fri Oct 9 03:38:15 2009 @@ -161,15 +161,14 @@ 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); Modified: qpid/trunk/qpid/cpp/src/qpid/sys/posix/SocketAddress.cpp URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/posix/SocketAddress.cpp?rev=823391&r1=823390&r2=823391&view=diff ============================================================================== --- qpid/trunk/qpid/cpp/src/qpid/sys/posix/SocketAddress.cpp (original) +++ qpid/trunk/qpid/cpp/src/qpid/sys/posix/SocketAddress.cpp Fri Oct 9 03:38:15 2009 @@ -39,7 +39,16 @@ ::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))); } --------------------------------------------------------------------- Apache Qpid - AMQP Messaging Implementation Project: http://qpid.apache.org Use/Interact: mailto:commits-subscr...@qpid.apache.org