Author: psmith Date: Sun Jan 28 23:27:18 2007 New Revision: 56
Modified: branches/home/psmith/restructure/src/buffer/buffer.lisp branches/home/psmith/restructure/src/buffer/nio-buffer-package.lisp branches/home/psmith/restructure/src/protocol/yarpc/yarpc-packet-factory.lisp Log: fixed no compact problem
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 Jan 28 23:27:18 2007 @@ -151,6 +151,13 @@ (setf position 0) byte-buffer))
+(defmethod compact((byte-buffer byte-buffer)) + :documentation "copy remaining bytes to the beginning of this buffer and set position to number of bytes copied (ready for a new put" + (with-slots (buf position limit) byte-buffer + (let ((remaining (remaining byte-buffer))) + (%memcpy buf (cffi:make-pointer (+ (cffi:pointer-address buf) position)) remaining) + (setf position remaining)))) + ;reads bytes from byte-buffer and returns a vector (unsigned-byte 8) (defmethod bytebuffer-read-vector((bb byte-buffer) &optional (num-bytes-to-read (remaining bb))) (let ((vec (make-uint8-seq num-bytes-to-read))) @@ -281,7 +288,14 @@ (assert (eql (bytebuffer-read-32 mybuf) 2147483649)) (format t "Mybuf (after r/w 32bit): ~A~%" mybuf)
+ (setf (buffer-position mybuf) 11)
+ (compact mybuf) + (format t "Mybuf (after compact): ~A~%" mybuf) + (assert (eql (buffer-position mybuf) (- 32 11))) + (flip mybuf) + (format t "Mybuf (flip): ~A~%" mybuf) + (assert (eql (bytebuffer-read-32 mybuf) 2147483649))
(free-buffer mybuf) (format t "Mybuf after free: ~A~%" mybuf)))
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 Jan 28 23:27:18 2007 @@ -31,5 +31,5 @@ bytebuffer-write-vector bytebuffer-write-string 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 + flip unflip clear buffer-position copy-buffer buffer-capacity compact ))
Modified: branches/home/psmith/restructure/src/protocol/yarpc/yarpc-packet-factory.lisp ============================================================================== --- branches/home/psmith/restructure/src/protocol/yarpc/yarpc-packet-factory.lisp (original) +++ branches/home/psmith/restructure/src/protocol/yarpc/yarpc-packet-factory.lisp Sun Jan 28 23:27:18 2007 @@ -50,11 +50,15 @@ (let ((packet-id (bytebuffer-read-8 buf)) (packet-length (bytebuffer-read-32 buf))) (if (<= (- packet-length +yarpc-packet-header-size+) (remaining buf)) ;is the whole packet available in the buffer? - (ecase packet-id - (0 (progn (format-log t "yarpc-packet-factory:get-packet - got CALL-METHOD-PACKET-ID~%") (call-method-packet (bytebuffer-read-string buf (- packet-length +yarpc-packet-header-size+))))) - (1 (progn (format-log t "yarpc-packet-factory:get-packet - got METHOD-RESPONSE-PACKET-ID~%") (method-response-packet (bytebuffer-read-string buf (- packet-length +yarpc-packet-header-size+)))))) - (let ((buffer-capacity (buffer-capacity buf))) + (let ((ret-packet (ecase packet-id + (0 (progn (format-log t "yarpc-packet-factory:get-packet - got CALL-METHOD-PACKET-ID~%") (call-method-packet (bytebuffer-read-string buf (- packet-length +yarpc-packet-header-size+))))) + (1 (progn (format-log t "yarpc-packet-factory:get-packet - got METHOD-RESPONSE-PACKET-ID~%") (method-response-packet (bytebuffer-read-string buf (- packet-length +yarpc-packet-header-size+)))))))) + (compact buf) + #+nio-debug (format-log t "yarpc-packet-factory:get-packet - after compact ~%~A~%" buf) + #+nio-debug (format-log t "yarpc-packet-factory:get-packet - retuirning packet ~A~%" ret-packet) + ret-packet) ;Failed to read a whole packet unflip and check size + (let ((buffer-capacity (buffer-capacity buf))) (unflip buf) (if (> packet-length buffer-capacity) (error 'buffer-too-small-error :recommended-size packet-length)))))))