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
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
41 (declare (ignorable usocket read-timeout write-timeout
))
42 ;; add other Lisps here if necessary
43 #+(or :sbcl
:cmu
:abcl
)
44 (unless (eql read-timeout write-timeout
)
45 (parameter-error "Read and write timeouts for socket must be equal."))
48 (socket:socket-options
(usocket:socket usocket
) :SO-RCVTIMEO read-timeout
))
51 (socket:socket-options
(usocket:socket usocket
) :SO-SNDTIMEO write-timeout
))
54 (setf (sb-bsd-sockets:sockopt-receive-timeout
(usocket:socket usocket
))
58 (setf (sb-bsd-sockets:sockopt-send-timeout
(usocket:socket usocket
))
62 (setf (ccl:stream-input-timeout
(usocket:socket usocket
))
66 (setf (ccl:stream-output-timeout
(usocket:socket usocket
))
70 (setf (sb-impl::fd-stream-timeout
(usocket:socket-stream usocket
))
71 (coerce read-timeout
'single-float
)))
73 (setf (lisp::fd-stream-timeout
(usocket:socket-stream usocket
))
74 (coerce read-timeout
'integer
))
77 (java:jcall
(java:jmethod
"java.net.Socket" "setSoTimeout" "int")
78 (usocket:socket usocket
)
79 (* 1000 read-timeout
)))
82 (warn "Unimplemented."))
83 #-
(or :clisp
:allegro
:openmcl
:sbcl
:lispworks
:cmu
:ecl
:abcl
)
84 (not-implemented 'set-timeouts
))