summaryrefslogtreecommitdiff
path: root/cpp/src/qpid/Url.cpp
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2008-02-01 16:03:02 +0000
committerAlan Conway <aconway@apache.org>2008-02-01 16:03:02 +0000
commitdf599b1716535909317e61f4b43516d48373ad1c (patch)
tree7971d8abe970f9711cf5ba7d817cf57fc0b85a87 /cpp/src/qpid/Url.cpp
parente5450586ffe0d33c92eed1b4c961e9b150f4663c (diff)
downloadqpid-python-df599b1716535909317e61f4b43516d48373ad1c.tar.gz
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
Diffstat (limited to 'cpp/src/qpid/Url.cpp')
-rw-r--r--cpp/src/qpid/Url.cpp28
1 files changed, 23 insertions, 5 deletions
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<UrlGrammar>
};
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