[nio-cvs] r27 - in branches/home/psmith/restructure: . patches src/buffer src/protocol/yarpc

psmith at common-lisp.net psmith at common-lisp.net
Sat Jan 6 04:42:01 UTC 2007


Author: psmith
Date: Fri Jan  5 23:42:00 2007
New Revision: 27

Added:
   branches/home/psmith/restructure/TODO
   branches/home/psmith/restructure/run-http.lisp
      - copied unchanged from r25, branches/home/psmith/restructure/run.lisp
   branches/home/psmith/restructure/run-yarpc.lisp
      - copied, changed from r25, branches/home/psmith/restructure/run.lisp
   branches/home/psmith/restructure/run.sh   (contents, props changed)
   branches/home/psmith/restructure/src/protocol/yarpc/
   branches/home/psmith/restructure/src/protocol/yarpc/nio-yarpc-package.lisp
   branches/home/psmith/restructure/src/protocol/yarpc/nio-yarpc.asd
   branches/home/psmith/restructure/src/protocol/yarpc/yarpc-state-machine.lisp
Removed:
   branches/home/psmith/restructure/run.lisp
Modified:
   branches/home/psmith/restructure/patches/cffi_0.9.2-mem_rw.diff
   branches/home/psmith/restructure/src/buffer/buffer.lisp
   branches/home/psmith/restructure/src/buffer/nio-buffer-package.lisp
Log:
Added first steps of YetAnotherRPC protocol

Added: branches/home/psmith/restructure/TODO
==============================================================================
--- (empty file)
+++ branches/home/psmith/restructure/TODO	Fri Jan  5 23:42:00 2007
@@ -0,0 +1,14 @@
+Do eagain queue
+
+Look into possibility of using chunga for chunked encoding on top of
+nio-buffer for http.
+
+Reinstate nio-httpd with new structure (dependency on above).
+
+Simple API: Consider buffered-state-machine layer which just buffers 
+everything and assumes we have enough memory, which will allow classic 
+coding style for people who dont need direct memory / low level control.
+
+Create UDP server
+
+Create RPC server / client

Modified: branches/home/psmith/restructure/patches/cffi_0.9.2-mem_rw.diff
==============================================================================
--- branches/home/psmith/restructure/patches/cffi_0.9.2-mem_rw.diff	(original)
+++ branches/home/psmith/restructure/patches/cffi_0.9.2-mem_rw.diff	Fri Jan  5 23:42:00 2007
@@ -18,7 +18,7 @@
 > (defun mem-write-vector (vector ptr type &optional (count (length vector)) (offset 0))
 >   (loop for i below count
 >       for off from offset by (%foreign-type-size type)
->             do (setf (%mem-ref ptr type off) (aref vector i))
+>             do (%mem-set (aref vector i) ptr type off)
 >                   finally (return i)))
 > 
 > 

Copied: branches/home/psmith/restructure/run-yarpc.lisp (from r25, branches/home/psmith/restructure/run.lisp)
==============================================================================
--- branches/home/psmith/restructure/run.lisp	(original)
+++ branches/home/psmith/restructure/run-yarpc.lisp	Fri Jan  5 23:42:00 2007
@@ -1,4 +1,4 @@
 (push :nio-debug *features*)
 (require :asdf)
-(require :nio-http)
-(nio:start-server 'identity 'identity 'nio-http:http-state-machine :host "127.0.0.1")
+(require :nio-yarpc)
+(nio:start-server 'identity 'identity 'nio-yarpc:yarpc-state-machine :host "127.0.0.1")

Added: branches/home/psmith/restructure/run.sh
==============================================================================
--- (empty file)
+++ branches/home/psmith/restructure/run.sh	Fri Jan  5 23:42:00 2007
@@ -0,0 +1,7 @@
+#!/bin/bash
+#
+# run.sh <http|yarpc>
+#
+
+export LANG=en_US.UTF-8
+sbcl --load run-$1.lisp

Modified: branches/home/psmith/restructure/src/buffer/buffer.lisp
==============================================================================
--- branches/home/psmith/restructure/src/buffer/buffer.lisp	(original)
+++ branches/home/psmith/restructure/src/buffer/buffer.lisp	Fri Jan  5 23:42:00 2007
@@ -129,9 +129,9 @@
     
 ;;TODO 
 ;;mem-write-vector (vector ptr type &optional (count (length vector)) (offset 0))
-(defmethod bytebuffer-write-string((byte-buffer byte-buffer) str &optional (index 0))
+(defmethod bytebuffer-write-string((byte-buffer byte-buffer) str &optional (index 0) (external-format :ascii))
   :documentation "Returns number of bytes written to bytebuffer"
-  (bytebuffer-write-vector byte-buffer (sb-ext:string-to-octets str :external-format :ascii)))
+  (bytebuffer-write-vector byte-buffer (sb-ext:string-to-octets str :external-format external-format)))
 
 ;;TODO rename
 (defmethod bytebuffer-write-vector((byte-buffer byte-buffer) vec &optional (index 0))

Modified: branches/home/psmith/restructure/src/buffer/nio-buffer-package.lisp
==============================================================================
--- branches/home/psmith/restructure/src/buffer/nio-buffer-package.lisp	(original)
+++ branches/home/psmith/restructure/src/buffer/nio-buffer-package.lisp	Fri Jan  5 23:42:00 2007
@@ -27,5 +27,5 @@
 (defpackage :nio-buffer (:use :cl :cffi)
 	    
 	    (:export
-	     byte-buffer free-buffer remaining inc-position get-string buffer-buf bytebuffer-write-vector flip map-to-foreign
+	     byte-buffer free-buffer remaining inc-position get-string buffer-buf bytebuffer-write-vector bytebuffer-write-string flip map-to-foreign
 	     ))

Added: branches/home/psmith/restructure/src/protocol/yarpc/nio-yarpc-package.lisp
==============================================================================
--- (empty file)
+++ branches/home/psmith/restructure/src/protocol/yarpc/nio-yarpc-package.lisp	Fri Jan  5 23:42:00 2007
@@ -0,0 +1,33 @@
+#|
+Copyright (c) 2007
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+3. The name of the author may not be used to endorse or promote products
+   derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+|#
+(defpackage :nio-yarpc (:use :cl :nio :nio-buffer)
+	    
+	    (:export
+
+	     ;; yarpc-state-machine
+	     yarpc-state-machine test-rpc
+	     ))

Added: branches/home/psmith/restructure/src/protocol/yarpc/nio-yarpc.asd
==============================================================================
--- (empty file)
+++ branches/home/psmith/restructure/src/protocol/yarpc/nio-yarpc.asd	Fri Jan  5 23:42:00 2007
@@ -0,0 +1,11 @@
+;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
+
+(in-package :asdf)
+
+(defsystem :nio-yarpc
+
+    :components ((:file "nio-yarpc-package")
+		 (:file "yarpc-state-machine" :depends-on ("nio-yarpc-package"))
+		 )
+
+    :depends-on (:nio))
\ No newline at end of file

Added: branches/home/psmith/restructure/src/protocol/yarpc/yarpc-state-machine.lisp
==============================================================================
--- (empty file)
+++ branches/home/psmith/restructure/src/protocol/yarpc/yarpc-state-machine.lisp	Fri Jan  5 23:42:00 2007
@@ -0,0 +1,63 @@
+#|
+Copyright (c) 2007
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+   notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+   notice, this list of conditions and the following disclaimer in the
+   documentation and/or other materials provided with the distribution.
+3. The name of the author may not be used to endorse or promote products
+   derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+|#
+(in-package :nio-yarpc)
+
+(declaim (optimize (debug 3) (speed 3) (space 0)))
+
+;; YetAnotherRPC state machine
+;;
+;; A server that processes remote procedure calls and returns results
+;;
+;; Test with: 
+;; > telnet 127.0.0.1 16323
+;; Trying 127.0.0.1...
+;; Connected to 127.0.0.1.
+;; Escape character is '^]'.
+;; (test-rpc "who" 2 's)
+;; response - who 2 'S ∑
+
+(defclass yarpc-state-machine (async-fd)())
+
+(defmethod print-object ((sm yarpc-state-machine) stream)
+  (format stream "#<YARPC-STATE-MACHINE ~A >" (call-next-method sm nil)))
+
+(defmethod process-read((sm yarpc-state-machine))
+  (with-slots (foreign-read-buffer foreign-write-buffer) sm
+    (let ((fn-result (execute-call (sb-ext:octets-to-string (get-string foreign-read-buffer) :external-format :ascii))))
+      (format t "process-read - function result: ~A~%" fn-result)
+      (nio-buffer:bytebuffer-write-string foreign-write-buffer fn-result 0 :utf-8)
+      (close-sm sm))))
+
+
+(defun execute-call (call-string)
+  (let* ((*package* (find-package :nio-yarpc))
+         (rpc-call-list (read-from-string call-string )))
+    (apply (first rpc-call-list) (rest rpc-call-list))))
+
+
+(defun test-rpc(a b c)
+  (format nil "response - ~A ~A ~A ~A~%" a b c (code-char #x2211)))



More information about the Nio-cvs mailing list