Changeset 8644 in project


Ignore:
Timestamp:
02/23/08 06:08:12 (12 years ago)
Author:
Jim Ursetto
Message:

spiffy: repair insidious fd leak in send-static-file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/3/spiffy/trunk/spiffy-base.scm

    r7864 r8644  
    201201    (if buffer
    202202        (let ([size (##sys#size buffer)])
    203           (set-header! (sprintf "Content-length: ~A" size))
     203          (set-header! (sprintf "Content-Length: ~A" size))
    204204          (write-response-header)
    205205          (unless (eq? 'HEAD (http:request-method (current-request)))
    206206            (display buffer) ) )
    207207        (let ([size (file-size fn)])
    208           (set-header! (sprintf "Content-length: ~A" (car (string-split (number->string size) ".")))) ;; yuck!
     208          (set-header! (sprintf "Content-Length: ~A" (car (string-split (number->string size) ".")))) ;; yuck!
    209209          (write-response-header)
    210210          (unless (eq? 'HEAD (http:request-method (current-request)))
    211             (let ([fd (file-open fn (+ open/binary open/rdonly))]
    212                   [rbs (spiffy-read-block-size)] )
    213               (spiffy-debug "(root) reading ~A with size ~A" fn size)
    214               (if (< size rbs)
    215                   (let ((buf (car (file-read fd size))))
    216                     (cache-write fn buf)
    217                     (display buf))
    218                   (sendfile fd (current-output-port)))
     211            (let ([fd (file-open fn (+ open/binary open/rdonly))])
     212              (handle-exceptions exn (begin
     213                                       (file-close fd)
     214                                       (signal exn))
     215                (let ([rbs (spiffy-read-block-size)])
     216                  (spiffy-debug "(root) reading ~A with size ~A" fn size)
     217                  (if (< size rbs)
     218                      (let ((buf (car (file-read fd size))))
     219                        (cache-write fn buf)
     220                        (display buf))
     221                      (sendfile fd (current-output-port)))))
    219222              (file-close fd)))))))
    220223
     
    292295               (unknown-handler (lambda _
    293296                                  (let ((ct (file-ext->mime-type ext)))
    294                                     (set-header! (sprintf "Content-type: ~a" ct))
     297                                    (set-header! (sprintf "Content-Type: ~a" ct))
    295298                                    ((content-transporter ct) ct path)))))
    296299          (parameterize ((current-pathinfo rest)
     
    388391      (if (null? fragments)
    389392          (begin
    390             (set-header! (sprintf "Content-length: ~A" pos))
     393            (set-header! (sprintf "Content-Length: ~A" pos))
    391394            (write-response-header)
    392395            (write-string dest pos) )
Note: See TracChangeset for help on using the changeset viewer.