[racket] Parameters and servlets

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Tue Jan 21 12:03:03 EST 2014

Hi Antoine,

The Web server makes no promises regarding threads and requests. The
actual implementation uses one thread per HTTP connection, which means
that on 1.1 connections there may be multiple requests for each
thread.

As for your code, I don't understand why the 'parameterize' approach
didn't work, could you go into that?

In particular, I would assume that you would do something like

(parameterize ([request-data (extract-the-data req)])
 (do-the-real-work req))

rather than doing a dance of setting it to #f and then putting it back in.

Jay


On Sat, Jan 18, 2014 at 11:11 AM, antoine <antoine.brand at sfr.fr> wrote:
> Bonjour,
>
> I want use a parameter to store data with a request lifetime.
>
> I first made a parameter
> (define request-data (make-parameter #f))
>
> That i fill in the main entry point for a servlet
> (define (start req)
>   (fill-request-data! req)
>   (treat req))
>
> ;; how i run the servlet for information
> (serve
>   #:port 8080
>   #:dispatch (dispatch/servlet start))
>
> (define (fill-request-data! req)
>   (when (something-present-in req)
>     (request-data some-data)))
>
> It seems to work well until i noticed that request-data isn't reset to #f for
> each request. I thought that each new thread (Is there a new thread created for
> each request?) will set request-data to its default.
>
> So i decided to rewrite start as
> (define (start req)
>   (parameterize ([request-data #f])
>     (fill-request-data! req)
>     (treat req)))
>
> But that don't works because i used responce/output and the proc arguments is out
> parameterize scope, i don't when the response struct call its output fields.
>
> So i have three solution:
>
> rewrite
> (define (start req)
>   (request-data #f)
>   (fill-request-data! req)
>   (treat req))
>
> Is there any defect in it? especialy regards to when the output fields is called?
>
> rewrite my responce/output like
>
> (let ([request-data-closurable (request-data)])
>   (responce/output (lambda (out) .... i can capture the value of request-data-closurable)))
>
> or rewrite responce/output
> (let ([data (do-the-rendering-here-and-now)])
>   (responce/output (lambda (out) data)))
>
> After writing this mail i remember threads inherits parameters but i am not sure
> why i get a value different from #f.
> Why not thread-cell for solution 1?
>
> thank you.
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users



-- 
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay

"The glory of God is Intelligence" - D&C 93

Posted on the users mailing list.