Add thread-support to lackup.

This commit is contained in:
Eitaro Fukamachi 2015-03-07 03:44:03 +09:00
parent 1e58de2f84
commit 5cae3bc030
2 changed files with 29 additions and 12 deletions

View file

@ -3,6 +3,8 @@
(:use :cl)
(:import-from :lack.util
:find-package-or-load)
(:import-from :bordeaux-threads
:make-thread)
(:export :run
:stop))
(in-package :lack.handler)
@ -20,15 +22,22 @@
(error "~S is unknown handler."
server))))
(defun run (app server &rest args)
(defun run (app server &rest args &key use-thread &allow-other-keys)
(let ((handler-package (find-handler server)))
(make-handler
:server server
:acceptor
(apply (intern #.(string '#:run) handler-package)
app
:allow-other-keys t
args))))
(flet ((run-server ()
(apply (intern #.(string '#:run) handler-package)
app
:allow-other-keys t
args)))
(make-handler
:server server
:acceptor (if use-thread
(bt:make-thread #'run-server
:name (format nil "lack-handler-~(~A~)" server)
:initial-bindings
`((*standard-output* . ,*standard-output*)
(*error-output* . ,*error-output*)))
(run-server))))))
(defun stop (handler)
(let ((acceptor (handler-acceptor handler)))

View file

@ -17,8 +17,16 @@
&key (server :hunchentoot)
(port 5000)
(debug t)
(use-thread #+thread-support t #-thread-support nil)
&allow-other-keys)
(apply #'lack.handler:run app server
:port port
:debug debug
(delete-from-plist args :server :use-thread :port :debug)))
(flet ((start-message ()
(format t "~&~:(~A~) server is started.~%Listening on localhost:~A.~%" server port)))
(unless use-thread
(start-message))
(prog1
(apply #'lack.handler:run app server
:port port
:debug debug
:use-thread use-thread
(delete-from-plist args :server :port :debug :use-thread))
(start-message))))