From df599b1716535909317e61f4b43516d48373ad1c Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Fri, 1 Feb 2008 16:03:02 +0000 Subject: Added cluster URL configuration, defaults to all interfaces. src/qpid/Plugin.h - added doxygen src/qpid/Url.cpp,.h - cache string rep, op==, istream/ostream ops. src/qpid/broker/Broker.h,.cpp - removed getUrl() src/qpid/cluster/Cluster.h,.cpp - use Url class src/qpid/cluster/ClusterPlugin.cpp - added --url configuration. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@617533 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/Url.cpp | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'cpp/src/qpid/Url.cpp') diff --git a/cpp/src/qpid/Url.cpp b/cpp/src/qpid/Url.cpp index 1e0e0b3603..d056edc683 100644 --- a/cpp/src/qpid/Url.cpp +++ b/cpp/src/qpid/Url.cpp @@ -36,10 +36,16 @@ using namespace std; namespace qpid { -Url Url::getHostnameUrl(uint16_t port) { +std::ostream& operator<<(std::ostream& os, const TcpAddress& a) { + return os << "tcp:" << a.host << ":" << a.port; +} + +std::istream& operator>>(std::istream&, const TcpAddress&); + +Url Url::getHostNameUrl(uint16_t port) { char name[HOST_NAME_MAX]; if (::gethostname(name, sizeof(name)) != 0) - throw Exception(QPID_MSG("Cannot get host name: " << strError(errno))); + throw InvalidUrl(QPID_MSG("Cannot get host name: " << strError(errno))); return Url(TcpAddress(name, port)); } @@ -66,9 +72,12 @@ Url Url::getIpAddressesUrl(uint16_t port) { } string Url::str() const { - ostringstream os; - os << *this; - return os.str(); + if (cache.empty() && !this->empty()) { + ostringstream os; + os << *this; + cache = os.str(); + } + return cache; } ostream& operator<<(ostream& os, const Url& url) { @@ -140,13 +149,22 @@ struct UrlGrammar : public grammar }; void Url::parse(const char* url) { + cache.clear(); if (!boost::spirit::parse(url, UrlGrammar(*this)).full) throw InvalidUrl(string("Invalid AMQP url: ")+url); } void Url::parseNoThrow(const char* url) { + cache.clear(); if (!boost::spirit::parse(url, UrlGrammar(*this)).full) clear(); } +std::istream& operator>>(std::istream& is, Url& url) { + std::string s; + is >> s; + url.parse(s); + return is; +} + } // namespace qpid -- cgit v1.2.1