You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by as...@apache.org on 2007/06/27 23:05:51 UTC
svn commit: r551327 - in /incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix:
EventChannelAcceptor.cpp Socket.cpp Socket.h
Author: astitcher
Date: Wed Jun 27 14:05:50 2007
New Revision: 551327
URL: http://svn.apache.org/viewvc?view=rev&rev=551327
Log:
Fixed missing POSIX implementation of Acceptor::getHost
Modified:
incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/EventChannelAcceptor.cpp
incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.cpp
incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.h
Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/EventChannelAcceptor.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/EventChannelAcceptor.cpp?view=diff&rev=551327&r1=551326&r2=551327
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/EventChannelAcceptor.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/EventChannelAcceptor.cpp Wed Jun 27 14:05:50 2007
@@ -18,13 +18,7 @@
* under the License.
*
*/
-#include <iostream>
-
-#include <boost/assert.hpp>
-#include <boost/ptr_container/ptr_vector.hpp>
-#include <boost/ptr_container/ptr_deque.hpp>
-#include <boost/bind.hpp>
-#include <boost/scoped_ptr.hpp>
+#include "EventChannelConnection.h"
#include "qpid/sys/ConnectionOutputHandler.h"
#include "qpid/sys/ConnectionInputHandler.h"
@@ -35,7 +29,16 @@
#include "qpid/framing/AMQFrame.h"
#include "qpid/Exception.h"
-#include "EventChannelConnection.h"
+#include <sys/socket.h>
+#include <netdb.h>
+
+#include <boost/assert.hpp>
+#include <boost/ptr_container/ptr_vector.hpp>
+#include <boost/ptr_container/ptr_deque.hpp>
+#include <boost/bind.hpp>
+#include <boost/scoped_ptr.hpp>
+
+#include <iostream>
namespace qpid {
namespace sys {
@@ -100,11 +103,19 @@
uint16_t EventChannelAcceptor::getPort() const {
return port; // Immutable no need for lock.
}
+
+std::string EventChannelAcceptor::getHost() const {
+ ::sockaddr_storage name; // big enough for any socket address
+ ::socklen_t namelen = sizeof(name);
+ if (::getsockname(listener.fd(), (::sockaddr*)&name, &namelen) < 0)
+ throw QPID_POSIX_ERROR(errno);
-uint16_t EventChannelAcceptor::getPort() const {
- return port; // Immutable no need for lock.
+ char dispName[NI_MAXHOST];
+ if (int rc=::getnameinfo((::sockaddr*)&name, namelen, dispName, sizeof(dispName), 0, 0, NI_NUMERICHOST) != 0)
+ throw QPID_POSIX_ERROR(rc);
+ return dispName;
}
-
+
void EventChannelAcceptor::run(ConnectionInputHandlerFactory* f) {
{
Mutex::ScopedLock l(lock);
Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.cpp
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.cpp?view=diff&rev=551327&r1=551326&r2=551327
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.cpp Wed Jun 27 14:05:50 2007
@@ -111,23 +111,8 @@
return ntohs(name.sin_port);
}
-
-std::string getHost() const {
- // TODO aconway 2007-06-11: Won't work for ip6
- struct sockaddr_in name;
- socklen_t namelen = sizeof(name);
- if (::getsockname(socket, (struct sockaddr*)&name, &namelen) < 0)
- throw QPID_POSIX_ERROR(errno);
- uint32_t addr = name.sin_host.s_addr;
- ostringstream os;
- os << uint8_t(addr >> 24) << '.'
- << uint8_t(addr >> 16) << '.'
- << uint8_t(addr >> 8) << '.'
- << uint8_t(addr);
- return os.str();
-}
-int Socket::fd()
+int Socket::fd() const
{
return socket;
}
Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.h
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.h?view=diff&rev=551327&r1=551326&r2=551327
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.h Wed Jun 27 14:05:50 2007
@@ -63,7 +63,7 @@
int listen(int port = 0, int backlog = 10);
/** Get file descriptor */
- int fd();
+ int fd() const;
private:
void init() const;