diff options
author | Alan Antonuk <alan.antonuk@gmail.com> | 2015-04-21 23:41:42 -0700 |
---|---|---|
committer | Alan Antonuk <alan.antonuk@gmail.com> | 2015-05-03 20:24:02 -0700 |
commit | 5498dc66c3be4176c3631ee4b4ec26d6cb4966ae (patch) | |
tree | e0b16bc62d0c647bef581faae204cdf4dcf790ce /librabbitmq/amqp_api.c | |
parent | a1326beab0054f35cf607297ae47ed3330086585 (diff) | |
download | rabbitmq-c-5498dc66c3be4176c3631ee4b4ec26d6cb4966ae.tar.gz |
Refactor heartbeat timeout code to be simpler
Refactor the heartbeat timeout code to hopefully simplify it and hopefully make
it less hairy to deal with in the future.
Diffstat (limited to 'librabbitmq/amqp_api.c')
-rw-r--r-- | librabbitmq/amqp_api.c | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/librabbitmq/amqp_api.c b/librabbitmq/amqp_api.c index ec2f9a1..3088b10 100644 --- a/librabbitmq/amqp_api.c +++ b/librabbitmq/amqp_api.c @@ -191,19 +191,17 @@ int amqp_basic_publish(amqp_connection_state_t state, m.immediate = immediate; m.ticket = 0; - if (amqp_heartbeat_enabled(state)) { - uint64_t current_timestamp = amqp_get_monotonic_timestamp(); - if (0 == current_timestamp) { - return AMQP_STATUS_TIMER_FAILURE; - } - - if (current_timestamp > state->next_recv_heartbeat) { - res = amqp_try_recv(state); - if (AMQP_STATUS_TIMEOUT == res) { - return AMQP_STATUS_HEARTBEAT_TIMEOUT; - } else if (AMQP_STATUS_OK != res) { - return res; - } + /* TODO(alanxz): this heartbeat check is happening in the wrong place, it + * should really be done in amqp_try_send/writev */ + res = amqp_time_has_past(state->next_recv_heartbeat); + if (AMQP_STATUS_TIMER_FAILURE == res) { + return res; + } else if (AMQP_STATUS_TIMEOUT == res) { + res = amqp_try_recv(state); + if (AMQP_STATUS_TIMEOUT == res) { + return AMQP_STATUS_HEARTBEAT_TIMEOUT; + } else if (AMQP_STATUS_OK != res) { + return res; } } |