X-Git-Url: http://dolda2000.com/gitweb/?p=lisp-utils.git;a=blobdiff_plain;f=common-net.lisp;h=57a5b84179253be609da7aa75b8119880d827999;hp=ffe7a2d75a01cab9658f12fe4b7b583ae66e5058;hb=HEAD;hpb=46ab5dc9cbab6096c81b7735a0e4751761c22c2c diff --git a/common-net.lisp b/common-net.lisp index ffe7a2d..57a5b84 100644 --- a/common-net.lisp +++ b/common-net.lisp @@ -107,6 +107,11 @@ (define-condition network-error (error) ()) +(define-condition simple-network-error (network-error simple-error) ()) + +(defun simple-network-error (format &rest args) + (error 'simple-network-error :format-control format :format-arguments args)) + (define-condition socket-error (socket-condition network-error) ()) (define-condition address-busy (network-error) @@ -429,7 +434,13 @@ (defmethod connected-address-p ((address tcp-address)) t) -(export '(tcp-address tcp4-address tcp6-address)) +(defun tcp-address-for (host-address port) + (check-type port (unsigned-byte 16)) + (etypecase host-address + (ipv4-address (make-instance 'tcp4-address :host-address host-address :port port)) + (ipv6-address (make-instance 'tcp6-address :host-address host-address :port port)))) + +(export '(tcp-address tcp4-address tcp6-address tcp-address-for)) ;;; UDP code @@ -439,18 +450,25 @@ (defmethod connected-address-p ((address tcp-address)) nil) -(export '(udp-address udp4-address udp6-address)) +(defun udp-address-for (host-address port) + (check-type port (unsigned-byte 16)) + (etypecase host-address + (ipv4-address (make-instance 'udp4-address :host-address host-address :port port)) + (ipv6-address (make-instance 'udp6-address :host-address host-address :port port)))) + +(export '(udp-address udp4-address udp6-address udp-address-for)) ;;; Unix sockets (defclass local-address (address) - ((path :type pathname))) + ((path :type (or pathname nil)))) (defmethod initialize-instance :after ((instance local-address) &key path) - (setf (slot-value instance 'path) (pathname path))) + (setf (slot-value instance 'path) (and path (pathname path)))) (defmethod format-address ((address local-address)) - (namestring (slot-value address 'path))) + (let ((path (slot-value address 'path))) + (and path (namestring path)))) (defclass local-stream-address (local-address) ()) (defclass local-seq-address (local-address) ())