Hi, Alexey
Good question. I think your problem can be divided into two sub-problems: 1) how to get multiple addresses (when possible) behind a single hostname, 2) how to do SOCKET-CONNECT with the logic (try all one by one until connection is succeed).
For the first sub-problem, I'm afraid that not all CL platform provided such a interface, but for those supported platforms (at least CMUCL, SBCL and LispWorks), you can use a internal USOCKET function called USOCKET::GET-HOSTS-BY-NAME, i.e.
* (usocket::get-hosts-by-name "www.google.com")
(#(72 14 203 104) #(72 14 203 99))
Once you got multiple addresses, you can feed them to SOCKET-CONNECT and do whatever you want.
I think I can patch USOCKET to make USOCKET::GET-HOSTS-BY-NAME return multiple addresses on all platforms, but this is not easy, will need time.
And for the second sub-problem. I think maybe you can try to use some CL condition programming technologies to achieve your goal: some kind of mixup of RESTART-CASE and HANDLER-BIND. However, current USOCKET didn't do condition work well: when SOCKET-CONNECT failed to connect, there's no uniform condition class signaled. I'm working on that, but if you can investigate on this and show me a working example for just any of your favorite CL platforms, I'd like to accept it as a new feature (once other related work was done)
Regards,
Chun Tian (binghe)
在 2011-3-16,22:13, Alexey Martynov 写道:
I have following problem: remote hostname resolves to multiple addresses and I want to try all one by one until connection is succeeded. But:
- current policy when multiple addresses given for hostname - try random one.
- no API for resolving addresses.
I can try to propose patch for this problem but in which direction I should go: provide resolving API or involve sequential trying of addresses?
-- Alexey Martynov
usocket-devel mailing list usocket-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/usocket-devel