This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: question about using the built-in web server


>>I suppose one approach might be to start the web server as a separate
>> process, and then have the editor and the web server communicate through
>> sockets, but that seems a bit troublesome.
>
>Using a separate thread is probably enough - but you still have to
>make sure the communication is thread-safe and non-blocking.

I'm actually not really clear how to communicate between the code that
starts the web server, and the code that is run in response to the http
request. This is what I've tried, without yet worrying about threading or
blocking.

backend.scm:

(module-export set-the-var)

; shared variable
(define the-var 0)

; set the shared variable
(define (set-the-var new-val)
  (format #t "before - the-var: ~a.~%~!" the-var)
  (set! the-var new-val)
  (format #t "after - the-var: ~a.~%~!" the-var))


testserver.scm:

(require "backend.scm")

; set the shared variable
(set-the-var 1)

; start the server
(gnu.kawa.servlet.KawaHttpHandler:addAutoHandler "/" ".")
(gnu.kawa.servlet.KawaHttpHandler:startServer 8888)
(format #t "running~%~!")



handlerequest.scm:

(require "backend.scm")

; set the shared variable
(set-the-var 2)

I was hoping that what I would see would be:

[when the server is started]
before - the-var: 0.
after - the-var: 1.
running

[when the request comes from a web page]
Compile /handlerequest.scm - a Scheme source file (based on extension)
before - the-var: 1.
after - the-var: 2.

ie. the-var is defined in the same environment for both testserver.scm and
handlerequest.scm.
 
But instead I see:


[when the server is started]
before - the-var: 0.
after - the-var: 1.
running

[when the request comes from a web page]
Compile /handlerequest.scm - a Scheme source file (based on extension)
before - the-var: 0.
after - the-var: 2.

So the-var that handlerequest.scm sees is different from the-var that
testserver.scm sees.

Any suggestions as to how to get this to work? The main thing I want to be
able to do is pass values from a web page through to the code which
started the server (so that eventually I can display this in the GUI to
the user).


thanks,
Alex



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]