Changes that bring CLASH up to extended HTTP/1.0 support:
Added naive buffering functionality for use in CLASH. This is currently only used to implement stream entities, but might have other uses. Given the exitence of generational garbage collectors, it might be advantageous to forego the pooling scheme and throw away buffers after each use. This will depend on implementations and usage patterns, though, so we should make this tunable...
This commit is contained in:
52
src/main/buffer.cl
Normal file
52
src/main/buffer.cl
Normal file
@ -0,0 +1,52 @@
|
||||
;;;; CLASH --- The Common Lisp Adaptable Simple HTTP server
|
||||
;;;; This is copyrighted software. See documentation for terms.
|
||||
;;;;
|
||||
;;;; buffer.cl --- Efficient I/O and buffer handling
|
||||
;;;;
|
||||
;;;; Checkout Tag: $Name$
|
||||
;;;; $Id$
|
||||
|
||||
(in-package :CLASH)
|
||||
|
||||
;;;; %File Description:
|
||||
;;;;
|
||||
;;;;
|
||||
;;;;
|
||||
|
||||
(defvar *default-io-buffer-size* 4096
|
||||
"Default size of newly created I/O buffers. This can be tuned to
|
||||
server needs.")
|
||||
|
||||
(defvar *io-buffers* nil
|
||||
"List of available I/O Buffers.")
|
||||
|
||||
(defun make-new-buffer ()
|
||||
"Create a new I/O buffer for use by get-io-buffer."
|
||||
(make-string *default-io-buffer-size*))
|
||||
|
||||
(defun get-io-buffer ()
|
||||
"Get an available I/O buffer. This should be released after use
|
||||
with `release-io-buffer', to enable it to be recycled. Otherwise it
|
||||
will just be GC'ed as usual."
|
||||
(or
|
||||
#+(and :CMU :MP)
|
||||
(mp:atomic-pop *io-buffers*)
|
||||
#-(and :CMU :MP)
|
||||
(pop *io-buffers*)
|
||||
|
||||
;; No ready-made buffer, so we create a new one
|
||||
(make-new-buffer)))
|
||||
|
||||
(defun release-io-buffer (buffer)
|
||||
"Return a buffer allocated by `get-io-buffer' to the buffer pool for
|
||||
re-use."
|
||||
#+(and :CMU :MP)
|
||||
(mp:atomic-push buffer *io-buffers*)
|
||||
#-(and :CMU :MP)
|
||||
(push buffer *io-buffers*)
|
||||
t)
|
||||
|
||||
(defmacro with-io-buffer ((var) &body body)
|
||||
`(let ((,var (get-io-buffer)))
|
||||
(unwind-protect (progn ,@body)
|
||||
(release-io-buffer ,var))))
|
||||
Reference in New Issue
Block a user