From b3b91e38a168f6fab0a374133e734be7b2d58e99 Mon Sep 17 00:00:00 2001 From: "Pierre R. Mai" Date: Sat, 22 Jul 2000 01:06:44 +0000 Subject: [PATCH] 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... --- src/main/buffer.cl | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/main/buffer.cl diff --git a/src/main/buffer.cl b/src/main/buffer.cl new file mode 100644 index 0000000..475b76f --- /dev/null +++ b/src/main/buffer.cl @@ -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))))