Subject: Re: Web services in CL
From: rpw3@rpw3.org (Rob Warnock)
Date: Sun, 24 Apr 2005 21:42:25 -0500
Newsgroups: comp.lang.lisp
Message-ID: <HpudnawvR9eMxPHfRVn-2g@speakeasy.net>
Bruce Butterfield <bab@entricom.com> wrote:
+---------------
| I am writing some web services in CL (SBCL for now) and I would like
| some advice about how to handle requests. In Java I would use a simple
| TCP listener on a known port and spawn a new thread to handle each
| request. Threads are at least fairly well documented in Java and I have
| had no issues (other than performance) using this model in previous
| implementations. Is there an equivalent simple, straightforward way to
| spawn new threads of execution upon accepting a TCP connection? I guess
| what I'm looking for is 'trivial-threads' to match up with
| 'trivial-sockets'. Anything out there?
+---------------

I do web programming with CMUCL [with a mod_lisp-like model],
spawning a new CMUCL (green) thread for each request. It seems
to work quite well for the level of traffic those applications
see [somewhat low, to be sure]. I don't know how much of CMUCL's
threading (the "MP" package) and TCP-handling (in the "EXT" package)
was carried over directly to SBCL, but I suspect there are probably
direct equivalents to the functions I use. Look for functions
in SBCL with names or functionality similar to these from CMUCL
to create a "listener" on a Unix-domain socket:

    mp:make-process
    ext:create-unix-listener
    mp:process-wait-until-fd-usable

and to accept a connection and spawn a thread to handle a request:

    ext:accept-unix-connection
    sys:make-fd-stream
    mp:make-process
    unix:unix-close


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607