Pass REQUEST from MAYBE-READ-POST-PARAMETERS to RAW-POST-DATA, patch
[hunchentoot.git] / lispworks.lisp
blobe9b4ed699dba36a469a010edbf6dfa414bcda5fb
1 ;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: HUNCHENTOOT; Base: 10 -*-
2 ;;; $Header: /usr/local/cvsrep/hunchentoot/port-lw.lisp,v 1.14 2008/04/08 14:39:18 edi Exp $
4 ;;; Copyright (c) 2004-2009, Dr. Edmund Weitz. All rights reserved.
6 ;;; Redistribution and use in source and binary forms, with or without
7 ;;; modification, are permitted provided that the following conditions
8 ;;; are met:
10 ;;; * Redistributions of source code must retain the above copyright
11 ;;; notice, this list of conditions and the following disclaimer.
13 ;;; * Redistributions in binary form must reproduce the above
14 ;;; copyright notice, this list of conditions and the following
15 ;;; disclaimer in the documentation and/or other materials
16 ;;; provided with the distribution.
18 ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED
19 ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 (in-package :hunchentoot)
32 (eval-when (:compile-toplevel :load-toplevel :execute)
33 ;; make sure socket code is loaded
34 (require "comm"))
36 (defun get-env-variable-as-directory (name)
37 "Retrieves the environment variable named NAME and interprets it as
38 the pathname of a directory which is returned."
39 (lw:when-let (string (lw:environment-variable name))
40 (when (plusp (length string))
41 (cond ((find (char string (1- (length string))) "\\/" :test #'char=) string)
42 (t (lw:string-append string "/"))))))
44 (defmacro with-rebinding (bindings &body body)
45 "Renaming LW:REBINDING for better indentation."
46 `(lw:rebinding ,bindings ,@body))
48 #+(and :lispworks4.4 (or :win32 :linux))
49 (let ((id :system-cons-free-chain))
50 (unless (scm::patch-id-loaded-p id)
51 (error "You need a patch to improve the performance of this code. Request patch ~S for ~A for ~A from lisp-support@lispworks.com using the Report Bug command."
52 id (lisp-implementation-type)
53 #+:win32 "Windows"
54 #+:linux "Linux")))
56 (defvar *cleanup-interval* 100
57 "Should be NIL or a positive integer. The system calls
58 *CLEANUP-FUNCTION* whenever *CLEANUP-INTERVAL* new worker threads
59 \(counted globally across all acceptors) have been created unless the
60 value is NIL. The initial value is 100.
62 This variable is only available on LispWorks.")
64 (defvar *cleanup-function* 'cleanup-function
65 "A designator for a function without arguments which is called on a
66 regular basis if *CLEANUP-INTERVAL* is not NIL. The initial value is
67 the name of a function which invokes a garbage collection on 32-bit
68 versions of LispWorks.
70 This variable is only available on LispWorks.")
72 (defvar *worker-counter* 0
73 "Internal counter used to count worker threads. Needed for
74 *CLEANUP-FUNCTION*.")
76 (defun cleanup-function ()
77 "The default for *CLEANUP-FUNCTION*. Invokes a GC on 32-bit
78 LispWorks."
79 #-:lispworks-64bit
80 (hcl:mark-and-sweep 2))
82 (defun get-peer-address-and-port (socket)
83 "Returns the peer address and port of the socket SOCKET as two
84 values. The address is returned as a string in dotted IP address
85 notation."
86 (multiple-value-bind (peer-addr peer-port)
87 (comm:get-socket-peer-address socket)
88 (values (ignore-errors (comm:ip-address-string peer-addr)) peer-port)))
90 (defun make-socket-stream (socket acceptor)
91 "Returns a stream for the socket SOCKET. The ACCEPTOR argument is
92 used to set the timeouts."
93 #-(or :lispworks5 :lispworks6)
94 (when (acceptor-write-timeout acceptor)
95 (parameter-error "You need LispWorks 5 or higher for write timeouts."))
96 (make-instance 'comm:socket-stream
97 :socket socket
98 :direction :io
99 :read-timeout (acceptor-read-timeout acceptor)
100 #+(or :lispworks5 :lispworks6) #+(or :lispworks5 :lispworks6)
101 :write-timeout (acceptor-write-timeout acceptor)
102 :element-type 'octet))
104 (defun make-lock (name)
105 "Simple wrapper to allow LispWorks and Bordeaux Threads to coexist."
106 (mp:make-lock :name name))
108 (defmacro with-lock-held ((lock) &body body)
109 "Simple wrapper to allow LispWorks and Bordeaux Threads to coexist."
110 `(mp:with-lock (,lock) ,@body))
112 ;; some help for the IDE
113 (dspec:define-dspec-alias defvar-unbound (name)
114 `(defparameter ,name))
116 (dspec:define-dspec-alias def-http-return-code (name)
117 `(defconstant ,name))
119 (editor:setup-indent "defvar-unbound" 1 2 4)
121 (editor:setup-indent "def-http-return-code" 1 2 4)