Showing posts with label hunchentoot. Show all posts
Showing posts with label hunchentoot. Show all posts

Sunday, 29 March 2009

Hunchentoot and CCL on Windows. Take 2.

I recently posted a brief workaround for a bug in CCL on MS Windows which prevented Hunchentoot from responding to HTTP requests. 

Shortly after posting this I, and everyone else on the openmcl-devel mailing list, received an email from R. Matthew Emerson who has informed us that this issue was resolved in their SVN repository over a week ago and that CCL no longer needs the workaround I posted.

So for all those CCL+Windows users, you can now
svn update
and
(rebuild-ccl :clean t)
and ignore my previous post.

Friday, 27 March 2009

Hunchentoot, CCL and Windows


It's been a couple of months now and I've been warming to CCL, so much so in fact, that it has replaced SBCL as my `other` CL implementation. If you've never used it, it is an Open Source Common Lisp which runs on a number of platforms, including Windows, Mac OS X and Linux in both 32 and 64 bit modes and supports threading on all 3 of these platforms.

There is however a small issue when running Hunchentoot with CCL on Windows; you will notice when connecting to a CCL+Hunchentoot server that it never responds with any content but hangs indefinitely. This is caused by a bug in the CCL Windows timeout handling which requires a small workaround by the user.

Fortunately the workaround is straightforward; simply start up Hunchentoot with the following extra parameters:

> (hunchentoot:start (make-instance 'hunchentoot:acceptor :port 8080 :read-timeout nil :write-timeout nil))

And you are on your way.

Tuesday, 2 December 2008

Announcing Mudballs

 This post is to announce the release of Mudballs, a collection of Common Lisp code for managing systems.  It is currently in an early stage of development and still has a long way to go but is currently able to compile,  load, document, download and install systems across Windows, Linux and Mac OSX. Mudballs supports the following implementations 
  • Lispworks on Mac OSX, Linux and Windows.
  • SBCL on Mac OSX and Linux.
  • CMUCL on Mac OSX and Linux.
  • CLISP on Linux and Windows (Mac OSX as well provided  you have FFI).
  • ClozureCL/OpenMCL on Mac OSX, Linux and Windows.
  • AllegroCL on Mac OSX, Linux and Windows.
 
 As it currently stands it is not ASDF compatible (not ideal, I know) but ASDF support is planned for the future. It is available from http://mudballs.com  which contains enough information to get the intrepid lisper on his or  her way.
 
 As a small taste, the following is now possible from a freshly installed Lisp with Mudballs loaded.

> (mb:install :hunchentoot)
> (hunchentoot:start-server :port 8080)

P.S.  Prizes for anyone that can come up with a logo which doesn't look like a pile of excrement.

Tuesday, 29 May 2007

Hunchentoot and packages

Over the past couple of years I've been experimenting with a number of CL
http servers and have recently turned to hunchentoot as my platform of choice
which, like the rest of Edi's packages, has found it's way into my heart.

One of the things I've often found rather annoying however (not with
Hunchentoot specifically, this is present in all of the CL web servers
I've experimented with) is that publishing a URL is a twofold process:

a) define your handler function (or something similar) and
b) register that handler with a particular URL.

Now all this becomes a little repetitive so here is a new publisher function
which allows you to publish your package on a particular URL so that any
requests to URL's 'below' that one will be resolved to a function in your package.

We play on one of the less remarked upon CL features (or lack of restrictions)
which allows symbols to start with a #\/ (a forward slash, to those not used to
the CL character macro reader) so we can publish our package on /test define a
function named /foo and automagically have requests to /test/foo mapped
to our /foo handler.

(modified 30/5/2007 16:00)
eg.

(asdf:oos 'asdf:load-op :hunchentoot)
(asdf:oos 'asdf:load-op :cl-who)

(defpackage :pack-test (:use :cl :hunchentoot :cl-who))
(in-package :pack-test)


(defun index ()
#'(lambda ()
(with-html-output-to-string (x)
(:html "The index page"))))

(defun seq-last (seq)
(aref seq (1- (length seq))))

(defun string->handler (string package)
(when (string= string "/") (return-from string->handler (index)))
(multiple-value-bind (sym type) (find-symbol string package)
(when (and (not (eql type :inherited))
(fboundp sym))
(symbol-function sym))))

(defun create-package-dispatcher (prefix)
(check-type prefix string)
(assert (eql (seq-last prefix) #\/) (prefix) "Prefix must end in a / (forward slash)")
#'(lambda (request)
(let* ((function (script-name request))
(mismatch (mismatch (script-name request) prefix
:test #'char=)))
(when (or (null mismatch)
(>= mismatch (length prefix)))
(string->handler (string-upcase (subseq function (1- (length prefix))))
*package*)))))

(push (create-package-dispatcher "/test/") *dispatch-table*)

(defun /index ()
(with-html-output-to-string (out)
(:html (:head (:title "Welcome"))
(:body (:h2 "This is my welcome page")))))

(defvar *server* (start-server :port 8080))

and now browsing to http://localhost:8080/test/index should give you a
nice new welcome page and adding a new URL is a simple 1 step process.


---
This post is courtesy of lispworks(5.0.2), hunchentoot(0.9.2) and cl-who (0.4.4)