Changeset 16650


Ignore:
Timestamp:
Dec 4, 2015, 12:31:10 AM (5 years ago)
Author:
svspire
Message:

#'resolve-address respects its errorp arg again. Changed a few callers
that don't want errors back to make that explicit. But there may be
others I missed.
Fixes ticket #1329. Probably.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/library/sockets.lisp

    r16626 r16650  
    14661466
    14671467(defun resolve-address (&key
    1468                           host
    1469                           port
    1470                           (socket-type :stream)
    1471                           (connect :active)
    1472                           address-family
    1473                           numeric-host-p
    1474                           #-windows-target numeric-service-p
    1475                           (singlep t)
    1476                           (errorp t))
     1468                        host
     1469                        port
     1470                        (socket-type :stream)
     1471                        (connect :active)
     1472                        address-family
     1473                        numeric-host-p
     1474                        #-windows-target numeric-service-p
     1475                        (singlep t)
     1476                        (errorp t))
    14771477  "Resolve a host and/or port string to one or more socket-address
    1478 instances.  Either host or port may be unspecified.  Calls
    1479 getaddrinfo() underneath.
    1480 
    1481 singlep may be passed as NIL to make the function return a list of
    1482 host addresses matching the specified query terms.  The default is to
    1483 return the first matching address.
    1484 
    1485 errorp may be passed as NIL to return NIL if no match was found."
    1486 
     1478  instances.  Either host or port may be unspecified.  Calls
     1479  getaddrinfo() underneath.
     1480 
     1481  singlep may be passed as NIL to make the function return a list of
     1482  host addresses matching the specified query terms.  The default is to
     1483  return the first matching address.
     1484 
     1485  errorp may be passed as NIL to return NIL if no match was found."
     1486 
    14871487  ;; We have historically supported the use of an (unsigned-byte 32)
    14881488  ;; value to represent an IPv4 address. If existing code does that to
     
    15001500                                                 (string port)) proto)))))
    15011501      (if (null inet-port)
    1502         (when errorp
    1503           (error "can't resolve port ~s with getservbyname" port))
    1504         (let* ((socket-address (make-instance 'socket-address))
    1505                (sin (sockaddr socket-address)))
    1506           (setf (pref sin :sockaddr_in.sin_family) #$AF_INET)
    1507           (setf (pref sin
    1508                       #+(or windows-target solaris-target) #>sockaddr_in.sin_addr.S_un.S_addr
    1509                       #-(or windows-target solaris-target) :sockaddr_in.sin_addr.s_addr) (htonl host))
    1510           (setf (pref sin :sockaddr_in.sin_port) inet-port)
    1511           (upgrade-socket-address-from-sockaddr #$AF_INET socket-address)
    1512           (return-from resolve-address socket-address)))))
    1513    
     1502          (when errorp
     1503            (error "can't resolve port ~s with getservbyname" port))
     1504          (let* ((socket-address (make-instance 'socket-address))
     1505                 (sin (sockaddr socket-address)))
     1506            (setf (pref sin :sockaddr_in.sin_family) #$AF_INET)
     1507            (setf (pref sin
     1508                        #+(or windows-target solaris-target) #>sockaddr_in.sin_addr.S_un.S_addr
     1509                        #-(or windows-target solaris-target) :sockaddr_in.sin_addr.s_addr) (htonl host))
     1510            (setf (pref sin :sockaddr_in.sin_port) inet-port)
     1511            (upgrade-socket-address-from-sockaddr #$AF_INET socket-address)
     1512            (return-from resolve-address socket-address)))))
     1513 
    15141514  (with-cstrs ((host-buf (or host ""))
    15151515               (port-buf (string-downcase (or (ensure-string port) ""))))
     
    15381538        (if (eql 0 err)
    15391539            (prog1
    1540                 (or (loop for info = (pref results :address) then (pref info #>addrinfo.ai_next)
    1541                           until (%null-ptr-p info)
    1542                           for sockaddr = (pref info #>addrinfo.ai_addr)
    1543                           for socket-address = (make-instance 'socket-address)
    1544                           do (loop for i below (pref info #>addrinfo.ai_addrlen)
    1545                                    do (setf (paref (sockaddr socket-address) :uint8_t i)
    1546                                             (paref sockaddr :uint8_t i)))
    1547                              (upgrade-socket-address-from-sockaddr (pref (sockaddr socket-address) :sockaddr_storage.ss_family)
    1548                                                                    socket-address)
    1549                           if singlep
    1550                             do (return socket-address)
    1551                           else
    1552                             collect socket-address)
    1553                     (when errorp
    1554                       (error "cannot resolve local service host ~A port ~A connect ~S type ~S"
    1555                              host port connect socket-type)))
     1540              (or (loop for info = (pref results :address) then (pref info #>addrinfo.ai_next)
     1541                    until (%null-ptr-p info)
     1542                    for sockaddr = (pref info #>addrinfo.ai_addr)
     1543                    for socket-address = (make-instance 'socket-address)
     1544                    do (loop for i below (pref info #>addrinfo.ai_addrlen)
     1545                         do (setf (paref (sockaddr socket-address) :uint8_t i)
     1546                                  (paref sockaddr :uint8_t i)))
     1547                    (upgrade-socket-address-from-sockaddr (pref (sockaddr socket-address) :sockaddr_storage.ss_family)
     1548                                                          socket-address)
     1549                    if singlep
     1550                    do (return socket-address)
     1551                    else
     1552                    collect socket-address)
     1553                  (when errorp
     1554                    (error "cannot resolve local service host ~A port ~A connect ~S type ~S"
     1555                           host port connect socket-type)))
    15561556              (#_freeaddrinfo (pref results :address)))
    1557               (values nil err))))))
     1557            (if errorp
     1558                (socket-error nil "getaddrinfo" err t)
     1559                (values nil err)))))))
    15581560
    15591561(defclass ip4-socket-address (ip-socket-address)
     
    17111713                                                                (:udp :datagram)
    17121714                                                                (:tcp :stream))
    1713                                                               proto))))
     1715                                                              proto)
     1716                                             :errorp nil)))
    17141717        (when socket-address
    17151718          (port socket-address)))))
     
    17201723  (if (typep host 'integer)
    17211724      host
    1722       (let ((socket-address (resolve-address :host host :address-family :internet)))
     1725      (let ((socket-address (resolve-address :host host :address-family :internet :errorp nil)))
    17231726        (when socket-address
    17241727          (host socket-address)))))
Note: See TracChangeset for help on using the changeset viewer.