[nio-cvs] r68 - in branches/home/psmith/restructure/src: buffer io statemachine
psmith at common-lisp.net
psmith at common-lisp.net
Sun Feb 4 23:04:14 UTC 2007
Author: psmith
Date: Sun Feb 4 18:04:14 2007
New Revision: 68
Modified:
branches/home/psmith/restructure/src/buffer/buffer.lisp
branches/home/psmith/restructure/src/buffer/nio-buffer-package.lisp
branches/home/psmith/restructure/src/io/async-fd.lisp
branches/home/psmith/restructure/src/statemachine/state-machine.lisp
Log:
large packet server side OK.
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 Sun Feb 4 18:04:14 2007
@@ -107,6 +107,10 @@
(defun byte-buffer (capacity)
(make-instance 'byte-buffer :capacity capacity :limit capacity :position 0 :buf (cffi:foreign-alloc :uint8 :count capacity)))
+;Gets a pointer to the address in the native memory of the position index
+(defmethod buffer-pointer ((bb byte-buffer))
+ (cffi:make-pointer (+ (cffi:pointer-address (buffer-buf bb)) (buffer-position bb))))
+
(defmethod print-object ((byte-buffer byte-buffer) stream)
(with-slots (capacity position limit buf) byte-buffer
(format stream "<byte-buffer :capacity ~A :position ~A :limit ~A :buf ~%~A>~%" capacity position limit (if buf (pretty-hex-dump (cffi:pointer-address buf) limit) nil))))
@@ -176,7 +180,8 @@
;Used to signal either an attempt has been made to write data to a buffer that is too small using a write (overflow)
; or an incomming packet doesn't have enough room to fit
(define-condition buffer-too-small-error (error)
- ((recommended-size :initarg :recommended-size)))
+ ((recommended-size :initarg :recommended-size
+ :accessor recommended-size)))
(defun buffer-too-small-error(recommended-size)
(make-instance 'buffer-too-small-error :recommended-size recommended-size))
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 Sun Feb 4 18:04:14 2007
@@ -32,5 +32,5 @@
bytebuffer-read-vector bytebuffer-read-string
bytebuffer-read-8 bytebuffer-read-32 bytebuffer-write-8 bytebuffer-write-32 bytebuffer-insert-8 bytebuffer-insert-32
flip unflip clear buffer-position copy-buffer buffer-capacity compact mark reset
- buffer-too-small-error
+ buffer-too-small-error recommended-size buffer-pointer
))
Modified: branches/home/psmith/restructure/src/io/async-fd.lisp
==============================================================================
--- branches/home/psmith/restructure/src/io/async-fd.lisp (original)
+++ branches/home/psmith/restructure/src/io/async-fd.lisp Sun Feb 4 18:04:14 2007
@@ -84,7 +84,7 @@
(with-slots (foreign-read-buffer read-fd) state-machine
#+nio-debug (format t "read-more called with ~A~%" state-machine)
#+nio-debug (format t "read-more - calling read() into ~A~%" foreign-read-buffer)
- (let ((new-bytes (%read read-fd (buffer-buf foreign-read-buffer) (remaining foreign-read-buffer))))
+ (let ((new-bytes (%read read-fd (buffer-pointer foreign-read-buffer) (remaining foreign-read-buffer))))
#+nio-debug (format t "read-more : Read ~A bytes into ~A~%" new-bytes foreign-read-buffer)
(cond
((< new-bytes 0)
Modified: branches/home/psmith/restructure/src/statemachine/state-machine.lisp
==============================================================================
--- branches/home/psmith/restructure/src/statemachine/state-machine.lisp (original)
+++ branches/home/psmith/restructure/src/statemachine/state-machine.lisp Sun Feb 4 18:04:14 2007
@@ -56,7 +56,13 @@
;Use the packet factory to obtain any valid packet and pass it through
(defmethod process-read((sm state-machine))
(with-slots (foreign-read-buffer) sm
- (let ((incoming-packet (get-packet (get-packet-factory sm) foreign-read-buffer)))
+ (let ((incoming-packet
+ (handler-case
+ (get-packet (get-packet-factory sm) foreign-read-buffer)
+ (buffer-too-small-error (read-err)
+ (if (recommend-buffer-size sm :read (recommended-size read-err))
+ (format-log t "resized incomming buffer ~A~%"foreign-read-buffer)
+ (error 'not-implemented-yet-read-resize-failure))))))
(format-log t "state-machine::process-read - incoming packet: ~A~%" incoming-packet)
(when incoming-packet
(when (not (process-incoming-packet sm incoming-packet))
More information about the Nio-cvs
mailing list