diff options
author | Alan Antonuk <alan.antonuk@gmail.com> | 2013-06-14 17:48:05 -0700 |
---|---|---|
committer | Alan Antonuk <alan.antonuk@gmail.com> | 2013-06-25 16:10:51 -0700 |
commit | daa0e663ed6ae6d49ed3cc0da3043e3d4e8b2252 (patch) | |
tree | c4f85982841a272f3f1a0b76708755adde52c378 /librabbitmq/amqp_connection.c | |
parent | 3866433fe273eded1e601b3274028684c3e77919 (diff) | |
download | rabbitmq-c-github-ask-daa0e663ed6ae6d49ed3cc0da3043e3d4e8b2252.tar.gz |
Add partial support for heartbeats in wait_frame
Diffstat (limited to 'librabbitmq/amqp_connection.c')
-rw-r--r-- | librabbitmq/amqp_connection.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/librabbitmq/amqp_connection.c b/librabbitmq/amqp_connection.c index ae3edf4..7ba6f42 100644 --- a/librabbitmq/amqp_connection.c +++ b/librabbitmq/amqp_connection.c @@ -40,6 +40,7 @@ #include "amqp_tcp_socket.h" #include "amqp_private.h" +#include "amqp_timer.h" #include <assert.h> #include <errno.h> #include <stdint.h> @@ -133,6 +134,15 @@ int amqp_tune_connection(amqp_connection_state_t state, state->frame_max = frame_max; state->heartbeat = heartbeat; + if (state->heartbeat > 0) { + uint64_t current_time = amqp_get_monotonic_timestamp(); + if (0 == current_time) { + return AMQP_STATUS_TIMER_FAILURE; + } + state->next_send_heartbeat = current_time + (state->heartbeat * AMQP_NS_PER_S); + state->next_recv_heartbeat = current_time + (2 * state->heartbeat * AMQP_NS_PER_S); + } + state->outbound_buffer.len = frame_max; newbuf = realloc(state->outbound_buffer.bytes, frame_max); if (newbuf == NULL) { @@ -491,5 +501,13 @@ int amqp_send_frame(amqp_connection_state_t state, out_frame_len + HEADER_SIZE + FOOTER_SIZE); } + if (state->heartbeat > 0) { + uint64_t current_time = amqp_get_monotonic_timestamp(); + if (0 == current_time) { + return AMQP_STATUS_TIMER_FAILURE; + } + state->next_send_heartbeat = current_time + (state->heartbeat * AMQP_NS_PER_S); + } + return res; } |