diff options
author | Tony Garnock-Jones <tonygarnockjones@gmail.com> | 2010-02-18 17:20:39 +1300 |
---|---|---|
committer | Tony Garnock-Jones <tonygarnockjones@gmail.com> | 2010-02-18 17:20:39 +1300 |
commit | c877f5da14b591ece42d93651ed0a7d9c38b3677 (patch) | |
tree | 111b9ed9135d3defc2d4893cfa17de20364a78a1 /librabbitmq | |
parent | 896df535ac9d877ca239c95003d55c8fee5ef047 (diff) | |
parent | 5568ccff3edef70041e45910077ed0ee17a435d7 (diff) | |
download | rabbitmq-c-github-ask-c877f5da14b591ece42d93651ed0a7d9c38b3677.tar.gz |
Merge default into amqp_0_9_1
Diffstat (limited to 'librabbitmq')
-rw-r--r-- | librabbitmq/amqp.h | 16 | ||||
-rw-r--r-- | librabbitmq/amqp_api.c | 60 | ||||
-rw-r--r-- | librabbitmq/amqp_private.h | 2 | ||||
-rw-r--r-- | librabbitmq/amqp_socket.c | 10 |
4 files changed, 51 insertions, 37 deletions
diff --git a/librabbitmq/amqp.h b/librabbitmq/amqp.h index 749671d..adfaaf6 100644 --- a/librabbitmq/amqp.h +++ b/librabbitmq/amqp.h @@ -337,8 +337,6 @@ extern amqp_rpc_reply_t amqp_login(amqp_connection_state_t state, int heartbeat, amqp_sasl_method_enum sasl_method, ...); -extern amqp_rpc_reply_t amqp_rpc_reply; - extern struct amqp_channel_open_ok_t_ *amqp_channel_open(amqp_connection_state_t state, amqp_channel_t channel); @@ -424,9 +422,19 @@ extern struct amqp_queue_purge_ok_t_ *amqp_queue_purge(amqp_connection_state_t s extern amqp_boolean_t amqp_data_in_buffer(amqp_connection_state_t state); /* - * Expose amqp_rpc_reply to libraries. + * For those API operations (such as amqp_basic_ack, + * amqp_queue_declare, and so on) that do not themselves return + * amqp_rpc_reply_t instances, we need some way of discovering what, + * if anything, went wrong. amqp_get_rpc_reply() returns the most + * recent amqp_rpc_reply_t instance corresponding to such an API + * operation for the given connection. + * + * Only use it for operations that do not themselves return + * amqp_rpc_reply_t; operations that do return amqp_rpc_reply_t + * generally do NOT update this per-connection-global amqp_rpc_reply_t + * instance. */ -extern amqp_rpc_reply_t amqp_get_rpc_reply(void); +extern amqp_rpc_reply_t amqp_get_rpc_reply(amqp_connection_state_t state); #ifdef __cplusplus } diff --git a/librabbitmq/amqp_api.c b/librabbitmq/amqp_api.c index 8adf3f0..fdf64a0 100644 --- a/librabbitmq/amqp_api.c +++ b/librabbitmq/amqp_api.c @@ -10,17 +10,15 @@ #include <assert.h> -amqp_rpc_reply_t amqp_rpc_reply; - -#define RPC_REPLY(replytype) \ - (amqp_rpc_reply.reply_type == AMQP_RESPONSE_NORMAL \ - ? (replytype *) amqp_rpc_reply.reply.decoded \ +#define RPC_REPLY(replytype) \ + (state->most_recent_api_result.reply_type == AMQP_RESPONSE_NORMAL \ + ? (replytype *) state->most_recent_api_result.reply.decoded \ : NULL) amqp_channel_open_ok_t *amqp_channel_open(amqp_connection_state_t state, amqp_channel_t channel) { - amqp_rpc_reply = + state->most_recent_api_result = AMQP_SIMPLE_RPC(state, channel, CHANNEL, OPEN, OPEN_OK, amqp_channel_open_t, AMQP_EMPTY_BYTES); @@ -118,7 +116,7 @@ amqp_exchange_declare_ok_t *amqp_exchange_declare(amqp_connection_state_t state, amqp_boolean_t auto_delete, amqp_table_t arguments) { - amqp_rpc_reply = + state->most_recent_api_result = AMQP_SIMPLE_RPC(state, channel, EXCHANGE, DECLARE, DECLARE_OK, amqp_exchange_declare_t, 0, exchange, type, passive, durable, auto_delete, 0, 0, arguments); @@ -134,7 +132,7 @@ amqp_queue_declare_ok_t *amqp_queue_declare(amqp_connection_state_t state, amqp_boolean_t auto_delete, amqp_table_t arguments) { - amqp_rpc_reply = + state->most_recent_api_result = AMQP_SIMPLE_RPC(state, channel, QUEUE, DECLARE, DECLARE_OK, amqp_queue_declare_t, 0, queue, passive, durable, exclusive, auto_delete, 0, arguments); @@ -148,7 +146,7 @@ amqp_queue_bind_ok_t *amqp_queue_bind(amqp_connection_state_t state, amqp_bytes_t routing_key, amqp_table_t arguments) { - amqp_rpc_reply = + state->most_recent_api_result = AMQP_SIMPLE_RPC(state, channel, QUEUE, BIND, BIND_OK, amqp_queue_bind_t, 0, queue, exchange, routing_key, 0, arguments); @@ -162,7 +160,7 @@ amqp_queue_unbind_ok_t *amqp_queue_unbind(amqp_connection_state_t state, amqp_bytes_t binding_key, amqp_table_t arguments) { - amqp_rpc_reply = + state->most_recent_api_result = AMQP_SIMPLE_RPC(state, channel, QUEUE, UNBIND, UNBIND_OK, amqp_queue_unbind_t, 0, queue, exchange, binding_key, arguments); @@ -178,7 +176,7 @@ amqp_basic_consume_ok_t *amqp_basic_consume(amqp_connection_state_t state, amqp_boolean_t exclusive, amqp_table_t filter) { - amqp_rpc_reply = + state->most_recent_api_result = AMQP_SIMPLE_RPC(state, channel, BASIC, CONSUME, CONSUME_OK, amqp_basic_consume_t, 0, queue, consumer_tag, no_local, no_ack, exclusive, 0, filter); @@ -200,34 +198,32 @@ int amqp_basic_ack(amqp_connection_state_t state, } amqp_queue_purge_ok_t *amqp_queue_purge(amqp_connection_state_t state, - amqp_channel_t channel, - amqp_bytes_t queue, - amqp_boolean_t no_wait) + amqp_channel_t channel, + amqp_bytes_t queue, + amqp_boolean_t no_wait) { - amqp_rpc_reply = AMQP_SIMPLE_RPC(state, channel, QUEUE, PURGE, PURGE_OK, - amqp_queue_purge_t, channel, queue, no_wait); + state->most_recent_api_result = + AMQP_SIMPLE_RPC(state, channel, QUEUE, PURGE, PURGE_OK, + amqp_queue_purge_t, channel, queue, no_wait); return RPC_REPLY(amqp_queue_purge_ok_t); } amqp_rpc_reply_t amqp_basic_get(amqp_connection_state_t state, - amqp_channel_t channel, - amqp_bytes_t queue, - amqp_boolean_t no_ack) + amqp_channel_t channel, + amqp_bytes_t queue, + amqp_boolean_t no_ack) { - amqp_method_number_t replies[] = { AMQP_BASIC_GET_OK_METHOD, - AMQP_BASIC_GET_EMPTY_METHOD, - 0 }; - amqp_rpc_reply = - AMQP_MULTIPLE_RESPONSE_RPC(state, channel, BASIC, GET, replies, - amqp_basic_get_t, - channel, queue, no_ack); - return amqp_rpc_reply; + amqp_method_number_t replies[] = { AMQP_BASIC_GET_OK_METHOD, + AMQP_BASIC_GET_EMPTY_METHOD, + 0 }; + state->most_recent_api_result = + AMQP_MULTIPLE_RESPONSE_RPC(state, channel, BASIC, GET, replies, + amqp_basic_get_t, + channel, queue, no_ack); + return state->most_recent_api_result; } -/* - * Expose amqp_rpc_reply to dynamically linked libraries - */ -amqp_rpc_reply_t amqp_get_rpc_reply(void) +amqp_rpc_reply_t amqp_get_rpc_reply(amqp_connection_state_t state) { - return amqp_rpc_reply; + return state->most_recent_api_result; } diff --git a/librabbitmq/amqp_private.h b/librabbitmq/amqp_private.h index 03a46fe..aba63b5 100644 --- a/librabbitmq/amqp_private.h +++ b/librabbitmq/amqp_private.h @@ -71,6 +71,8 @@ struct amqp_connection_state_t_ { amqp_link_t *first_queued_frame; amqp_link_t *last_queued_frame; + + amqp_rpc_reply_t most_recent_api_result; }; #define CHECK_LIMIT(b, o, l, v) ({ if ((o + l) > (b).len) { return -EFAULT; } (v); }) diff --git a/librabbitmq/amqp_socket.c b/librabbitmq/amqp_socket.c index c6412a9..0cf9c18 100644 --- a/librabbitmq/amqp_socket.c +++ b/librabbitmq/amqp_socket.c @@ -386,10 +386,18 @@ amqp_rpc_reply_t amqp_login(amqp_connection_state_t state, { va_list vl; amqp_rpc_reply_t result; + int status; va_start(vl, sasl_method); - amqp_login_inner(state, channel_max, frame_max, heartbeat, sasl_method, vl); + status = amqp_login_inner(state, channel_max, frame_max, heartbeat, sasl_method, vl); + if (status <= 0) { + result.reply_type = AMQP_RESPONSE_LIBRARY_EXCEPTION; + result.reply.id = 0; + result.reply.decoded = NULL; + result.library_errno = -status; + return result; + } { amqp_connection_open_t s = |