summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2008-01-18 00:11:27 +0000
committerAlan Conway <aconway@apache.org>2008-01-18 00:11:27 +0000
commit83dee547047f0ca56d37a3a42ba2a1f4270a6b73 (patch)
tree7ceea111f47e819c5a70e9897e79960721bf4f76
parentede4f0298cb74280dd4e91efe1a7151a74058992 (diff)
downloadqpid-python-83dee547047f0ca56d37a3a42ba2a1f4270a6b73.tar.gz
Add optional host, port arguments to all example clients.
Verify can start private broker & pass host/port to examples, by default it still uses local host/standard port. Added host:port to Socket error messages. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@613018 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/cpp/examples/Makefile.am2
-rw-r--r--qpid/cpp/examples/examples/direct/declare_queues.cpp6
-rw-r--r--qpid/cpp/examples/examples/direct/direct_producer.cpp6
-rw-r--r--qpid/cpp/examples/examples/direct/listener.cpp6
-rw-r--r--qpid/cpp/examples/examples/fanout/declare_queues.cpp6
-rw-r--r--qpid/cpp/examples/examples/fanout/fanout_producer.cpp6
-rw-r--r--qpid/cpp/examples/examples/fanout/listener.cpp6
-rw-r--r--qpid/cpp/examples/examples/pub-sub/topic_listener.cpp6
-rw-r--r--qpid/cpp/examples/examples/pub-sub/topic_publisher.cpp6
-rw-r--r--qpid/cpp/examples/examples/pub-sub/verify.in1
-rw-r--r--qpid/cpp/examples/examples/request-response/client.cpp6
-rw-r--r--qpid/cpp/examples/examples/request-response/server.cpp6
-rw-r--r--qpid/cpp/examples/examples/request-response/verify.in1
-rwxr-xr-xqpid/cpp/examples/verify40
-rw-r--r--qpid/cpp/src/qpid/sys/posix/Socket.cpp16
-rw-r--r--qpid/cpp/src/qpid/sys/posix/check.h2
16 files changed, 74 insertions, 48 deletions
diff --git a/qpid/cpp/examples/Makefile.am b/qpid/cpp/examples/Makefile.am
index 73b7a84ad0..e5fc509eac 100644
--- a/qpid/cpp/examples/Makefile.am
+++ b/qpid/cpp/examples/Makefile.am
@@ -37,7 +37,7 @@ VERIFY=$(abs_top_srcdir)/examples/verify
# Build the examples in the source tree.
all-local:
- cd examples && $(MAKE) CXX="$(CXX)" CXXFLAGS="-I../../$(top_srcdir)/src -I../../$(top_srcdir)/src/gen -I../../$(top_builddir)/src/gen -L../../$(top_builddir)/src/.libs -Wl,-rpath,$(abs_top_builddir)/src/.libs" all
+ cd examples && $(MAKE) CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS) -I../../$(top_srcdir)/src -I../../$(top_srcdir)/src/gen -I../../$(top_builddir)/src/gen -L../../$(top_builddir)/src/.libs -Wl,-rpath,$(abs_top_builddir)/src/.libs" all
# Verify the examples in the buid tree.
check-local: all-local
diff --git a/qpid/cpp/examples/examples/direct/declare_queues.cpp b/qpid/cpp/examples/examples/direct/declare_queues.cpp
index 861a4329c5..d57e6a797b 100644
--- a/qpid/cpp/examples/examples/direct/declare_queues.cpp
+++ b/qpid/cpp/examples/examples/direct/declare_queues.cpp
@@ -53,11 +53,13 @@ using namespace qpid::framing;
using std::string;
-int main() {
+int main(int argc, char** argv) {
+ const char* host = argc>1 ? argv[1] : "127.0.0.1";
+ int port = argc>2 ? atoi(argv[2]) : 5672;
Connection connection;
Message msg;
try {
- connection.open("127.0.0.1", 5672);
+ connection.open(host, port);
Session session = connection.newSession();
diff --git a/qpid/cpp/examples/examples/direct/direct_producer.cpp b/qpid/cpp/examples/examples/direct/direct_producer.cpp
index 1500b77399..515e84c8d9 100644
--- a/qpid/cpp/examples/examples/direct/direct_producer.cpp
+++ b/qpid/cpp/examples/examples/direct/direct_producer.cpp
@@ -60,11 +60,13 @@ using namespace qpid::framing;
using std::stringstream;
using std::string;
-int main() {
+int main(int argc, char** argv) {
+ const char* host = argc>1 ? argv[1] : "127.0.0.1";
+ int port = argc>2 ? atoi(argv[2]) : 5672;
Connection connection;
Message message;
try {
- connection.open("127.0.0.1", 5672 );
+ connection.open(host, port);
Session session = connection.newSession();
//--------- Main body of program --------------------------------------------
diff --git a/qpid/cpp/examples/examples/direct/listener.cpp b/qpid/cpp/examples/examples/direct/listener.cpp
index a2486dd309..3f92d189de 100644
--- a/qpid/cpp/examples/examples/direct/listener.cpp
+++ b/qpid/cpp/examples/examples/direct/listener.cpp
@@ -92,11 +92,13 @@ void Listener::received(Message& message) {
-int main() {
+int main(int argc, char** argv) {
+ const char* host = argc>1 ? argv[1] : "127.0.0.1";
+ int port = argc>2 ? atoi(argv[2]) : 5672;
Connection connection;
Message msg;
try {
- connection.open("127.0.0.1", 5672);
+ connection.open(host, port);
Session session = connection.newSession();
//--------- Main body of program --------------------------------------------
diff --git a/qpid/cpp/examples/examples/fanout/declare_queues.cpp b/qpid/cpp/examples/examples/fanout/declare_queues.cpp
index f4f74ba1e9..6b1eabfeec 100644
--- a/qpid/cpp/examples/examples/fanout/declare_queues.cpp
+++ b/qpid/cpp/examples/examples/fanout/declare_queues.cpp
@@ -53,11 +53,13 @@ using namespace qpid::framing;
using std::string;
-int main() {
+int main(int argc, char** argv) {
+ const char* host = argc>1 ? argv[1] : "127.0.0.1";
+ int port = argc>2 ? atoi(argv[2]) : 5672;
Connection connection;
Message msg;
try {
- connection.open("127.0.0.1", 5672);
+ connection.open(host, port);
Session session = connection.newSession();
diff --git a/qpid/cpp/examples/examples/fanout/fanout_producer.cpp b/qpid/cpp/examples/examples/fanout/fanout_producer.cpp
index 976c53aae4..a5904e6731 100644
--- a/qpid/cpp/examples/examples/fanout/fanout_producer.cpp
+++ b/qpid/cpp/examples/examples/fanout/fanout_producer.cpp
@@ -60,11 +60,13 @@ using namespace qpid::framing;
using std::stringstream;
using std::string;
-int main() {
+int main(int argc, char** argv) {
+ const char* host = argc>1 ? argv[1] : "127.0.0.1";
+ int port = argc>2 ? atoi(argv[2]) : 5672;
Connection connection;
Message message;
try {
- connection.open("127.0.0.1", 5672 );
+ connection.open(host, port);
Session session = connection.newSession();
//--------- Main body of program --------------------------------------------
diff --git a/qpid/cpp/examples/examples/fanout/listener.cpp b/qpid/cpp/examples/examples/fanout/listener.cpp
index 9cf2bf0e4b..3f94f73f48 100644
--- a/qpid/cpp/examples/examples/fanout/listener.cpp
+++ b/qpid/cpp/examples/examples/fanout/listener.cpp
@@ -93,11 +93,13 @@ void Listener::received(Message& message) {
-int main() {
+int main(int argc, char** argv) {
+ const char* host = argc>1 ? argv[1] : "127.0.0.1";
+ int port = argc>2 ? atoi(argv[2]) : 5672;
Connection connection;
Message msg;
try {
- connection.open("127.0.0.1", 5672);
+ connection.open(host, port);
Session session = connection.newSession();
//--------- Main body of program --------------------------------------------
diff --git a/qpid/cpp/examples/examples/pub-sub/topic_listener.cpp b/qpid/cpp/examples/examples/pub-sub/topic_listener.cpp
index 323c93dd0b..7364d89abb 100644
--- a/qpid/cpp/examples/examples/pub-sub/topic_listener.cpp
+++ b/qpid/cpp/examples/examples/pub-sub/topic_listener.cpp
@@ -131,10 +131,12 @@ void Listener::listen() {
subscriptions.run();
}
-int main() {
+int main(int argc, char** argv) {
+ const char* host = argc>1 ? argv[1] : "127.0.0.1";
+ int port = argc>2 ? atoi(argv[2]) : 5672;
Connection connection;
try {
- connection.open("127.0.0.1", 5672);
+ connection.open(host, port);
Session session = connection.newSession();
//--------- Main body of program --------------------------------------------
diff --git a/qpid/cpp/examples/examples/pub-sub/topic_publisher.cpp b/qpid/cpp/examples/examples/pub-sub/topic_publisher.cpp
index 52c2827e58..ebb2f22215 100644
--- a/qpid/cpp/examples/examples/pub-sub/topic_publisher.cpp
+++ b/qpid/cpp/examples/examples/pub-sub/topic_publisher.cpp
@@ -94,11 +94,13 @@ void no_more_messages(Session& session)
session.messageTransfer(arg::content=message, arg::destination="amq.topic");
}
-int main() {
+int main(int argc, char** argv) {
+ const char* host = argc>1 ? argv[1] : "127.0.0.1";
+ int port = argc>2 ? atoi(argv[2]) : 5672;
Connection connection;
Message message;
try {
- connection.open("127.0.0.1", 5672 );
+ connection.open(host, port);
Session session = connection.newSession();
//--------- Main body of program --------------------------------------------
diff --git a/qpid/cpp/examples/examples/pub-sub/verify.in b/qpid/cpp/examples/examples/pub-sub/verify.in
index cc76bb0436..aa3227388a 100644
--- a/qpid/cpp/examples/examples/pub-sub/verify.in
+++ b/qpid/cpp/examples/examples/pub-sub/verify.in
@@ -58,4 +58,5 @@ Subscribing to queue europe
Subscribing to queue news
Subscribing to queue usa
Subscribing to queue weather
+==== ./topic_listener
====
diff --git a/qpid/cpp/examples/examples/request-response/client.cpp b/qpid/cpp/examples/examples/request-response/client.cpp
index 742acb9071..717df64be0 100644
--- a/qpid/cpp/examples/examples/request-response/client.cpp
+++ b/qpid/cpp/examples/examples/request-response/client.cpp
@@ -107,11 +107,13 @@ void Listener::received(Message& message) {
using std::stringstream;
using std::string;
-int main() {
+int main(int argc, char** argv) {
+ const char* host = argc>1 ? argv[1] : "127.0.0.1";
+ int port = argc>2 ? atoi(argv[2]) : 5672;
Connection connection;
Message request;
try {
- connection.open("127.0.0.1", 5672 );
+ connection.open(host, port);
Session session = connection.newSession();
//--------- Main body of program --------------------------------------------
diff --git a/qpid/cpp/examples/examples/request-response/server.cpp b/qpid/cpp/examples/examples/request-response/server.cpp
index 1aae49829f..4f87d8b253 100644
--- a/qpid/cpp/examples/examples/request-response/server.cpp
+++ b/qpid/cpp/examples/examples/request-response/server.cpp
@@ -124,11 +124,13 @@ void Listener::received(Message& request) {
}
-int main() {
+int main(int argc, char** argv) {
+ const char* host = argc>1 ? argv[1] : "127.0.0.1";
+ int port = argc>2 ? atoi(argv[2]) : 5672;
Connection connection;
Message message;
try {
- connection.open("127.0.0.1", 5672 );
+ connection.open(host, port);
Session session = connection.newSession();
//--------- Main body of program --------------------------------------------
diff --git a/qpid/cpp/examples/examples/request-response/verify.in b/qpid/cpp/examples/examples/request-response/verify.in
index 81777fd049..18d61b5f75 100644
--- a/qpid/cpp/examples/examples/request-response/verify.in
+++ b/qpid/cpp/examples/examples/request-response/verify.in
@@ -12,6 +12,7 @@ Response: AND THE MOME RATHS OUTGRABE.
Shutting down listener for client
====
==== remove_uuid server.out
+==== ./server
Activating request queue listener for: request
Waiting for requests
Request: Twas brillig, and the slithy toves (client )
diff --git a/qpid/cpp/examples/verify b/qpid/cpp/examples/verify
index b53afe470d..10f2226aa5 100755
--- a/qpid/cpp/examples/verify
+++ b/qpid/cpp/examples/verify
@@ -1,25 +1,21 @@
#!/bin/sh
# Run from the installed examples/ dir with a full path to this script.
-#
+# If $QPIDD is set, run a private QPIDD and use it.
+# If $QPID_HOST or $QPID_PORT are set, use them to connect.
DIR=$PWD
SRC=`dirname $0 | sed 's|^\([^/].*\)|'$PWD'/\1|'`/examples
# Start private broker if QPIDD is set.
-
if [ -n "$QPIDD" ] ; then
- # FIXME aconway 2007-12-14: Should use --port 0, need
- # to make examples clients more flexible to connect.
- #
- $QPIDD -d || { echo "Cannot start $QPIDD" ; exit 1; }
+ export QPID_PORT=`$QPIDD -dp0` || { echo "Cannot start $QPIDD" ; exit 1; }
trap "$QPIDD -q" EXIT
fi
-# Utility functions
+ARGS="${QPID_HOST:-localhost} $QPID_PORT"
-run() {
- echo ==== $*; eval "$*"; echo ====;
-}
+title() { echo ==== $*; eval "$*"; echo ====; }
+run() { echo ==== $*; eval "$* $ARGS"; echo ====; }
waitfor() { until grep -a -l "$2" $1 >/dev/null 2>&1 ; do sleep 1 ; done ; }
@@ -38,17 +34,11 @@ remove_uuid() {
# Scripts for each example
direct() {
- run ./declare_queues > verify.out
+ run ./declare_queues > verify.out
run ./direct_producer >> verify.out
run ./listener >> verify.out
}
-persistent() {
- run ./declare_queues >> verify.out
- run ./direct_persistent_producer >> verify.out
- run ./listener >> verify.out
-}
-
fanout() {
run ./declare_queues > verify.out
run ./fanout_producer >>verify.out
@@ -56,26 +46,28 @@ fanout() {
}
pub_sub() {
- ./topic_listener | tee topic_listener.out > topic_listener.wait &
+ run ./topic_listener | tee topic_listener.out > topic_listener.wait &
waitfor topic_listener.wait "Listening"
run ./topic_publisher > verify.out
- wait
- run remove_uuid "topic_listener.out | sort" >> verify.out
+ kill %%
+ wait 2> /dev/null
+ title "remove_uuid topic_listener.out | sort" >> verify.out
}
request_response() {
- ./server | tee server.out > server.wait &
+ run ./server | tee server.out > server.wait &
waitfor server.wait "Waiting"
run ./client | remove_uuid > verify.out
- kill %%
+ kill %%
wait 2> /dev/null
- run remove_uuid server.out >> verify.out
+ title "remove_uuid server.out" >> verify.out
}
# FIXME aconway 2007-12-14: put back pub-sub and persistence when fixed.
# Main
-for ex in direct fanout request-response ; do
+EXAMPLES=${*:-direct fanout pub-sub request-response}
+for ex in $EXAMPLES ; do
func=`echo $ex | tr - _`
echo "Verifing $ex"
( cd $ex && $func && verify && rm -f *.out *.wait)
diff --git a/qpid/cpp/src/qpid/sys/posix/Socket.cpp b/qpid/cpp/src/qpid/sys/posix/Socket.cpp
index f0cc8cd5a5..6e872c4fbc 100644
--- a/qpid/cpp/src/qpid/sys/posix/Socket.cpp
+++ b/qpid/cpp/src/qpid/sys/posix/Socket.cpp
@@ -113,6 +113,17 @@ void Socket::setNonblocking() const {
QPID_POSIX_CHECK(::fcntl(impl->fd, F_SETFL, O_NONBLOCK));
}
+namespace {
+const char* h_errstr(int e) {
+ switch (e) {
+ case HOST_NOT_FOUND: return "Host not found";
+ case NO_ADDRESS: return "Name does not have an IP address";
+ case TRY_AGAIN: return "A temporary error occurred on an authoritative name server.";
+ case NO_RECOVERY: return "Non-recoverable name server error";
+ default: return "Unknown error";
+ }
+}
+}
void Socket::connect(const std::string& host, int port) const
{
@@ -123,10 +134,11 @@ void Socket::connect(const std::string& host, int port) const
// TODO: Be good to make this work for IPv6 as well as IPv4
// Use more modern lookup functions
struct hostent* hp = gethostbyname ( host.c_str() );
- if (hp == 0) throw QPID_POSIX_ERROR(errno);
+ if (hp == 0)
+ throw Exception(QPID_MSG("Cannot resolve " << host << ": " << h_errstr(h_errno)));
memcpy(&name.sin_addr.s_addr, hp->h_addr_list[0], hp->h_length);
if (::connect(socket, (struct sockaddr*)(&name), sizeof(name)) < 0)
- throw QPID_POSIX_ERROR(errno);
+ throw qpid::Exception(QPID_MSG(strError(errno) << ": " << host << ":" << port));
}
void
diff --git a/qpid/cpp/src/qpid/sys/posix/check.h b/qpid/cpp/src/qpid/sys/posix/check.h
index f864bf8762..40aa0d4d27 100644
--- a/qpid/cpp/src/qpid/sys/posix/check.h
+++ b/qpid/cpp/src/qpid/sys/posix/check.h
@@ -26,7 +26,7 @@
#include <cerrno>
-#define QPID_POSIX_ERROR(ERRNO) qpid::Exception(QPID_MSG(qpid::strError(ERRNO)) << " " << ERRNO)
+#define QPID_POSIX_ERROR(ERRNO) qpid::Exception(QPID_MSG(qpid::strError(ERRNO)));
/** THROW QPID_POSIX_ERROR(errno) if RESULT is less than zero */
#define QPID_POSIX_CHECK(RESULT) \