Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Broke up files to only one real export per file.

  • Loading branch information...
commit 19e559643e2e10af5e310fb70c1b655771ceb82c 1 parent 84b40cc
@nklein authored
View
31 sockets/api.lisp
@@ -1,13 +1,28 @@
(org.tfeb.conduit-packages:defpackage :unet-sockets
(:use :cl)
(:extends/including :unet-sockets-interface
- #:sockets-interface
- #:sockets-hostname-not-found-error
- #:sockets-hostname-not-found-error-hostname
- #:sockets-get-address
- #:sockets-create-datagram-socket)
+ #:sockets-interface)
(:extends/including :unet-sockets-base-socket
- #:sockets-base-socket
- #:sockets-send-datagram
- #:sockets-poll-datagram))
+ #:base-socket)
+
+ (:extends/including :unet-sockets-hostname-not-found-error
+ #:hostname-not-found-error
+ #:hostname-not-found-error-hostname)
+
+ (:extends/including :unet-sockets-get-address
+ #:get-address)
+
+ (:extends/including :unet-sockets-address+port-not-available-error
+ #:address+port-not-available-error
+ #:address+port-not-available-error-address
+ #:address+port-not-available-error-port)
+
+ (:extends/including :unet-sockets-create-datagram-socket
+ #:create-datagram-socket)
+
+ (:extends/including :unet-sockets-send-datagram
+ #:send-datagram)
+
+ (:extends/including :unet-sockets-poll-datagram
+ #:poll-datagram))
View
12 sockets/base-socket.lisp
@@ -1,13 +1,9 @@
(defpackage :unet-sockets-base-socket
(:use :cl)
- (:export :sockets-base-socket
- :sockets-send-datagram
- :sockets-poll-datagram))
+ (:export :base-socket))
(in-package :unet-sockets-base-socket)
-(defclass sockets-base-socket ()
- ())
-
-(defgeneric sockets-send-datagram (sockets-base-socket data ip-address port))
-(defgeneric sockets-poll-datagram (sockets-base-socket))
+(defclass base-socket ()
+ ()
+ (:documentation "The BASE-SOCKET class is the base class for all sockets returned from specializations of the CREATE-DATAGRAM-SOCKET method"))
View
27 sockets/fake/add-socket-to-interface.lisp
@@ -0,0 +1,27 @@
+;;;
+;;; File: unet/sockets/fake/add-socket-to-interface.lisp
+;;; Author: Patrick Stein <pat@nklein.com>
+;;;
+
+;;;---------------------------------------------------------------------------
+;;; Visibility: This package should not be imported or used from outside
+;;; of this directory.
+(defpackage :unet-sockets-fake-add-socket-to-interface
+ (:use :cl)
+ (:import-from :unet-sockets-fake-interface
+ #:interface-hash-table)
+ (:import-from :unet-sockets-fake-make-hash-key
+ #:make-hash-key)
+ (:import-from :unet-sockets-fake-get-socket-from-interface
+ #:get-socket-from-interface)
+ (:export :add-socket-to-interface))
+
+(in-package :unet-sockets-fake-add-socket-to-interface)
+
+;;;---------------------------------------------------------------------------
+;;; Visibility: Exported from this package
+(defun add-socket-to-interface (interface ip-address port socket)
+ "This function is used to add a new SOCKET to the INTERFACE's set of managed sockets. The IP-ADDRESS and PORT will be used at a later time to retrieve this SOCKET."
+ (unless (get-socket-from-interface interface ip-address port)
+ (let ((key (make-hash-key ip-address port)))
+ (setf (gethash key (interface-hash-table interface)) socket))))
View
35 sockets/fake/create-datagram-socket.lisp
@@ -0,0 +1,35 @@
+;;;
+;;; File: unet/sockets/fake/create-datagram-socket.lisp
+;;; Author: Patrick Stein <pat@nklein.com>
+;;;
+
+;;;---------------------------------------------------------------------------
+;;; Visibility: This package should not be imported or used from outside
+;;; of this directory.
+(defpackage :unet-sockets-fake-create-datagram-socket
+ (:use :cl)
+ (:import-from :unet-sockets
+ #:address+port-not-available-error
+ #:create-datagram-socket)
+ (:import-from :unet-sockets-fake-interface
+ #:fake-sockets-interface)
+ (:import-from :unet-sockets-fake-add-socket-to-interface
+ #:add-socket-to-interface)
+ (:import-from :unet-sockets-fake-socket
+ #:fake-socket))
+
+(in-package :unet-sockets-fake-create-datagram-socket)
+
+;;;---------------------------------------------------------------------------
+;;; Visibility: Public via the UNET-SOCKETS package
+(defmethod create-datagram-socket ((sockets-interface fake-sockets-interface)
+ ip-address
+ port)
+ "This method implements the CREATE-DATAGRAM-SOCKET method of the UNET-SOCKETS:SOCKETS-INTERFACE for the FAKE-SOCKETS-INTERFACE. For the FAKE-SOCKETS-INTERFACE, this adds a new queue to be managed by the FAKE-SOCKETS-INTERFACE and indexed by the IP-ADDRESS and PORT."
+ (let ((socket (make-instance 'fake-socket
+ :interface sockets-interface)))
+ (unless (add-socket-to-interface sockets-interface ip-address port socket)
+ (error 'address+port-not-available-error
+ :address ip-address
+ :port port))
+ socket))
View
23 sockets/fake/get-address.lisp
@@ -0,0 +1,23 @@
+;;;
+;;; File: unet/sockets/fake/get-address.lisp
+;;; Author: Patrick Stein <pat@nklein.com>
+;;;
+
+;;;---------------------------------------------------------------------------
+;;; Visibility: This package should not be imported or used from outside
+;;; of this directory.
+(defpackage :unet-sockets-fake-get-address
+ (:use :cl)
+ (:import-from :unet-sockets
+ #:get-address)
+ (:import-from :unet-sockets-fake-interface
+ #:fake-sockets-interface))
+
+(in-package :unet-sockets-fake-get-address)
+
+;;;---------------------------------------------------------------------------
+;;; Visibility: Public via the UNET-SOCKETS package
+(defmethod get-address
+ ((sockets-interface fake-sockets-interface) (hostname string))
+ "This method implements the UNET-SOCKETS:SOCKETS-GET-ADDRESS method for the FAKE-SOCKETS-INTERFACE. For the FAKE-SOCKETS-INTERFACE, we simply make a keyword from the given HOSTNAME as we do not need the IP-ADDRESS to actually mean anything in the outside world."
+ (values (intern (string-upcase hostname) "KEYWORD")))
View
24 sockets/fake/get-socket-from-interface.lisp
@@ -0,0 +1,24 @@
+;;;
+;;; File: unet/sockets/fake/get-socket-from-interface.lisp
+;;; Author: Patrick Stein <pat@nklein.com>
+;;;
+
+;;;---------------------------------------------------------------------------
+;;; Visibility: This package should not be imported or used from outside
+;;; of this directory.
+(defpackage :unet-sockets-fake-get-socket-from-interface
+ (:use :cl)
+ (:import-from :unet-sockets-fake-make-hash-key
+ #:make-hash-key)
+ (:import-from :unet-sockets-fake-interface
+ #:interface-hash-table)
+ (:export :get-socket-from-interface))
+
+(in-package :unet-sockets-fake-get-socket-from-interface)
+
+;;;---------------------------------------------------------------------------
+;;; Visibility: Exported from this package
+(defun get-socket-from-interface (interface ip-address port)
+ "This function is used to retrieve a SOCKET from the INTERFACE's set of managed sockets. The IP-ADDRESS and PORT are used to find the appropriate SOCKET."
+ (let ((key (make-hash-key ip-address port)))
+ (values (gethash key (interface-hash-table interface)))))
View
24 sockets/fake/interface.lisp
@@ -11,9 +11,7 @@
(:documentation "This package defines the FAKE-SOCKETS-INTERFACE which implements the UNET-SOCKETS:SOCKETS-INTERFACE. This package also defines some utility functions used by other packages in this directory to implement the methods needed for the UNET-SOCKETS:SOCKETS-INTERFACE.")
(:import-from :unet-sockets
#:sockets-interface)
- (:export :fake-sockets-interface
- :add-socket-to-interface
- :get-socket-from-interface))
+ (:export :fake-sockets-interface))
(in-package :unet-sockets-fake-interface)
@@ -23,23 +21,3 @@
((sockets :initform (make-hash-table :test #'equal)
:reader interface-hash-table))
(:documentation "This class implements the UNET-SOCKETS:SOCKETS-INTERFACE. It does so without a network connection by managing a list of incoming-queues for each declared socket. These queues are kept in a hash table indexed by the IP-ADDRESS and PORT of the socket."))
-
-;;;---------------------------------------------------------------------------
-;;; Visibility: Private to this package
-(defun make-hash-key (ip-address port)
- "This function is used to create a hash key from a given IP-ADDRESS and PORT"
- (cons ip-address port))
-
-;;;---------------------------------------------------------------------------
-;;; Visibility: Exported from this package
-(defun add-socket-to-interface (interface ip-address port socket)
- "This function is used to add a new SOCKET to the INTERFACE's set of managed sockets. The IP-ADDRESS and PORT will be used at a later time to retrieve this SOCKET."
- (let ((key (make-hash-key ip-address port)))
- (setf (gethash key (interface-hash-table interface)) socket)))
-
-;;;---------------------------------------------------------------------------
-;;; Visibility: Exported from this package
-(defun get-socket-from-interface (interface ip-address port)
- "This function is used to retrieve a SOCKET from the INTERFACE's set of managed sockets. The IP-ADDRESS and PORT are used to find the appropriate SOCKET."
- (let ((key (make-hash-key ip-address port)))
- (values (gethash key (interface-hash-table interface)))))
View
19 sockets/fake/make-hash-key.lisp
@@ -0,0 +1,19 @@
+;;;
+;;; File: unet/sockets/fake/make-hash-key.lisp
+;;; Author: Patrick Stein <pat@nklein.com>
+;;;
+
+;;;---------------------------------------------------------------------------
+;;; Visibility: This package should not be imported or used from outside
+;;; of this directory.
+(defpackage :unet-sockets-fake-make-hash-key
+ (:use :cl)
+ (:export :make-hash-key))
+
+(in-package :unet-sockets-fake-make-hash-key)
+
+;;;---------------------------------------------------------------------------
+;;; Visibility: Should only be used by other packages in this directory.
+(defun make-hash-key (ip-address port)
+ "This function is used to create a hash key from a given IP-ADDRESS and PORT"
+ (cons ip-address port))
View
65 sockets/fake/methods.lisp
@@ -1,65 +0,0 @@
-;;;
-;;; File: unet/sockets/fake/methods.lisp
-;;; Author: Patrick Stein <pat@nklein.com>
-;;;
-
-;;;---------------------------------------------------------------------------
-;;; Visibility: This package should not be imported or used from outside
-;;; of this directory.
-(defpackage :unet-sockets-fake-methods
- (:use :cl)
- (:documentation "This package implements the methods required of the FAKE-SOCKETS-INTERFACE to support the UNET-SOCKETS:SOCKETS-INTERFACE. It implements the SOCKETS-GET-ADDRESS, SOCKETS-CREATE-DATAGRAM-SOCKET, SOCKETS-SEND-DATAGRAM, and SOCKETS-POLL-DATAGRAM methods required by UNET-SOCKETS:SOCKETS-INTERFACE.")
- (:import-from :jpl-queues
- #:enqueue
- #:empty?
- #:dequeue)
- (:import-from :unet-sockets
- #:sockets-get-address
- #:sockets-create-datagram-socket
- #:sockets-send-datagram
- #:sockets-poll-datagram)
- (:import-from :unet-sockets-fake-interface
- #:fake-sockets-interface
- #:add-socket-to-interface
- #:get-socket-from-interface)
- (:import-from :unet-sockets-fake-socket
- #:fake-socket
- #:socket-get-interface
- #:socket-incoming-queue))
-
-(in-package :unet-sockets-fake-methods)
-
-;;;---------------------------------------------------------------------------
-;;; Visibility: Public via the UNET-SOCKETS package
-(defmethod sockets-get-address
- ((sockets-interface fake-sockets-interface) (hostname string))
- "This method implements the UNET-SOCKETS:SOCKETS-GET-ADDRESS method for the FAKE-SOCKETS-INTERFACE. For the FAKE-SOCKETS-INTERFACE, we simply make a keyword from the given HOSTNAME as we do not need the IP-ADDRESS to actually mean anything in the outside world."
- (values (intern (string-upcase hostname) "KEYWORD")))
-
-;;;---------------------------------------------------------------------------
-;;; Visibility: Public via the UNET-SOCKETS package
-(defmethod sockets-create-datagram-socket
- ((sockets-interface fake-sockets-interface) ip-address port)
- "This method implements the SOCKETS-CREATE-DATAGRAM-SOCKET method of the UNET-SOCKETS:SOCKETS-INTERFACE for the FAKE-SOCKETS-INTERFACE. For the FAKE-SOCKETS-INTERFACE, this adds a new queue to be managed by the FAKE-SOCKETS-INTERFACE and indexed by the IP-ADDRESS and PORT."
- (let ((socket (make-instance 'fake-socket
- :interface sockets-interface)))
- (add-socket-to-interface sockets-interface ip-address port socket)
- socket))
-
-;;;---------------------------------------------------------------------------
-;;; Visibility: Public via the UNET-SOCKETS package
-(defmethod sockets-send-datagram ((socket fake-socket) data ip-address port)
- "This method implements the SOCKETS-SEND-DATAGRAM method of the UNET-SOCKETS:SOCKETS-INTERFACE for the FAKE-SOCKETS-INTERFACE. For the FAKE-SOCKETS-INTERFACE, this finds the destination queue using the IP-ADDRESS and PORT managed by the FAKE-SOCKETS-INTERFACE that created the sending SOCKET and adds the DATA to the incoming queue for that destination."
- (let ((destination (get-socket-from-interface (socket-get-interface socket)
- ip-address
- port)))
- (enqueue data (socket-incoming-queue destination))))
-
-;;;---------------------------------------------------------------------------
-;;; Visibility: Public via the UNET-SOCKETS package
-(defmethod sockets-poll-datagram ((socket fake-socket))
- "This method implements the SOCKETS-POLL-DATAGRAM method of the UNET-SOCKETS:SOCKETS-INTERFACE for the FAKE-SOCKETS-INTERFACE. For the FAKE-SOCKETS-INTERFACE, this checks the incoming queue of the given SOCKET and returns the next value on it if there is one."
- (let ((queue (socket-incoming-queue socket)))
- (cond
- ((empty? queue) (values nil nil))
- (t (values (dequeue queue) t)))))
View
29 sockets/fake/poll-datagram.lisp
@@ -0,0 +1,29 @@
+;;;
+;;; File: unet/sockets/fake/poll-datagram.lisp
+;;; Author: Patrick Stein <pat@nklein.com>
+;;;
+
+;;;---------------------------------------------------------------------------
+;;; Visibility: This package should not be imported or used from outside
+;;; of this directory.
+(defpackage :unet-sockets-fake-poll-datagram
+ (:use :cl)
+ (:import-from :jpl-queues
+ #:dequeue)
+ (:import-from :unet-sockets
+ #:poll-datagram)
+ (:import-from :unet-sockets-fake-get-socket-from-interface
+ #:get-socket-from-interface)
+ (:import-from :unet-sockets-fake-socket
+ #:fake-socket
+ #:socket-get-interface
+ #:socket-incoming-queue))
+
+(in-package :unet-sockets-fake-poll-datagram)
+
+;;;---------------------------------------------------------------------------
+;;; Visibility: Public via the UNET-SOCKETS package
+(defmethod poll-datagram ((socket fake-socket))
+ "This method implements the POLL-DATAGRAM method of the UNET-SOCKETS:SOCKETS-INTERFACE for the FAKE-SOCKETS-INTERFACE. For the FAKE-SOCKETS-INTERFACE, this checks the incoming queue of the given SOCKET and returns the next value on it if there is one."
+ (let ((queue (socket-incoming-queue socket)))
+ (dequeue queue)))
View
34 sockets/fake/send-datagram.lisp
@@ -0,0 +1,34 @@
+;;;
+;;; File: unet/sockets/fake/send-datagram.lisp
+;;; Author: Patrick Stein <pat@nklein.com>
+;;;
+
+;;;---------------------------------------------------------------------------
+;;; Visibility: This package should not be imported or used from outside
+;;; of this directory.
+(defpackage :unet-sockets-fake-send-datagram
+ (:use :cl)
+ (:import-from :jpl-queues
+ #:enqueue)
+ (:import-from :unet-sockets
+ #:send-datagram)
+ (:import-from :unet-sockets-fake-get-socket-from-interface
+ #:get-socket-from-interface)
+ (:import-from :unet-sockets-fake-socket
+ #:fake-socket
+ #:socket-get-interface
+ #:socket-incoming-queue))
+
+(in-package :unet-sockets-fake-send-datagram)
+
+;;;---------------------------------------------------------------------------
+;;; Visibility: Public via the UNET-SOCKETS package
+(defmethod send-datagram ((socket fake-socket)
+ data
+ ip-address
+ port)
+ "This method implements the SOCKETS-SEND-DATAGRAM method of the UNET-SOCKETS:SOCKETS-INTERFACE for the FAKE-SOCKETS-INTERFACE. For the FAKE-SOCKETS-INTERFACE, this finds the destination queue using the IP-ADDRESS and PORT managed by the FAKE-SOCKETS-INTERFACE that created the sending SOCKET and adds the DATA to the incoming queue for that destination."
+ (let ((destination (get-socket-from-interface (socket-get-interface socket)
+ ip-address
+ port)))
+ (enqueue data (socket-incoming-queue destination))))
View
3  sockets/fake/socket.lisp
@@ -8,11 +8,10 @@
;;; of this directory.
(defpackage :unet-sockets-fake-socket
(:use :cl)
- (:documentation "This package defines the FAKE-SOCKET class. The FAKE-SOCKET class extends the UNET-SOCKETS:SOCKETS-BASE-SOCKET class. It is the type of SOCKETS-BASE-SOCKET returned by the SOCKETS-CREATE-DATAGRAM-SOCKET when called on the FAKE-SOCKETS-INTERFACE.")
(:import-from :jpl-queues
#:unbounded-fifo-queue)
(:import-from :unet-sockets
- #:sockets-base-socket)
+ #:base-socket)
(:import-from :unet-sockets-fake-interface
#:fake-sockets-interface)
(:export :fake-socket
View
24 sockets/interface.lisp
@@ -1,27 +1,9 @@
(defpackage :unet-sockets-interface
(:use :cl)
- (:export :sockets-interface
- :sockets-hostname-not-found-error
- :sockets-hostname-not-found-error-hostname
- :sockets-get-address
- :sockets-create-datagram-socket))
+ (:export :sockets-interface))
(in-package :unet-sockets-interface)
(defclass sockets-interface ()
- ())
-
-(define-condition sockets-hostname-not-found-error (error)
- ((hostname :initarg :hostname
- :reader sockets-hostname-not-found-error-hostname)))
-
-(defmethod print-object ((hnf sockets-hostname-not-found-error) stream)
- (with-accessors ((hostname sockets-hostname-not-found-error-hostname)) hnf
- (print-unreadable-object (hnf stream :type t)
- (format stream ":HOSTNAME ~S" hostname))))
-
-(defgeneric sockets-get-address (sockets-interface hostname)
- (:documentation "Using the SOCKETS-INTERFACE, resolve the HOSTNAME string into an IP address. This will throw a SOCKETS-HOSTNAME-NOT-FOUND-ERROR if the IP address of the given HOSTNAME cannot be determined."))
-
-(defgeneric sockets-create-datagram-socket (sockets-interface ip-address port)
- (:documentation "Create a SOCKETS-BASE-SOCKET instance bound to IP-ADDRESS and PORT. The IP-ADDRESS can be either the keyword IPADDR-ANY or an address as returned by SOCKET-GET-ADDRESS."))
+ ()
+ (:documentation "The SOCKETS-INTERFACE class serves as the base class for all implementations of this interface. This interface supports the methods GET-ADDRESS and CREATE-DATAGRAM-SOCKET."))
View
23 unet-sockets-fake.asd
@@ -14,6 +14,25 @@
((:module "fake"
:components ((:file "interface")
(:file "socket" :depends-on ("interface"))
- (:file "methods" :depends-on ("interface"
- "socket"))
+ (:file "make-hash-key")
+ (:file "get-socket-from-interface"
+ :depends-on ("interface"
+ "make-hash-key"))
+ (:file "add-socket-to-interface"
+ :depends-on ("interface"
+ "make-hash-key"
+ "get-socket-from-interface"))
+ (:file "get-address" :depends-on ("interface"))
+ (:file "create-datagram-socket"
+ :depends-on ("interface"
+ "socket"
+ "add-socket-to-interface"))
+ (:file "send-datagram"
+ :depends-on ("interface"
+ "socket"
+ "get-socket-from-interface"))
+ (:file "poll-datagram"
+ :depends-on ("interface"
+ "socket"
+ "get-socket-from-interface"))
(:file "api" :depends-on ("interface"))))))))
View
25 unet-sockets.asd
@@ -3,13 +3,26 @@
(asdf:defsystem :unet-sockets
:description
- "unet-sockets: socket interfacelayer used by unet"
+ "unet-sockets: socket interface layer used by unet"
:version "0.1.2012.10.02"
:author "Patrick Stein <pat@nklein.com>"
:licence "MIT"
:depends-on ("conduit-packages")
- :components ((:module "sockets"
- :components ((:file "interface")
- (:file "base-socket")
- (:file "api" :depends-on ("interface"
- "base-socket"))))))
+ :components (
+ (:module "sockets"
+ :components ((:file "interface")
+ (:file "base-socket")
+ (:file "hostname-not-found-error")
+ (:file "get-address")
+ (:file "address+port-not-available-error")
+ (:file "create-datagram-socket")
+ (:file "send-datagram")
+ (:file "poll-datagram")
+ (:file "api" :depends-on ("interface"
+ "base-socket"
+ "hostname-not-found-error"
+ "get-address"
+ "address+port-not-available-error"
+ "create-datagram-socket"
+ "send-datagram"
+ "poll-datagram"))))))
Please sign in to comment.
Something went wrong with that request. Please try again.