X-Git-Url: http://git.cascardo.info/?p=cascardo%2Fchat.git;a=blobdiff_plain;f=sort_udns.c;h=a14de00010e2fec0bdae32eeacb75e961c9f9ce7;hp=8b0336bab578e363758fe25b34cbda34355430a8;hb=35e6e468cbc964683c7e6ca3510a49c63f4b1095;hpb=68aad407c269e1ccea8ccba21101ab6f93470890 diff --git a/sort_udns.c b/sort_udns.c index 8b0336b..a14de00 100644 --- a/sort_udns.c +++ b/sort_udns.c @@ -93,32 +93,32 @@ void dns_srv_sort (struct dns_srv* srvaddr, int n) sum = 0; /* Compute the sum of weights for the priority prio */ for (i = j; i < n && srvaddr[i].priority == prio; i++) - { - sum += srvaddr[i].weight; - } + { + sum += srvaddr[i].weight; + } /* If there is no more nodes with priority prio, get next prio */ if (i == j && srvaddr[i].priority > prio) - { - prio = srvaddr[i].priority; - } + { + prio = srvaddr[i].priority; + } else - { - while (sum > 0) - { - wrand = random_int_range (0, sum + 1); - for (i = j; i < n && srvaddr[i].weight < wrand; i++) - { - wrand -= srvaddr[i].weight; - } - assert (i < n); - assert (srvaddr[i].priority == prio); - dns_srv_switch (srvaddr, j, i); - sum -= srvaddr[j].weight; - j++; - } - /* Those remaining addresses with weight 0 */ - for (i = j; i < n && srvaddr[i].priority == prio; i++, j++); - } + { + while (sum > 0) + { + wrand = random_int_range (0, sum + 1); + for (i = j; i < n && srvaddr[i].weight < wrand; i++) + { + wrand -= srvaddr[i].weight; + } + assert (i < n); + assert (srvaddr[i].priority == prio); + dns_srv_switch (srvaddr, j, i); + sum -= srvaddr[j].weight; + j++; + } + /* Those remaining addresses with weight 0 */ + for (i = j; i < n && srvaddr[i].priority == prio; i++, j++); + } } }