- Timestamp:
- 01/12/07 06:44:39 (18 years ago)
- Location:
- branches/home/psmith/restructure
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified branches/home/psmith/restructure/run-yarpc.lisp ¶
r27 r33 2 2 (require :asdf) 3 3 (require :nio-yarpc) 4 4 5 (nio:start-server 'identity 'identity 'nio-yarpc:yarpc-state-machine :host "127.0.0.1") -
TabularUnified branches/home/psmith/restructure/src/buffer/buffer.lisp ¶
r28 r33 119 119 byte-buffer)) 120 120 121 ;reads bytes from byte-buffer and returns a vector (unsigned-byte 8) 122 (defmethod bytebuffer-read-vector((bb byte-buffer) &optional (num-bytes-to-read (remaining bb))) 123 (let ((vec (make-uint8-seq num-bytes-to-read))) 124 (with-slots (buf) bb 125 (inc-position bb (cffi:mem-read-vector vec (buffer-buf bb) :unsigned-char num-bytes-to-read))) 126 vec)) 121 127 122 (defmethod get-string((byte-buffer byte-buffer)) 123 (flip byte-buffer) 124 (with-slots (position limit buf) byte-buffer 125 (let ((tmp (make-uint8-seq (remaining byte-buffer)))) 126 (inc-position byte-buffer (cffi:mem-read-vector tmp buf :unsigned-char limit)) 127 (format t " read: ~A~%" (sb-ext:octets-to-string tmp :external-format :ascii)) 128 tmp))) 129 130 ;;TODO 131 ;;mem-write-vector (vector ptr type &optional (count (length vector)) (offset 0)) 132 (defmethod bytebuffer-write-string((byte-buffer byte-buffer) str &optional (index 0) (external-format :ascii)) 128 ; Read bytes from bytebuffer abd return a string using the supplied decoding 129 ;TODO move octets-to-string into nio-compat 130 (defmethod bytebuffer-read-string((bb byte-buffer) &optional (num-bytes-to-read (remaining bb)) (external-format :ascii)) 131 (sb-ext:octets-to-string (bytebuffer-read-vector bb num-bytes-to-read) :external-format external-format)) 132 133 134 ;; Write bytes from vector vec to bytebuffer 135 (defmethod bytebuffer-write-vector((bb byte-buffer) vec) 133 136 :documentation "Returns number of bytes written to bytebuffer" 134 (bytebuffer-write-vector byte-buffer (sb-ext:string-to-octets str :external-format external-format))) 135 136 ;;TODO rename 137 (defmethod bytebuffer-write-vector((byte-buffer byte-buffer) vec &optional (index 0)) 138 :documentation "Returns number of bytes written to bytebuffer" 139 (if (> (remaining byte-buffer) 0) 137 (if (> (remaining bb) 0) 140 138 0 141 139 (progn 142 (clear b yte-buffer)143 (let ((bytes-written (cffi:mem-write-vector vec (buffer-buf b yte-buffer) :unsigned-char)))140 (clear bb) 141 (let ((bytes-written (cffi:mem-write-vector vec (buffer-buf bb) :unsigned-char))) 144 142 (format t "bytebuffer-write-vector - byteswritten: ~A" bytes-written) 145 (inc-position b yte-bufferbytes-written)143 (inc-position bb bytes-written) 146 144 bytes-written)))) 145 146 ;; Writes data from string str to bytebuffer using specified encoding 147 ;TODO move string-to-octets into nio-compat 148 (defmethod bytebuffer-write-string((bb byte-buffer) str &optional (external-format :ascii)) 149 :documentation "Returns number of bytes written to bytebuffer" 150 (bytebuffer-write-vector bb (sb-ext:string-to-octets str :external-format external-format))) 147 151 148 152 … … 169 173 (format t "Remaining ~A~%" (remaining mybuf)) 170 174 171 (format t "mybuf string ~A~%" ( get-string mybuf))175 (format t "mybuf string ~A~%" (bytebuffer-read-string mybuf)) 172 176 173 177 (format t "Mybuf (after get-string): ~A~%" mybuf) -
TabularUnified branches/home/psmith/restructure/src/buffer/nio-buffer-package.lisp ¶
r28 r33 28 28 29 29 (:export 30 byte-buffer free-buffer remaining inc-position get-string buffer-buf bytebuffer-write-vector bytebuffer-write-string flip30 byte-buffer free-buffer remaining inc-position get-string buffer-buf bytebuffer-write-vector bytebuffer-write-string bytebuffer-read-vector bytebuffer-read-string flip 31 31 )) -
TabularUnified branches/home/psmith/restructure/src/protocol/yarpc/nio-yarpc-package.lisp ¶
r31 r33 25 25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 26 |# 27 (defpackage :nio-yarpc (:use :cl :nio :nio- buffer)27 (defpackage :nio-yarpc (:use :cl :nio :nio-sm :nio-buffer) 28 28 29 29 (:export 30 30 31 31 ;; yarpc-state-machine 32 yarpc-state-machine test-rpc test-rpc-list test-rpc-string32 yarpc-state-machine yarpc-state-machine-factory test-rpc test-rpc-list test-rpc-string get-packet-factory 33 33 )) -
TabularUnified branches/home/psmith/restructure/src/protocol/yarpc/nio-yarpc.asd ¶
r27 r33 6 6 7 7 :components ((:file "nio-yarpc-package") 8 (:file "yarpc-state-machine" :depends-on ("nio-yarpc-package")) 8 (:file "yarpc-packet-factory" :depends-on ("nio-yarpc-package")) 9 (:file "yarpc-state-machine" :depends-on ("yarpc-packet-factory")) 9 10 ) 10 11 11 :depends-on (:nio ))12 :depends-on (:nio :nio-sm)) -
TabularUnified branches/home/psmith/restructure/src/protocol/yarpc/yarpc-state-machine.lisp ¶
r31 r33 41 41 ;; response - who 2 'S 42 42 ;; 43 (defclass yarpc-state-machine ( async-fd)())43 (defclass yarpc-state-machine (state-machine)()) 44 44 45 (defun yarpc-state-machine () 46 (make-instance 'yarpc-state-machine)) 47 48 (defparameter yarpc-pf (yarpc-packet-factory)) 49 50 (defmethod get-packet-factory((sm yarpc-state-machine)) 51 yarpc-pf) 45 52 46 53 ;;TODO move somewhere suitable … … 75 82 (format stream "#<YARPC-STATE-MACHINE ~A >" (call-next-method sm nil))) 76 83 77 (defmethod process-read((sm yarpc-state-machine)) 78 (with-slots (foreign-read-buffer foreign-write-buffer) sm 79 (let ((fn-result (execute-call (sb-ext:octets-to-string (get-string foreign-read-buffer) :external-format :ascii)))) 80 (format t "process-read - function result: ~A~%" fn-result) 81 (nio-buffer:bytebuffer-write-string foreign-write-buffer (write-to-string fn-result) 0 :utf-8) 82 (close-sm sm)))) 84 (defconstant STATE-INITIALISED 0) 85 (defconstant STATE-SEND-RESPONSE 1) 83 86 87 (defparameter state STATE-INITIALISED) 84 88 85 89 (define-condition authorization-error (error) ()) 86 90 91 ;Process a call method packet, returns 92 (defmethod process-packet ((sm yarpc-state-machine) (call call-method-packet)) 93 ;todo change state, create method-response packet and return it 94 ;(assert (eql state 0)) 95 (handler-case 96 (let ((result (execute-call (get-call-string call)))) 97 (when result 98 (let ((response-packet (progn 99 (setf state STATE-SEND-RESPONSE) 100 (method-response-packet result)))) 101 (values response-packet t)))) 102 (reader-error (re) (format t "No such function ~A~%" (get-call-string call))) 103 (authorization-error (ae) (format t "Function not declared with defremote ~A~%" (get-call-string call))))) 104 105 87 106 (defun execute-call (call-string) 88 (handler-case89 107 (let* ((rpc-call-list (read-from-string call-string )) 90 108 (fn (member (symbol-function (first rpc-call-list)) *remote-fns* ))) … … 92 110 (if fn 93 111 (apply (first rpc-call-list) (rest rpc-call-list)) 94 (error 'authorization-error))) 95 (reader-error (re) (format t "No such function ~A~%" call-string)))) 112 (error 'authorization-error)))) 96 113 -
TabularUnified branches/home/psmith/restructure/src/statemachine/nio-sm-package.lisp ¶
r32 r33 30 30 31 31 ;; state-machine 32 state-machine 32 state-machine packet-factory get-packet-factory get-packet 33 33 )) -
TabularUnified branches/home/psmith/restructure/src/statemachine/state-machine.lisp ¶
r32 r33 43 43 (format stream "#<STATE-MACHINE ~A >" (call-next-method sm nil))) 44 44 45 (defgeneric process-packet(state-machine packet)) 46 47 (defgeneric get-packet-factory(state-machine)) 48 45 49 (defmethod process-read((sm state-machine)) 46 50 (with-slots (foreign-read-buffer foreign-write-buffer) sm 47 (let ((fn-result (execute-call (sb-ext:octets-to-string (get-string foreign-read-buffer) :external-format :ascii)))) 48 (format t "process-read - function result: ~A~%" fn-result) 49 (nio-buffer:bytebuffer-write-string foreign-write-buffer (write-to-string fn-result) 0 :utf-8) 50 (close-sm sm)))) 51 (let ((incomming-packet (get-packet (get-packet-factory sm) foreign-read-buffer))) 52 (format t "state-machine::process-read - incomming packet: ~A~%" incomming-packet) 53 (when incomming-packet 54 (multiple-value-bind (ret-packet close) (process-packet sm incomming-packet) 55 (format t "state-machine::process-read - return packet: ~A~%" ret-packet) 56 (when ret-packet (put-packet ret-packet foreign-write-buffer)) 57 (if close 58 (close-sm sm) 59 )))))) 51 60 52 61 62 63 (defclass packet-factory () 64 ()) 65 66 ; Get the packet in buf using the packet factory 67 (defgeneric get-packet (packet-factory buf)) 68 69 ; Write the packet to the buffer 70 (defun put-packet (packet buf) 71 (nio-buffer:bytebuffer-write-vector buf (get-bytes packet)))
Note: See TracChangeset
for help on using the changeset viewer.