[usocket-devel] socket-connect and hostnames resolved to multiple addresses

Nikodemus Siivola nikodemus at random-state.net
Thu Mar 17 08:02:28 UTC 2011


Here's what I would consider one idiomatic way to try all addresses on
using SB-BSD-SOCKETS.

(defun connect-to-host (socket host port)
  (let ((addresses (host-ent-addresses (get-host-by-name host))))
    (tagbody
     :connect
       (let ((addr (pop addresses)))
         (handler-bind ((socket-error
                         (lambda (e) (when addresses (go :connect)))))
           (socket-connect socket addr port))))))

Cheers,

 -- Nikodemus




More information about the usocket-devel mailing list