Author: aconway
Date: Thu Jan 17 16:11:27 2008
New Revision: 613018
URL: http://svn.apache.org/viewvc?rev=613018&view=rev
Log:
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.
Modified:
incubator/qpid/trunk/qpid/cpp/examples/Makefile.am
incubator/qpid/trunk/qpid/cpp/examples/examples/direct/declare_queues.cpp
incubator/qpid/trunk/qpid/cpp/examples/examples/direct/direct_producer.cpp
incubator/qpid/trunk/qpid/cpp/examples/examples/direct/listener.cpp
incubator/qpid/trunk/qpid/cpp/examples/examples/fanout/declare_queues.cpp
incubator/qpid/trunk/qpid/cpp/examples/examples/fanout/fanout_producer.cpp
incubator/qpid/trunk/qpid/cpp/examples/examples/fanout/listener.cpp
incubator/qpid/trunk/qpid/cpp/examples/examples/pub-sub/topic_listener.cpp
incubator/qpid/trunk/qpid/cpp/examples/examples/pub-sub/topic_publisher.cpp
incubator/qpid/trunk/qpid/cpp/examples/examples/pub-sub/verify.in
incubator/qpid/trunk/qpid/cpp/examples/examples/request-response/client.cpp
incubator/qpid/trunk/qpid/cpp/examples/examples/request-response/server.cpp
incubator/qpid/trunk/qpid/cpp/examples/examples/request-response/verify.in
incubator/qpid/trunk/qpid/cpp/examples/verify
incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.cpp
incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/check.h
Modified: incubator/qpid/trunk/qpid/cpp/examples/Makefile.am
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/examples/Makefile.am?rev=613018&r1=613017&r2=613018&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/examples/Makefile.am (original)
+++ incubator/qpid/trunk/qpid/cpp/examples/Makefile.am Thu Jan 17 16:11:27 2008
@@ -37,7 +37,7 @@
# 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
Modified:
incubator/qpid/trunk/qpid/cpp/examples/examples/direct/declare_queues.cpp
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/examples/examples/direct/declare_queues.cpp?rev=613018&r1=613017&r2=613018&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/examples/examples/direct/declare_queues.cpp
(original)
+++ incubator/qpid/trunk/qpid/cpp/examples/examples/direct/declare_queues.cpp
Thu Jan 17 16:11:27 2008
@@ -53,11 +53,13 @@
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();
Modified:
incubator/qpid/trunk/qpid/cpp/examples/examples/direct/direct_producer.cpp
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/examples/examples/direct/direct_producer.cpp?rev=613018&r1=613017&r2=613018&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/examples/examples/direct/direct_producer.cpp
(original)
+++ incubator/qpid/trunk/qpid/cpp/examples/examples/direct/direct_producer.cpp
Thu Jan 17 16:11:27 2008
@@ -60,11 +60,13 @@
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 --------------------------------------------
Modified: incubator/qpid/trunk/qpid/cpp/examples/examples/direct/listener.cpp
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/examples/examples/direct/listener.cpp?rev=613018&r1=613017&r2=613018&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/examples/examples/direct/listener.cpp
(original)
+++ incubator/qpid/trunk/qpid/cpp/examples/examples/direct/listener.cpp Thu Jan
17 16:11:27 2008
@@ -92,11 +92,13 @@
-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 --------------------------------------------
Modified:
incubator/qpid/trunk/qpid/cpp/examples/examples/fanout/declare_queues.cpp
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/examples/examples/fanout/declare_queues.cpp?rev=613018&r1=613017&r2=613018&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/examples/examples/fanout/declare_queues.cpp
(original)
+++ incubator/qpid/trunk/qpid/cpp/examples/examples/fanout/declare_queues.cpp
Thu Jan 17 16:11:27 2008
@@ -53,11 +53,13 @@
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();
Modified:
incubator/qpid/trunk/qpid/cpp/examples/examples/fanout/fanout_producer.cpp
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/examples/examples/fanout/fanout_producer.cpp?rev=613018&r1=613017&r2=613018&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/examples/examples/fanout/fanout_producer.cpp
(original)
+++ incubator/qpid/trunk/qpid/cpp/examples/examples/fanout/fanout_producer.cpp
Thu Jan 17 16:11:27 2008
@@ -60,11 +60,13 @@
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 --------------------------------------------
Modified: incubator/qpid/trunk/qpid/cpp/examples/examples/fanout/listener.cpp
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/examples/examples/fanout/listener.cpp?rev=613018&r1=613017&r2=613018&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/examples/examples/fanout/listener.cpp
(original)
+++ incubator/qpid/trunk/qpid/cpp/examples/examples/fanout/listener.cpp Thu Jan
17 16:11:27 2008
@@ -93,11 +93,13 @@
-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 --------------------------------------------
Modified:
incubator/qpid/trunk/qpid/cpp/examples/examples/pub-sub/topic_listener.cpp
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/examples/examples/pub-sub/topic_listener.cpp?rev=613018&r1=613017&r2=613018&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/examples/examples/pub-sub/topic_listener.cpp
(original)
+++ incubator/qpid/trunk/qpid/cpp/examples/examples/pub-sub/topic_listener.cpp
Thu Jan 17 16:11:27 2008
@@ -131,10 +131,12 @@
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
--------------------------------------------
Modified:
incubator/qpid/trunk/qpid/cpp/examples/examples/pub-sub/topic_publisher.cpp
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/examples/examples/pub-sub/topic_publisher.cpp?rev=613018&r1=613017&r2=613018&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/examples/examples/pub-sub/topic_publisher.cpp
(original)
+++ incubator/qpid/trunk/qpid/cpp/examples/examples/pub-sub/topic_publisher.cpp
Thu Jan 17 16:11:27 2008
@@ -94,11 +94,13 @@
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 --------------------------------------------
Modified: incubator/qpid/trunk/qpid/cpp/examples/examples/pub-sub/verify.in
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/examples/examples/pub-sub/verify.in?rev=613018&r1=613017&r2=613018&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/examples/examples/pub-sub/verify.in (original)
+++ incubator/qpid/trunk/qpid/cpp/examples/examples/pub-sub/verify.in Thu Jan
17 16:11:27 2008
@@ -58,4 +58,5 @@
Subscribing to queue news
Subscribing to queue usa
Subscribing to queue weather
+==== ./topic_listener
====
Modified:
incubator/qpid/trunk/qpid/cpp/examples/examples/request-response/client.cpp
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/examples/examples/request-response/client.cpp?rev=613018&r1=613017&r2=613018&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/examples/examples/request-response/client.cpp
(original)
+++ incubator/qpid/trunk/qpid/cpp/examples/examples/request-response/client.cpp
Thu Jan 17 16:11:27 2008
@@ -107,11 +107,13 @@
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 --------------------------------------------
Modified:
incubator/qpid/trunk/qpid/cpp/examples/examples/request-response/server.cpp
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/examples/examples/request-response/server.cpp?rev=613018&r1=613017&r2=613018&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/examples/examples/request-response/server.cpp
(original)
+++ incubator/qpid/trunk/qpid/cpp/examples/examples/request-response/server.cpp
Thu Jan 17 16:11:27 2008
@@ -124,11 +124,13 @@
}
-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 --------------------------------------------
Modified:
incubator/qpid/trunk/qpid/cpp/examples/examples/request-response/verify.in
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/examples/examples/request-response/verify.in?rev=613018&r1=613017&r2=613018&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/examples/examples/request-response/verify.in
(original)
+++ incubator/qpid/trunk/qpid/cpp/examples/examples/request-response/verify.in
Thu Jan 17 16:11:27 2008
@@ -12,6 +12,7 @@
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 )
Modified: incubator/qpid/trunk/qpid/cpp/examples/verify
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/examples/verify?rev=613018&r1=613017&r2=613018&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/examples/verify (original)
+++ incubator/qpid/trunk/qpid/cpp/examples/verify Thu Jan 17 16:11:27 2008
@@ -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 @@
# 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 @@
}
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)
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?rev=613018&r1=613017&r2=613018&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.cpp (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/Socket.cpp Thu Jan 17
16:11:27 2008
@@ -113,6 +113,17 @@
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 @@
// 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
Modified: incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/check.h
URL:
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/check.h?rev=613018&r1=613017&r2=613018&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/check.h (original)
+++ incubator/qpid/trunk/qpid/cpp/src/qpid/sys/posix/check.h Thu Jan 17
16:11:27 2008
@@ -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) \