(define (fcgi-handler-responder socket req content-length) ; this does the fcgi dance involving multiplexing the stdin, stdout and stderr ; streams over the socket. We have to make that the socket doesn't deadlock. ; Deadlock will occur if we let the FCGI script fill up all the buffers and we ; neglect to read anything before sending data. (define (in-out-dance #!optional (data #f)) (printf "\nDancing.\n") (let ((messages (if data (read/write-socket socket 1 fcgi-stdin data) (read/write-socket socket 1 #f)))) ; process the messages (pp messages) ; Quick hack so we can see something working (let ((stdout (alist-ref fcgi-stdout messages))) (if (and stdout (> (blob-size (car stdout)) 0)) (send-response status: 'ok body: (blob->string (car stdout))))) ; when it starts, sort out the headers: remove content-length and close? if content length is not supplied then close? ; transfer it to the spiffy response port or log it to debug-log as it arrives. (printf "That dance is over.\n") (if (alist-ref fcgi-end-request messages) #t #f) ) ) ;(read/write-socket socket request-id type . args) ; send fcgi-begin-request (read/write-socket socket 1 fcgi-begin-request fcgi-responder) ; send fcgi-params (read/write-socket socket 1 fcgi-params (cgi-build-env req "!!!FIXME!!!")) (read/write-socket socket 1 fcgi-params 'close-stream) ; stream request data over fcgi-stdin. (copy-port (request-port req) in-out-dance content-length) (let loop ((done? (in-out-dance 'close-stream))) ; wait for all the replies to come back (if (not done?) (loop (in-out-dance)))))