disallow non-graphic characters in pathnames
[hunchentoot.git] / set-timeouts.lisp
blobe44ecf3c8da1733ae9a78ea86daf38af91c7a608
1 ;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: CL-USER; Base: 10 -*-
3 ;;; Copyright (c) 2004-2010, Dr. Edmund Weitz. All rights reserved.
5 ;;; Redistribution and use in source and binary forms, with or without
6 ;;; modification, are permitted provided that the following conditions
7 ;;; are met:
9 ;;; * Redistributions of source code must retain the above copyright
10 ;;; notice, this list of conditions and the following disclaimer.
12 ;;; * Redistributions in binary form must reproduce the above
13 ;;; copyright notice, this list of conditions and the following
14 ;;; disclaimer in the documentation and/or other materials
15 ;;; provided with the distribution.
17 ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED
18 ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
21 ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 (in-package :hunchentoot)
31 (defun set-timeouts (usocket read-timeout write-timeout)
32 "Sets up timeouts on the given USOCKET object. READ-TIMEOUT is the
33 read timeout period, WRITE-TIMEOUT is the write timeout, specified in
34 \(fractional) seconds. The timeouts can either be implemented using
35 the low-level socket options SO_RCVTIMEO and SO_SNDTIMEO or some
36 other, implementation specific mechanism. On platforms that do not
37 support separate read and write timeouts, both must be equal or an
38 error will be signaled. READ-TIMEOUT and WRITE-TIMEOUT may be NIL,
39 which means that the corresponding socket timeout value will not be
40 set."
41 (declare (ignorable usocket read-timeout write-timeout))
42 ;; add other Lisps here if necessary
43 #+(or :sbcl :cmu)
44 (unless (eql read-timeout write-timeout)
45 (parameter-error "Read and write timeouts for socket must be equal."))
46 #+:clisp
47 (when read-timeout
48 (socket:socket-options (usocket:socket usocket) :SO-RCVTIMEO read-timeout))
49 #+:clisp
50 (when write-timeout
51 (socket:socket-options (usocket:socket usocket) :SO-SNDTIMEO write-timeout))
52 #+:ecl
53 (when read-timeout
54 (print (list (usocket:socket usocket) read-timeout))
55 (setf (sb-bsd-sockets:sockopt-receive-timeout (usocket:socket usocket))
56 read-timeout))
57 #+:ecl
58 (when write-timeout
59 (print (list (usocket:socket usocket) write-timeout))
60 (setf (sb-bsd-sockets:sockopt-send-timeout (usocket:socket usocket))
61 write-timeout))
62 #+:openmcl
63 (when read-timeout
64 (setf (ccl:stream-input-timeout (usocket:socket usocket))
65 read-timeout))
66 #+:openmcl
67 (when write-timeout
68 (setf (ccl:stream-output-timeout (usocket:socket usocket))
69 write-timeout))
70 #+:sbcl
71 (when read-timeout
72 (setf (sb-impl::fd-stream-timeout (usocket:socket-stream usocket))
73 (coerce read-timeout 'single-float)))
74 #+:cmu
75 (setf (lisp::fd-stream-timeout (usocket:socket-stream usocket))
76 (coerce read-timeout 'integer))
77 #-(or :clisp :allegro :openmcl :sbcl :lispworks :cmu :ecl)
78 (not-implemented 'set-timeouts))