Permalink
Browse files

more complete interface for vector streams; decode-struct macro

1 parent 1d363cd commit fea0ec5547d8315c9ee3942bf114cdd799347840 @lisp committed Sep 10, 2010
Showing with 40 additions and 2 deletions.
  1. +3 −0 definition-operators.lisp
  2. +0 −1 server.lisp
  3. +37 −1 vector-protocol.lisp
@@ -321,6 +321,9 @@
(unknown-field ,prot name id read-field-type value)))))
(stream-read-field-end ,prot))))))
+(defmacro decode-struct (prot class field-definitions extra-plist)
+ (generate-struct-decoder prot class field-definitions extra-plist))
+
(defmacro def-request-method (name (parameter-list return-type) &rest options)
"Generate a request function definition.
View
@@ -175,7 +175,6 @@
(return-from :process-loop))))
(loop (unless (open-stream-p input-transport) (return))
(process service protocol))))
- (print (list :closing connection (usocket:socket-stream connection)))
(close input-transport)
(close output-transport)))
;; listening socket closed
View
@@ -138,7 +138,7 @@
;;;
;;; input
-(defmethod stream-read-byte ((stream vector-stream-transport))
+(defmethod stream-read-byte ((stream vector-input-stream))
(with-slots (position vector) stream
(when (< position (length vector))
(let ((byte (aref vector position)))
@@ -147,6 +147,26 @@
(- (logxor 255 (1- byte)))
byte)))))
+(defmethod stream-read-unsigned-byte ((stream vector-input-stream))
+ (with-slots (position vector) stream
+ (when (< position (length vector))
+ (let ((byte (aref vector position)))
+ (incf position)
+ byte))))
+
+#+ccl
+(defmethod ccl:stream-tyi ((stream vector-input-stream))
+ (stream-read-byte stream))
+
+(defmethod stream-reader ((stream vector-input-stream))
+ (values #'(lambda (stream)
+ (with-slots (position vector) stream
+ (when (< position (length vector))
+ (let ((byte (aref vector position)))
+ (incf position)
+ byte))))
+ stream))
+
(defmethod stream-read-sequence ((stream vector-input-stream) (sequence vector)
#+mcl &key #-mcl &optional (start 0) (end nil))
@@ -178,6 +198,22 @@
(setf position next)))
+#+ccl
+(defmethod ccl:stream-tyo ((stream vector-output-stream) byte)
+ (stream-write-byte stream byte))
+
+(defmethod stream-writer ((stream vector-output-stream))
+ (values #'(lambda (stream byte &aux next)
+ (with-slots (position vector) stream
+ (unless (< (setf next (1+ position)) (length vector))
+ (setf vector
+ (adjust-array vector (+ next (floor (/ next 4)))
+ :element-type *binary-transport-element-type*)))
+ (setf (aref vector position)
+ (logand #xff byte))
+ (setf position next)))
+ stream))
+
(defmethod stream-write-sequence ((stream vector-output-stream) (sequence vector)
#+mcl &key #-mcl &optional (start 0) (end nil))
(unless end (setf end (length sequence)))

0 comments on commit fea0ec5

Please sign in to comment.