Skip to content

Commit

Permalink
Change connection timeout to work per IP
Browse files Browse the repository at this point in the history
  • Loading branch information
Олег Переверзев committed Jun 28, 2019
1 parent 60adf5f commit 8115125
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions librabbitmq/amqp_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,10 @@ int amqp_open_socket_inner(char const *hostname, int portnumber,
char portnumber_string[33];
int sockfd = -1;
int last_error;
amqp_time_t deadline_per_ip;
uint64_t timeout_per_ip;
uint64_t now_ns;


last_error = amqp_os_socket_init();
if (AMQP_STATUS_OK != last_error) {
Expand All @@ -495,15 +499,22 @@ int amqp_open_socket_inner(char const *hostname, int portnumber,
return AMQP_STATUS_HOSTNAME_RESOLUTION_FAILED;
}

timeout_per_ip = amqp_time_ms_until(deadline) * AMQP_NS_PER_MS;

for (addr = address_list; addr; addr = addr->ai_next) {
sockfd = connect_socket(addr, deadline);

now_ns = amqp_get_monotonic_timestamp();
if (0 == now_ns)
return AMQP_STATUS_TIMER_FAILURE;

deadline_per_ip.time_point_ns = now_ns + timeout_per_ip;
sockfd = connect_socket(addr, deadline_per_ip);

if (sockfd >= 0) {
last_error = AMQP_STATUS_OK;
break;
} else if (sockfd == AMQP_STATUS_TIMEOUT) {
last_error = sockfd;
break;
}
}

Expand Down

0 comments on commit 8115125

Please sign in to comment.