summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDavid Wragg <dpw@lshift.net>2010-05-30 23:31:40 +0100
committerDavid Wragg <dpw@lshift.net>2010-05-30 23:31:40 +0100
commit66a0a987914626fc0ea86067a0ea1dd7a2bebdd2 (patch)
tree0e400acdd2e7f35ed47b94d51308b142e82dbeac /examples
parent7e8fbea4c9212774c101e33218d26a0dc992dc03 (diff)
downloadrabbitmq-c-66a0a987914626fc0ea86067a0ea1dd7a2bebdd2.tar.gz
Make error codes returned by librabbitmq functions opaque
Windows doesn't generally use POSIX error codes, which poses a problem for librabbitmq's approach of using those error codes in its API. So make the librabbitmq error codes opaque: They are still be integers, but client code is not supposed to assume anything about them, except that they can be passed to a new amqp_error_string() function which returns the corresponding error message Internally, the error codes are either taken from a set of librabbitmq-specific values, or correspond to an OS-specific (POSIX or win32) error code, with a simple encoding to indicate which is which.
Diffstat (limited to 'examples')
-rw-r--r--examples/amqp_consumer.c10
-rw-r--r--examples/amqp_listen.c6
-rw-r--r--examples/amqp_listenq.c6
-rw-r--r--examples/example_utils.c5
4 files changed, 15 insertions, 12 deletions
diff --git a/examples/amqp_consumer.c b/examples/amqp_consumer.c
index 45db990..5dfbb33 100644
--- a/examples/amqp_consumer.c
+++ b/examples/amqp_consumer.c
@@ -94,7 +94,8 @@ static void run(amqp_connection_state_t conn)
amqp_maybe_release_buffers(conn);
result = amqp_simple_wait_frame(conn, &frame);
- if (result <= 0) return;
+ if (result < 0)
+ return;
if (frame.frame_type != AMQP_FRAME_METHOD)
continue;
@@ -103,7 +104,9 @@ static void run(amqp_connection_state_t conn)
continue;
result = amqp_simple_wait_frame(conn, &frame);
- if (result <= 0) return;
+ if (result < 0)
+ return;
+
if (frame.frame_type != AMQP_FRAME_HEADER) {
fprintf(stderr, "Expected header!");
abort();
@@ -114,7 +117,8 @@ static void run(amqp_connection_state_t conn)
while (body_received < body_target) {
result = amqp_simple_wait_frame(conn, &frame);
- if (result <= 0) return;
+ if (result < 0)
+ return;
if (frame.frame_type != AMQP_FRAME_BODY) {
fprintf(stderr, "Expected body!");
diff --git a/examples/amqp_listen.c b/examples/amqp_listen.c
index c1401ee..412dcd5 100644
--- a/examples/amqp_listen.c
+++ b/examples/amqp_listen.c
@@ -125,7 +125,7 @@ int main(int argc, char const * const *argv) {
amqp_maybe_release_buffers(conn);
result = amqp_simple_wait_frame(conn, &frame);
printf("Result %d\n", result);
- if (result <= 0)
+ if (result < 0)
break;
printf("Frame type %d, channel %d\n", frame.frame_type, frame.channel);
@@ -143,7 +143,7 @@ int main(int argc, char const * const *argv) {
(int) d->routing_key.len, (char *) d->routing_key.bytes);
result = amqp_simple_wait_frame(conn, &frame);
- if (result <= 0)
+ if (result < 0)
break;
if (frame.frame_type != AMQP_FRAME_HEADER) {
@@ -162,7 +162,7 @@ int main(int argc, char const * const *argv) {
while (body_received < body_target) {
result = amqp_simple_wait_frame(conn, &frame);
- if (result <= 0)
+ if (result < 0)
break;
if (frame.frame_type != AMQP_FRAME_BODY) {
diff --git a/examples/amqp_listenq.c b/examples/amqp_listenq.c
index 00dd2d7..1fc7db0 100644
--- a/examples/amqp_listenq.c
+++ b/examples/amqp_listenq.c
@@ -107,7 +107,7 @@ int main(int argc, char const * const *argv) {
amqp_maybe_release_buffers(conn);
result = amqp_simple_wait_frame(conn, &frame);
printf("Result %d\n", result);
- if (result <= 0)
+ if (result < 0)
break;
printf("Frame type %d, channel %d\n", frame.frame_type, frame.channel);
@@ -125,7 +125,7 @@ int main(int argc, char const * const *argv) {
(int) d->routing_key.len, (char *) d->routing_key.bytes);
result = amqp_simple_wait_frame(conn, &frame);
- if (result <= 0)
+ if (result < 0)
break;
if (frame.frame_type != AMQP_FRAME_HEADER) {
@@ -144,7 +144,7 @@ int main(int argc, char const * const *argv) {
while (body_received < body_target) {
result = amqp_simple_wait_frame(conn, &frame);
- if (result <= 0)
+ if (result < 0)
break;
if (frame.frame_type != AMQP_FRAME_BODY) {
diff --git a/examples/example_utils.c b/examples/example_utils.c
index 628572c..ae8f093 100644
--- a/examples/example_utils.c
+++ b/examples/example_utils.c
@@ -61,7 +61,7 @@
void die_on_error(int x, char const *context) {
if (x < 0) {
- fprintf(stderr, "%s: %s\n", context, strerror(-x));
+ fprintf(stderr, "%s: %s\n", context, amqp_error_string(-x));
exit(1);
}
}
@@ -76,8 +76,7 @@ void die_on_amqp_error(amqp_rpc_reply_t x, char const *context) {
break;
case AMQP_RESPONSE_LIBRARY_EXCEPTION:
- fprintf(stderr, "%s: %s\n", context,
- x.library_errno ? strerror(x.library_errno) : "(end-of-stream)");
+ fprintf(stderr, "%s: %s\n", context, amqp_error_string(x.library_error));
break;
case AMQP_RESPONSE_SERVER_EXCEPTION: