From ehuelsmann at common-lisp.net Thu Jun 8 19:43:24 2006 From: ehuelsmann at common-lisp.net (ehuelsmann at common-lisp.net) Date: Thu, 8 Jun 2006 15:43:24 -0400 (EDT) Subject: [usocket-cvs] r116 - usocket/trunk Message-ID: <20060608194324.286D83D005@common-lisp.net> Author: ehuelsmann Date: Thu Jun 8 15:43:23 2006 New Revision: 116 Modified: usocket/trunk/condition.lisp usocket/trunk/usocket.lisp Log: Trivial-sockets compat addition (as far as possible at this stage) Also formatting tweaks and comment removal. Modified: usocket/trunk/condition.lisp ============================================================================== --- usocket/trunk/condition.lisp (original) +++ usocket/trunk/condition.lisp Thu Jun 8 15:43:23 2006 @@ -5,6 +5,13 @@ (in-package :usocket) +;; Condition raised by operations with unsupported arguments +;; For trivial-sockets compatibility. + +(define-condition unsupported (error) + ((feature :initarg :feature :reader unsupported-feature))) + + ;; Conditions raised by sockets operations (define-condition socket-condition (condition) Modified: usocket/trunk/usocket.lisp ============================================================================== --- usocket/trunk/usocket.lisp (original) +++ usocket/trunk/usocket.lisp Thu Jun 8 15:43:23 2006 @@ -10,23 +10,38 @@ (defclass usocket () ((socket :initarg :socket - :accessor socket) + :accessor socket + :documentation "Implementation specific socket object instance.") (stream :initarg :stream - :accessor socket-stream) -;; (local-address ;; possibly need to eliminate -;; :initarg :local-address -;; :accessor local-address) -;; (local-port ;; possibly need to eliminate -;; :initarg :local-port -;; :accessor local-port) - )) + :accessor socket-stream + :documentation "Implementation specific socket stream instance."))) (defun make-socket (&key socket stream) + "Create a usocket socket type from implementation specific socket +and stream objects." (make-instance 'usocket :socket socket :stream stream)) +(defun open-stream (peer-host peer-port + &key (local-host :any) + (local-port 0) + (external-format :default) + (element-type 'character) + (protocol :tcp)) + (unless (and (eql local-host :any) (eql local-port 0)) + (error 'unsupported :feature :bind)) + (unless (eql protocol :tcp) + (error 'unsupported :feature `(:protocol ,protocol))) + (unless (eql external-format :default) + (error 'unsupported :feature :external-format)) + (unless (eql element-type 'character) + (error 'unsupported :feature :element-type)) + (let ((sock (socket-connect peer-host peer-port))) + (when sock + (socket-stream sock)))) + (defgeneric socket-close (usocket) (:documentation "Close a previously opened `usocket'.")) @@ -103,8 +118,8 @@ (defgeneric host-byte-order (address)) (defmethod host-byte-order ((string string)) - "Convert a string, such as 192.168.1.1, to host-byte-order, such as -3232235777." + "Convert a string, such as 192.168.1.1, to host-byte-order, +such as 3232235777." (let ((list (list-of-strings-to-integers (split-sequence:split-sequence #\. string)))) (+ (* (first list) 256 256 256) (* (second list) 256 256) (* (third list) 256) (fourth list)))) @@ -163,6 +178,11 @@ ;; Setting of documentation for backend defined functions ;; +;; Documentation for the function +;; +;; (defun SOCKET-CONNECT (host port) ..) +;; + (setf (documentation 'socket-connect 'function) "Connect to `host' on `port'. `host' is assumed to be a string of an IP address represented in vector notation, such as #(192 168 1 1). From ehuelsmann at common-lisp.net Thu Jun 8 21:35:51 2006 From: ehuelsmann at common-lisp.net (ehuelsmann at common-lisp.net) Date: Thu, 8 Jun 2006 17:35:51 -0400 (EDT) Subject: [usocket-cvs] r117 - usocket/trunk Message-ID: <20060608213551.C0C6D17034@common-lisp.net> Author: ehuelsmann Date: Thu Jun 8 17:35:51 2006 New Revision: 117 Modified: usocket/trunk/usocket.lisp Log: Add documentation. Modified: usocket/trunk/usocket.lisp ============================================================================== --- usocket/trunk/usocket.lisp (original) +++ usocket/trunk/usocket.lisp Thu Jun 8 17:35:51 2006 @@ -30,6 +30,8 @@ (external-format :default) (element-type 'character) (protocol :tcp)) + "trivial-sockets compat function to make usocket a drop-in replacement +apart from the package naming difference." (unless (and (eql local-host :any) (eql local-port 0)) (error 'unsupported :feature :bind)) (unless (eql protocol :tcp)