summaryrefslogtreecommitdiff
path: root/examples/amqp_sendstring.c
diff options
context:
space:
mode:
authorTony Garnock-Jones <tonyg@kcbbs.gen.nz>2009-04-27 00:44:59 +0100
committerTony Garnock-Jones <tonyg@kcbbs.gen.nz>2009-04-27 00:44:59 +0100
commit3a51512706eb5dcebb6c8e2d4dcd571273f49899 (patch)
tree7cd5af04f901aba44f1ce43bccb6685b97ef33f6 /examples/amqp_sendstring.c
parente954a0bf0d30c21b5563db2fd07e5d85d076edc2 (diff)
downloadrabbitmq-c-github-ask-3a51512706eb5dcebb6c8e2d4dcd571273f49899.tar.gz
More examples; clean shutdown
Diffstat (limited to 'examples/amqp_sendstring.c')
-rw-r--r--examples/amqp_sendstring.c64
1 files changed, 3 insertions, 61 deletions
diff --git a/examples/amqp_sendstring.c b/examples/amqp_sendstring.c
index 77d8fd3..c914f86 100644
--- a/examples/amqp_sendstring.c
+++ b/examples/amqp_sendstring.c
@@ -8,55 +8,7 @@
#include <unistd.h>
-static void die_on_error(int x, char const *context) {
- if (x < 0) {
- fprintf(stderr, "%s: %s\n", context, strerror(-x));
- exit(1);
- }
-}
-
-static void die_on_amqp_error(amqp_rpc_reply_t x, char const *context) {
- switch (x.reply_type) {
- case AMQP_RESPONSE_NORMAL:
- return;
-
- case AMQP_RESPONSE_NONE:
- fprintf(stderr, "%s: missing RPC reply type!", context);
- break;
-
- case AMQP_RESPONSE_LIBRARY_EXCEPTION:
- fprintf(stderr, "%s: %s\n", context, strerror(x.library_errno));
- break;
-
- case AMQP_RESPONSE_SERVER_EXCEPTION:
- switch (x.reply.id) {
- case AMQP_CONNECTION_CLOSE_METHOD: {
- amqp_connection_close_t *m = (amqp_connection_close_t *) x.reply.decoded;
- fprintf(stderr, "%s: server connection error %d, message: %*s",
- context,
- m->reply_code,
- (int) m->reply_text.len,
- (char *) m->reply_text.bytes);
- break;
- }
- case AMQP_CHANNEL_CLOSE_METHOD: {
- amqp_channel_close_t *m = (amqp_channel_close_t *) x.reply.decoded;
- fprintf(stderr, "%s: server channel error %d, message: %*s",
- context,
- m->reply_code,
- (int) m->reply_text.len,
- (char *) m->reply_text.bytes);
- break;
- }
- default:
- fprintf(stderr, "%s: unknown server error, method id 0x%08X", context, x.reply.id);
- break;
- }
- break;
- }
-
- exit(1);
-}
+#include "example_utils.h"
int main(int argc, char const * const *argv) {
char const *hostname;
@@ -100,19 +52,9 @@ int main(int argc, char const * const *argv) {
"Publishing");
}
- printf("Waiting for frames...\n");
- while (1) {
- amqp_frame_t frame;
- int result = amqp_simple_wait_frame(conn, &frame);
- printf("Result %d\n", result);
- printf("Frame type %d, channel %d\n", frame.frame_type, frame.channel);
- if (result == 0) break;
- amqp_maybe_release_buffers(conn);
- }
-
+ die_on_amqp_error(amqp_channel_close(conn, AMQP_REPLY_SUCCESS), "Closing channel");
+ die_on_amqp_error(amqp_connection_close(conn, AMQP_REPLY_SUCCESS), "Closing connection");
amqp_destroy_connection(conn);
-
die_on_error(close(sockfd), "Closing socket");
-
return 0;
}