--YZ5djTAD1cGYuMQK
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

I√Īaki Baz Castillo:

> I get data (DNS SRV records), which is an array with entries like this:

> #<EventMachine::Udns::RR_SRV:0x00000001ea4970 @domain="domain.org", @priority=1, @weight=50, @port=5062>

> Each entry is a SRV record. It has a priority (lowest value is the
> best) and weight (higher value means more probability to choose it).

> The client getting such array of SRV records wants to connect to a
> server based on SRV priorities/weight, which works as follows:
> - SRV records with best priority must be used first.
> - If there are various SRV records with same priority, then the
> probability of choosing each one depends on its weight value (random
> with weight).
> - If the chosen SRV record fails to connect (i.e. server down) next
> one (based on same priority/weight rules) must be tryed.

Something to the tune of

srvs.sort { |a, b| (a.priority <=> b.priority).nonzero? or (b.weight <=> a.weight).nonzero? or rand }

should work, then. :)

Piotr Szotkowski
-- 
°∆Driving myself slowly nuts with printing recursive S-expressions sanely in Go.°«
°∆Ford Prefect always said that going insane should
be enjoyed, and is not something to be rushed.°«
                                             [Eleanor McHugh, Phillip Gawlowski]




--YZ5djTAD1cGYuMQK
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iEYEARECAAYFAk4CA/8ACgkQi/mCfdEo8UpMkACbBAqOOyuGGbi2PX7bCkQQh2Cd
oMoAoIyZdFJ2I+MY6FPU7fn+9wcrRyNB
G9
-----END PGP SIGNATURE-----

--YZ5djTAD1cGYuMQK--