From 6b055d740f36bce05cbb19377fcc98a8ff92e1f5 Mon Sep 17 00:00:00 2001 From: Stelian Ionescu Date: Fri, 18 Apr 2008 01:54:40 +0200 Subject: [PATCH] Rename FAMILY to ADDRESS-FAMILY in MAKE-SOCKET and socket classes. Signed-off-by: Stelian Ionescu --- doc/sockets.texinfo | 2 +- net.sockets/base-sockets.lisp | 12 ++++++------ net.sockets/make-socket.lisp | 40 ++++++++++++++++++++-------------------- net.sockets/pkgdcl.lisp | 2 +- net.sockets/socket-methods.lisp | 20 ++++++++++---------- net.sockets/trivial-sockets.lisp | 4 ++-- tests/events.lisp | 4 ++-- tests/sockets.lisp | 28 ++++++++++++++-------------- 8 files changed, 56 insertions(+), 56 deletions(-) diff --git a/doc/sockets.texinfo b/doc/sockets.texinfo index 9d68bb9..4cf3ecd 100644 --- a/doc/sockets.texinfo +++ b/doc/sockets.texinfo @@ -198,7 +198,7 @@ Describe sockets here. @include include/fun-sockets-socket-os-fd.texinfo @include include/fun-sockets-socket-type.texinfo @include include/fun-sockets-socket-protocol.texinfo -@include include/fun-sockets-socket-family.texinfo +@include include/fun-sockets-socket-address-family.texinfo @include include/fun-sockets-socket-open-p.texinfo @include include/fun-sockets-ipv6-socket-p.texinfo @include include/fun-sockets-local-name.texinfo diff --git a/net.sockets/base-sockets.lisp b/net.sockets/base-sockets.lisp index 16c2fdd..849c824 100644 --- a/net.sockets/base-sockets.lisp +++ b/net.sockets/base-sockets.lisp @@ -8,12 +8,12 @@ ;;;; Sockets (defclass socket (dual-channel-single-fd-mixin) - ((family :initarg :family :accessor socket-family) + ((address-family :initarg :address-family :accessor socket-address-family) (protocol :initarg :protocol :accessor socket-protocol) (bound :initform nil :reader socket-bound-p :type boolean)) (:documentation "Base class for sockets.")) -(unset-method-docstring #'socket-family () '(socket)) -(set-function-docstring 'socket-family "Return the family of a socket.") +(unset-method-docstring #'socket-address-family () '(socket)) +(set-function-docstring 'socket-address-family "Return the address family of a socket.") (unset-method-docstring #'socket-protocol () '(socket)) (set-function-docstring 'socket-protocol "Return the protocol of a socket.") @@ -74,15 +74,15 @@ For a complete list of supported options see net.sockets/socket-options.lisp .") (:documentation "Disassociates `SOCKET' from any remote address. Works only on DATAGRAM sockets.")) -(define-symbol-macro +default-inet-family+ +(define-symbol-macro +default-inet-address-family+ (if *ipv6* :ipv6 :ipv4)) (defclass internet-socket (socket) () - (:default-initargs :family +default-inet-family+) + (:default-initargs :address-family +default-inet-address-family+) (:documentation "Mixin for sockets of domain AF_INET or AF_INET6.")) (defclass local-socket (socket) () - (:default-initargs :family :local) + (:default-initargs :address-family :local) (:documentation "Mixin for sockets of domain AF_LOCAL.")) (defgeneric send-file-descriptor (socket file-descriptor) diff --git a/net.sockets/make-socket.lisp b/net.sockets/make-socket.lisp index 411871d..59d960e 100644 --- a/net.sockets/make-socket.lisp +++ b/net.sockets/make-socket.lisp @@ -8,7 +8,7 @@ (defun create-socket (family type connect external-format &key fd input-buffer-size output-buffer-size) (make-instance (select-socket-class family type connect :default) - :family family :file-descriptor fd + :address-family family :file-descriptor fd :external-format external-format :input-buffer-size input-buffer-size :output-buffer-size output-buffer-size)) @@ -18,7 +18,7 @@ (cond ((and (constantp family) (constantp type) (constantp connect)) `(make-instance ',(select-socket-class family type connect :default) - :family ,family :file-descriptor ,fd + :address-family ,family :file-descriptor ,fd :external-format ,external-format :input-buffer-size ,input-buffer-size :output-buffer-size ,output-buffer-size)) @@ -270,53 +270,53 @@ If a non-local exit occurs during the execution of `BODY' call CLOSE with :ABORT ;;; MAKE-SOCKET -(defun make-socket (&rest args &key (family :internet) (type :stream) +(defun make-socket (&rest args &key (address-family :internet) (type :stream) (connect :active) (ipv6 *ipv6*) (external-format :default) &allow-other-keys) "Creates a socket instance of the appropriate subclass of SOCKET." - (check-type family (member :internet :local :ipv4 :ipv6) "one of :INTERNET, :LOCAL, :IPV4 or :IPV6") + (check-type address-family (member :internet :local :ipv4 :ipv6) "one of :INTERNET, :LOCAL, :IPV4 or :IPV6") (check-type type (member :stream :datagram) "either :STREAM or :DATAGRAM") (check-type connect (member :active :passive) "either :ACTIVE or :PASSIVE") - (let ((args (remove-from-plist args :family :type :connect :external-format :ipv6))) - (when (eq :ipv4 family) (setf ipv6 nil)) + (let ((args (remove-from-plist args :address-family :type :connect :external-format :ipv6))) + (when (eq :ipv4 address-family) (setf ipv6 nil)) (let ((*ipv6* ipv6)) - (when (eq :internet family) (setf family +default-inet-family+)) - (multiple-value-case ((family type connect) :test #'eq) + (when (eq :internet address-family) (setf address-family +default-inet-address-family+)) + (multiple-value-case ((address-family type connect) :test #'eq) (((:ipv4 :ipv6) :stream :active) - (%make-internet-stream-active-socket args family external-format)) + (%make-internet-stream-active-socket args address-family external-format)) (((:ipv4 :ipv6) :stream :passive) - (%make-internet-stream-passive-socket args family external-format)) + (%make-internet-stream-passive-socket args address-family external-format)) ((:local :stream :active) (%make-local-stream-active-socket args :local external-format)) ((:local :stream :passive) (%make-local-stream-passive-socket args :local external-format)) (((:ipv4 :ipv6) :datagram) - (%make-internet-datagram-socket args family external-format)) + (%make-internet-datagram-socket args address-family external-format)) ((:local :datagram) (%make-local-datagram-socket args :local external-format)))))) -(define-compiler-macro make-socket (&whole form &rest args &key (family :internet) (type :stream) +(define-compiler-macro make-socket (&whole form &rest args &key (address-family :internet) (type :stream) (connect :active) (ipv6 '*ipv6* ipv6p) (external-format :default) &allow-other-keys) (cond - ((and (constantp family) (constantp type) (constantp connect)) - (check-type family (member :internet :local :ipv4 :ipv6) "one of :INTERNET, :LOCAL, :IPV4 or :IPV6") + ((and (constantp address-family) (constantp type) (constantp connect)) + (check-type address-family (member :internet :local :ipv4 :ipv6) "one of :INTERNET, :LOCAL, :IPV4 or :IPV6") (check-type type (member :stream :datagram) "either :STREAM or :DATAGRAM") (check-type connect (member :active :passive) "either :ACTIVE or :PASSIVE") (let ((lower-function - (multiple-value-case ((family type connect) :test #'eq) + (multiple-value-case ((address-family type connect) :test #'eq) (((:ipv4 :ipv6 :internet) :stream :active) '%make-internet-stream-active-socket) (((:ipv4 :ipv6 :internet) :stream :passive) '%make-internet-stream-passive-socket) ((:local :stream :active) '%make-local-stream-active-socket) ((:local :stream :passive) '%make-local-stream-passive-socket) (((:ipv4 :ipv6 :internet) :datagram) '%make-internet-datagram-socket) ((:local :datagram) '%make-local-datagram-socket))) - (newargs (remove-from-plist args :family :type :connect :external-format :ipv6))) - (multiple-value-case (family) - (:internet (setf family '+default-inet-family+)) + (newargs (remove-from-plist args :address-family :type :connect :external-format :ipv6))) + (multiple-value-case (address-family) + (:internet (setf address-family '+default-inet-address-family+)) (:ipv4 (setf ipv6 nil))) - (let ((expansion `(,lower-function (list ,@newargs) ,family ,external-format))) - (if (or ipv6p (eq :ipv4 family)) + (let ((expansion `(,lower-function (list ,@newargs) ,address-family ,external-format))) + (if (or ipv6p (eq :ipv4 address-family)) `(let ((*ipv6* ,ipv6)) ,expansion) expansion)))) (t form))) diff --git a/net.sockets/pkgdcl.lisp b/net.sockets/pkgdcl.lisp index 241f018..2853d95 100644 --- a/net.sockets/pkgdcl.lisp +++ b/net.sockets/pkgdcl.lisp @@ -192,7 +192,7 @@ #:send-to #:shutdown #:socket-connected-p - #:socket-family + #:socket-address-family #:socket-open-p #:socket-option #:socket-os-fd diff --git a/net.sockets/socket-methods.lisp b/net.sockets/socket-methods.lisp index 9b66b30..d9d1bee 100644 --- a/net.sockets/socket-methods.lisp +++ b/net.sockets/socket-methods.lisp @@ -17,15 +17,15 @@ ((:ipv6 :datagram :active :default) . socket-datagram-internet-active))) ;;; FIXME: should match :default to whatever protocol is the default. -(defun select-socket-class (family type connect protocol) - (or (cdr (assoc (list family type connect protocol) *socket-type-map* +(defun select-socket-class (address-family type connect protocol) + (or (cdr (assoc (list address-family type connect protocol) *socket-type-map* :test #'equal)) (error "No socket class found !!"))) ;;;; Shared Initialization -(defun translate-make-socket-keywords-to-constants (family type protocol) - (let ((sf (ecase family +(defun translate-make-socket-keywords-to-constants (address-family type protocol) + (let ((sf (ecase address-family (:ipv4 af-inet) (:ipv6 af-inet6) (:local af-local))) @@ -42,15 +42,15 @@ (fd-of socket)) (defmethod initialize-instance :after ((socket socket) &key - file-descriptor family type + file-descriptor address-family type (protocol :default)) - (with-accessors ((fd fd-of) (fam socket-family) (proto socket-protocol)) + (with-accessors ((fd fd-of) (fam socket-address-family) (proto socket-protocol)) socket (setf fd (or file-descriptor (multiple-value-call #'%socket (translate-make-socket-keywords-to-constants - family type protocol)))) - (setf fam family + address-family type protocol)))) + (setf fam address-family proto protocol))) (defmethod (setf external-format-of) (external-format (socket passive-socket)) @@ -71,12 +71,12 @@ (defun ipv6-socket-p (socket) "Return T if SOCKET is an AF_INET6 socket." - (eq :ipv6 (socket-family socket))) + (eq :ipv6 (socket-address-family socket))) ;;;; Printing (defun sock-fam (socket) - (ecase (socket-family socket) + (ecase (socket-address-family socket) (:ipv4 "IPv4") (:ipv6 "IPv6"))) diff --git a/net.sockets/trivial-sockets.lisp b/net.sockets/trivial-sockets.lisp index 0fec56b..774e42e 100644 --- a/net.sockets/trivial-sockets.lisp +++ b/net.sockets/trivial-sockets.lisp @@ -50,7 +50,7 @@ (error 'unsupported :feature `(:protocol ,protocol))) (let ((net.sockets:*ipv6* nil)) (handler-bind ((error (lambda (c) (error 'socket-error :nested-error c)))) - (net.sockets:make-socket :family :internet + (net.sockets:make-socket :address-family :internet :connect :active :type :stream :remote-host (resolve-hostname peer-host) @@ -69,7 +69,7 @@ (let ((net.sockets:*ipv6* nil)) (handler-bind ((error (lambda (c) (error 'socket-error :nested-error c)))) (let* ((host (if (eq host :any) net.sockets:+ipv4-unspecified+ host)) - (socket (net.sockets:make-socket :family :internet + (socket (net.sockets:make-socket :address-family :internet :type :stream :connect :passive :local-host host diff --git a/tests/events.lisp b/tests/events.lisp index bf63322..6ae8391 100644 --- a/tests/events.lisp +++ b/tests/events.lisp @@ -68,9 +68,9 @@ (test event-base-with-open-sockets (is-false (with-event-base (base) - (with-open-socket (passive :family :ipv4 :connect :passive + (with-open-socket (passive :address-family :ipv4 :connect :passive :local-host +ipv4-unspecified+) - (with-open-socket (active :family :ipv4 + (with-open-socket (active :address-family :ipv4 :remote-port (local-port passive) :remote-host #(127 0 0 1)) (add-timer base #'timeout-cb 5) diff --git a/tests/sockets.lisp b/tests/sockets.lisp index b084b5e..1ed9e1a 100644 --- a/tests/sockets.lisp +++ b/tests/sockets.lisp @@ -266,16 +266,16 @@ (make-socket :this-kw-arg-doesnt-exist t))) (test make-socket.2 - (is (equalp (with-open-socket (s :family :ipv4) + (is (equalp (with-open-socket (s :address-family :ipv4) (values (socket-connected-p s) (socket-open-p s) (> (socket-os-fd s) 1) - (socket-family s) + (socket-address-family s) (socket-protocol s))) (values nil t t :ipv4 :default)))) ; why isn't it :TCP? (test make-socket.3 - (is-true (with-open-socket (s :family :ipv4) + (is-true (with-open-socket (s :address-family :ipv4) (typep s 'socket)))) ;;; Given the functions we've got so far, if you can think of a better @@ -284,13 +284,13 @@ ;;; as me. (test inet.socket-bind.1 (signals socket-address-in-use-error - (with-open-socket (s :family :ipv4 :connect :passive + (with-open-socket (s :address-family :ipv4 :connect :passive :local-host #(127 0 0 1) :local-port 1974) - (with-open-socket (s :family :ipv4 :connect :passive + (with-open-socket (s :address-family :ipv4 :connect :passive :local-host #(127 0 0 1) :local-port 1974))))) (test sockopt.1 - (is-true (with-open-socket (s :family :ipv4) + (is-true (with-open-socket (s :address-family :ipv4) (setf (socket-option s :reuse-address) t) (socket-option s :reuse-address)))) @@ -307,7 +307,7 @@ (test simple-tcp-client (is-true (with-open-socket (s :remote-host *echo-address* :remote-port *echo-port* - :family :ipv4) + :address-family :ipv4) (let ((data (make-string 200))) (format s "here is some text") (finish-output s) @@ -318,7 +318,7 @@ (test sockaddr-return-type (is-true (with-open-socket (s :remote-host *echo-address* :remote-port *echo-port* - :family :ipv4) + :address-family :ipv4) (and (ipv4-address-p (remote-host s)) (numberp (remote-port s)))))) @@ -331,14 +331,14 @@ (test simple-udp-client.1 (is-true (with-open-socket (s :remote-host *echo-address* :remote-port *echo-port* - :type :datagram :family :ipv4) + :type :datagram :address-family :ipv4) (send-to s "here is some text") (let ((nbytes (nth-value 1 (receive-from s :size 200)))) (plusp nbytes))))) (test simple-udp-client.2 (is-true - (with-open-socket (s :type :datagram :family :ipv4) + (with-open-socket (s :type :datagram :address-family :ipv4) (send-to s "here is some more text" :remote-host *echo-address* :remote-port *echo-port*) @@ -352,8 +352,8 @@ (asdf:system-definition-pathname (asdf:find-system '#:iolib-tests))))))) ;; (ignore-errors (delete-file file)) - (with-open-socket (p :family :local :connect :passive :local-filename file) - (with-open-socket (a :family :local :remote-filename file) + (with-open-socket (p :address-family :local :connect :passive :local-filename file) + (with-open-socket (a :address-family :local :remote-filename file) (format a "local socket test") (finish-output a)) (let ((s (accept-connection p))) @@ -363,7 +363,7 @@ "local socket test"))) (defmacro with-http-stream ((var host port request) &body body) - `(with-open-socket (,var :family :ipv4 :remote-host ,host :remote-port ,port) + `(with-open-socket (,var :address-family :ipv4 :remote-host ,host :remote-port ,port) (format ,var ,(concatenate 'string request " HTTP/1.0~%~%")) (finish-output ,var) ,@body)) @@ -396,7 +396,7 @@ (test socket-open-p.2 (is-true (with-open-socket (s :remote-host *echo-address* :remote-port *echo-port* - :family :ipv4) + :address-family :ipv4) (socket-open-p s)))) (test socket-open-p.3 -- 2.11.4.GIT