This is the mail archive of the guile@cygnus.com mailing list for the Guile project.


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

Re: Guile for servlets (a sort of generic mod_guile)


Jim Blandy <jimb@cygnus.com> writes:

> One idea (possibly a dumb one) would be to make a special script
> interpreter for writing servers.
> 
>     #!/usr/local/bin/guile-server
>     !#
> 
>     (handle-connection 20004
>       (lambda (socket)
>         (write (apply + (read socket)) socket)
>         (close-port socket)))

As a case of prior art, RScheme handles this as follows (more or less,
I haven't tested this bit of code, but I've used the interface
before):

  (let* ((server-fd (inet-server 20004))
         (service (make-service server-fd)))
    (bind ((client-fd peer-address (get-next-client service)))
      (let ((input-port (open-input-fd client-fd))
            (output-port (open-output-fd client-fd)))
        (write (apply + (read input-port)) output-port)
        (close-input-port input-port)
        (close-output-port output-port))))
         
Of course you don't really need the bind if you're not going to use
the extra peer-address return value.

There's a similar interface for clients.

FWIW

-- 
Rob Browning <rlb@cs.utexas.edu> PGP=E80E0D04F521A094 532B97F5D64E3930

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