cURL / Mailing Lists / curl-library / Single Mail

curl-library

round robin DNS without Ares only takes first IP

From: A Nonymous <anon_at_ymous.none>
Date: Wed, 27 Apr 2005 17:06:30 +0200

A Nonymous wrote:

> Alternatively I could count the number of addresses, choose the
> starting address, jump to the head after reaching the tail and
> terminate the loop when reaching the starting address again.
> Unless a certain option is set the starting address will be the head
> itself.

The following is a "diff -u" of my patch:

--- t1 2005-04-27 16:49:10.000000000 +0200
+++ t2 2005-04-27 17:03:41.000000000 +0200
@@ -722,6 +722,8 @@
   struct SessionHandle *data = conn->data;
   curl_socket_t sockfd = CURL_SOCKET_BAD;
   int aliasindex;
+ int aliascount;
+ int aliasfirst;
   int num_addr;
   Curl_addrinfo *ai;
   Curl_addrinfo *curr_addr;
@@ -783,11 +785,36 @@
     /* don't hang when doing multi */
     timeout_per_addr = 0;

- /*
- * Connecting with a Curl_addrinfo chain
- */
- for (curr_addr = ai, aliasindex=0; curr_addr;
- curr_addr = curr_addr->ai_next, aliasindex++) {
+ if (1 /* if option to start with random address is set */) {
+ /*
+ * Count elements in Curl_addrinfo chain
+ */
+ for (curr_addr = ai, aliascount=0; curr_addr;
+ curr_addr = curr_addr->ai_next) {
+ aliascount++;
+ }
+ /*
+ * Choose first alias to use by random and seek to it
+ */
+ aliasfirst = rand() % aliascount;
+ for (curr_addr = ai, aliasindex=0; aliasindex < aliasfirst;
+ curr_addr = curr_addr->ai_next) {
+ aliasindex++;
+ }
+ }
+ else {
+ aliasfirst = 0;
+ curr_addr = ai;
+ }
+
+ /*
+ * Connecting with a Curl_addrinfo chain
+ */
+ for (aliasindex = 0; aliasindex < aliascount;
+ curr_addr = curr_addr->ai_next, aliasindex++) {
+ if (curr_addr == NULL) {
+ curr_addr = ai;
+ }

     /* start connecting to the IP curr_addr points to */
     sockfd = singleipconnect(conn, curr_addr, timeout_per_addr, connected);
Received on 2005-04-27