diff options
author | David Wragg <david@rabbitmq.com> | 2010-10-21 17:49:04 +0100 |
---|---|---|
committer | David Wragg <david@rabbitmq.com> | 2010-10-21 17:49:04 +0100 |
commit | b7b614ae3fe0c450c71fcef6fc5812a158619783 (patch) | |
tree | 024d3df37c872b24880344d6ac4f7529eedccfbc | |
parent | c5705c2b64d2f6f8bf12bc74538228f802e7f708 (diff) | |
download | rabbitmq-c-github-ask-b7b614ae3fe0c450c71fcef6fc5812a158619783.tar.gz |
Eliminate the AMQP_CHECK_RESULT macro
-rw-r--r-- | librabbitmq/amqp_api.c | 17 | ||||
-rw-r--r-- | librabbitmq/amqp_private.h | 9 | ||||
-rw-r--r-- | librabbitmq/amqp_socket.c | 43 |
3 files changed, 37 insertions, 32 deletions
diff --git a/librabbitmq/amqp_api.c b/librabbitmq/amqp_api.c index 3a44701..a489bea 100644 --- a/librabbitmq/amqp_api.c +++ b/librabbitmq/amqp_api.c @@ -133,6 +133,7 @@ int amqp_basic_publish(amqp_connection_state_t state, amqp_frame_t f; size_t body_offset; size_t usable_body_payload_size = state->frame_max - (HEADER_SIZE + FOOTER_SIZE); + int res; amqp_basic_publish_t m = (amqp_basic_publish_t) { @@ -144,7 +145,9 @@ int amqp_basic_publish(amqp_connection_state_t state, amqp_basic_properties_t default_properties; - AMQP_CHECK_RESULT(amqp_send_method(state, channel, AMQP_BASIC_PUBLISH_METHOD, &m)); + res = amqp_send_method(state, channel, AMQP_BASIC_PUBLISH_METHOD, &m); + if (res < 0) + return res; if (properties == NULL) { memset(&default_properties, 0, sizeof(default_properties)); @@ -156,7 +159,10 @@ int amqp_basic_publish(amqp_connection_state_t state, f.payload.properties.class_id = AMQP_BASIC_CLASS; f.payload.properties.body_size = body.len; f.payload.properties.decoded = (void *) properties; - AMQP_CHECK_RESULT(amqp_send_frame(state, &f)); + + res = amqp_send_frame(state, &f); + if (res < 0) + return res; body_offset = 0; while (1) { @@ -176,7 +182,9 @@ int amqp_basic_publish(amqp_connection_state_t state, } body_offset += f.payload.body_fragment.len; - AMQP_CHECK_RESULT(amqp_send_frame(state, &f)); + res = amqp_send_frame(state, &f); + if (res < 0) + return res; } return 0; @@ -301,8 +309,7 @@ int amqp_basic_ack(amqp_connection_state_t state, .delivery_tag = delivery_tag, .multiple = multiple }; - AMQP_CHECK_RESULT(amqp_send_method(state, channel, AMQP_BASIC_ACK_METHOD, &m)); - return 0; + return amqp_send_method(state, channel, AMQP_BASIC_ACK_METHOD, &m); } amqp_queue_purge_ok_t *amqp_queue_purge(amqp_connection_state_t state, diff --git a/librabbitmq/amqp_private.h b/librabbitmq/amqp_private.h index ec2ba39..61591e5 100644 --- a/librabbitmq/amqp_private.h +++ b/librabbitmq/amqp_private.h @@ -255,15 +255,6 @@ extern int amqp_encode_table(amqp_bytes_t encoded, extern void amqp_abort(const char *fmt, ...); -#define AMQP_CHECK_RESULT_CLEANUP(expr, stmts) \ - ({ \ - int _result = (expr); \ - if (_result < 0) { stmts; return _result; } \ - _result; \ - }) - -#define AMQP_CHECK_RESULT(expr) AMQP_CHECK_RESULT_CLEANUP(expr, ) - #ifndef NDEBUG extern void amqp_dump(void const *buffer, size_t len); #else diff --git a/librabbitmq/amqp_socket.c b/librabbitmq/amqp_socket.c index ee67415..dfce2d8 100644 --- a/librabbitmq/amqp_socket.c +++ b/librabbitmq/amqp_socket.c @@ -172,33 +172,37 @@ static int wait_frame_inner(amqp_connection_state_t state, amqp_frame_t *decoded_frame) { while (1) { - int result; + int res; while (amqp_data_in_buffer(state)) { amqp_bytes_t buffer; buffer.len = state->sock_inbound_limit - state->sock_inbound_offset; buffer.bytes = ((char *) state->sock_inbound_buffer.bytes) + state->sock_inbound_offset; - AMQP_CHECK_RESULT((result = amqp_handle_input(state, buffer, decoded_frame))); - state->sock_inbound_offset += result; + + res = amqp_handle_input(state, buffer, decoded_frame); + if (res < 0) + return res; + + state->sock_inbound_offset += res; if (decoded_frame->frame_type != 0) /* Complete frame was read. Return it. */ return 0; /* Incomplete or ignored frame. Keep processing input. */ - assert(result != 0); - } + assert(res != 0); + } - result = recv(state->sockfd, state->sock_inbound_buffer.bytes, + res = recv(state->sockfd, state->sock_inbound_buffer.bytes, state->sock_inbound_buffer.len, 0); - if (result <= 0) { - if (result == 0) + if (res <= 0) { + if (res == 0) return -ERROR_CONNECTION_CLOSED; else return -amqp_socket_error(); } - state->sock_inbound_limit = result; + state->sock_inbound_limit = res; state->sock_inbound_offset = 0; } } @@ -394,7 +398,9 @@ static int amqp_login_inner(amqp_connection_state_t state, .response = response_bytes, .locale = {.len = 5, .bytes = "en_US"} }; - AMQP_CHECK_RESULT(amqp_send_method(state, 0, AMQP_CONNECTION_START_OK_METHOD, &s)); + res = amqp_send_method(state, 0, AMQP_CONNECTION_START_OK_METHOD, &s); + if (res < 0) + return res; } amqp_release_buffers(state); @@ -411,19 +417,18 @@ static int amqp_login_inner(amqp_connection_state_t state, server_heartbeat = s->heartbeat; } - if (server_channel_max != 0 && server_channel_max < channel_max) { + if (server_channel_max != 0 && server_channel_max < channel_max) channel_max = server_channel_max; - } - if (server_frame_max != 0 && server_frame_max < frame_max) { + if (server_frame_max != 0 && server_frame_max < frame_max) frame_max = server_frame_max; - } - if (server_heartbeat != 0 && server_heartbeat < heartbeat) { + if (server_heartbeat != 0 && server_heartbeat < heartbeat) heartbeat = server_heartbeat; - } - AMQP_CHECK_RESULT(amqp_tune_connection(state, channel_max, frame_max, heartbeat)); + res = amqp_tune_connection(state, channel_max, frame_max, heartbeat); + if (res < 0) + return res; { amqp_connection_tune_ok_t s = @@ -432,7 +437,9 @@ static int amqp_login_inner(amqp_connection_state_t state, .frame_max = frame_max, .heartbeat = heartbeat }; - AMQP_CHECK_RESULT(amqp_send_method(state, 0, AMQP_CONNECTION_TUNE_OK_METHOD, &s)); + res = amqp_send_method(state, 0, AMQP_CONNECTION_TUNE_OK_METHOD, &s); + if (res < 0) + return res; } amqp_release_buffers(state); |